Skip to content

Commit

Permalink
Add docblock comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed May 11, 2024
1 parent 193324e commit 29047b1
Showing 1 changed file with 84 additions and 1 deletion.
85 changes: 84 additions & 1 deletion src/Geometry/Tools/RectangleResizer.php
Expand Up @@ -11,7 +11,10 @@
class RectangleResizer
{
/**
* @param null|int $width
* @param null|int $height
* @throws GeometryException
* @return void
*/
public function __construct(
protected ?int $width = null,
Expand All @@ -31,35 +34,61 @@ public function __construct(
}

/**
* @throws GeometryException
* Static factory method to create resizer with given target size
*
* @param array $arguments
* @return RectangleResizer
*/
public static function to(mixed ...$arguments): self

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.

Check failure on line 42 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() has parameter $arguments with no value type specified in iterable type array.
{
return new self(...$arguments);

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 6.9.12-55

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 7.1.0-40

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 6.9.12-55

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 7.1.0-40

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 6.9.12-55

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 6.9.12-55

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 7.1.0-40

Method Intervention\Image\Geometry\Tools\RectangleResizer::to() throws checked exception Intervention\Image\Exceptions\GeometryException but it's missing from the PHPDoc @throws tag.

Check failure on line 44 in src/Geometry/Tools/RectangleResizer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 7.1.0-40

Parameter #1 $width of class Intervention\Image\Geometry\Tools\RectangleResizer constructor expects int|null, array given.
}

/**
* Determine if resize has target width
*
* @return bool
*/
protected function hasTargetWidth(): bool
{
return is_integer($this->width);
}

/**
* Return target width of resizer if available
*
* @return null|int
*/
protected function getTargetWidth(): ?int
{
return $this->hasTargetWidth() ? $this->width : null;
}

/**
* Determine if resize has target height
*
* @return bool
*/
protected function hasTargetHeight(): bool
{
return is_integer($this->height);
}

/**
* Return target width of resizer if available
*
* @return null|int
*/
protected function getTargetHeight(): ?int
{
return $this->hasTargetHeight() ? $this->height : null;
}

/**
* Return target size object
*
* @throws GeometryException
* @return SizeInterface
*/
protected function getTargetSize(): SizeInterface
{
Expand All @@ -70,20 +99,38 @@ protected function getTargetSize(): SizeInterface
return new Rectangle($this->width, $this->height);
}

/**
* Set target width of resizer
*
* @param int $width
* @return RectangleResizer
*/
public function toWidth(int $width): self
{
$this->width = $width;

return $this;
}

/**
* Set target height of resizer
*
* @param int $height
* @return RectangleResizer
*/
public function toHeight(int $height): self
{
$this->height = $height;

return $this;
}

/**
* Set target size to given size object
*
* @param SizeInterface $size
* @return RectangleResizer
*/
public function toSize(SizeInterface $size): self
{
$this->width = $size->width();
Expand All @@ -92,6 +139,12 @@ public function toSize(SizeInterface $size): self
return $this;
}

/**
* Get proportinal width
*
* @param SizeInterface $size
* @return int
*/
protected function getProportionalWidth(SizeInterface $size): int
{
if (!$this->hasTargetHeight()) {
Expand All @@ -101,6 +154,12 @@ protected function getProportionalWidth(SizeInterface $size): int
return max([1, (int) round($this->height * $size->aspectRatio())]);
}

/**
* Get proportinal height
*
* @param SizeInterface $size
* @return int
*/
protected function getProportionalHeight(SizeInterface $size): int
{
if (!$this->hasTargetWidth()) {
Expand All @@ -110,6 +169,12 @@ protected function getProportionalHeight(SizeInterface $size): int
return max([1, (int) round($this->width / $size->aspectRatio())]);
}

/**
* Resize given size to target size of the resizer
*
* @param SizeInterface $size
* @return SizeInterface
*/
public function resize(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
Expand All @@ -125,6 +190,12 @@ public function resize(SizeInterface $size): SizeInterface
return $resized;
}

/**
* Resize given size to target size of the resizer but do not exceed original size
*
* @param SizeInterface $size
* @return SizeInterface
*/
public function resizeDown(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
Expand All @@ -144,6 +215,12 @@ public function resizeDown(SizeInterface $size): SizeInterface
return $resized;
}

/**
* Resize given size to target size proportinally
*
* @param SizeInterface $size
* @return SizeInterface
*/
public function scale(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
Expand All @@ -168,6 +245,12 @@ public function scale(SizeInterface $size): SizeInterface
return $resized;
}

/**
* Resize given size to target size proportinally but do not exceed original size
*
* @param SizeInterface $size
* @return SizeInterface
*/
public function scaleDown(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
Expand Down

0 comments on commit 29047b1

Please sign in to comment.