Size validator for comment dimensions and margins

This commit is contained in:
MarkBaker 2020-11-02 23:48:57 +01:00
parent a16badbcc4
commit 06f7d3c8bd
3 changed files with 22 additions and 17 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added
- Nothing.
- Provided a Size Helper class to validate size values (pt, px, em)
### Changed

View File

@ -129,13 +129,13 @@ class Comment implements IComparable
}
/**
* Set comment width (CSS style, i.e. XXpx or YYpt).
* Set comment width (CSS style, i.e. XXpx or YYpt). Default unit is pt.
*/
public function setWidth(string $width): self
{
$result = new Size($width);
if ($result->valid()) {
$this->width = $result->size() . $result->unit();
$width = new Size($width);
if ($width->valid()) {
$this->width = (string) $width;
}
return $this;
@ -150,13 +150,13 @@ class Comment implements IComparable
}
/**
* Set comment height (CSS style, i.e. XXpx or YYpt).
* Set comment height (CSS style, i.e. XXpx or YYpt). Default unit is pt.
*/
public function setHeight(string $height): self
{
$result = new Size($height);
if ($result->valid()) {
$this->height = $result->size() . $result->unit();
$height = new Size($height);
if ($height->valid()) {
$this->height = (string) $height;
}
return $this;
@ -171,13 +171,13 @@ class Comment implements IComparable
}
/**
* Set left margin (CSS style, i.e. XXpx or YYpt).
* Set left margin (CSS style, i.e. XXpx or YYpt). Default unit is pt.
*/
public function setMarginLeft(string $margin): self
{
$result = new Size($margin);
if ($result->valid()) {
$this->marginLeft = $result->size() . $result->unit();
$margin = new Size($margin);
if ($margin->valid()) {
$this->marginLeft = (string) $margin;
}
return $this;
@ -192,13 +192,13 @@ class Comment implements IComparable
}
/**
* Set top margin (CSS style, i.e. XXpx or YYpt).
* Set top margin (CSS style, i.e. XXpx or YYpt). Default unit is pt.
*/
public function setMarginTop(string $margin): self
{
$result = new Size($margin);
if ($result->valid()) {
$this->marginTop = $result->size() . $result->unit();
$margin = new Size($margin);
if ($margin->valid()) {
$this->marginTop = (string) $margin;
}
return $this;

View File

@ -35,4 +35,9 @@ class Size
{
return $this->unit;
}
public function __toString()
{
return $this->size . $this->unit;
}
}