Skip to content
Permalink
Browse files

phpStan fixes

  • Loading branch information
dg committed Nov 13, 2019
1 parent b7e6205 commit bc1df2548be3420bc7b9425d15888bd8b077939a
Showing with 12 additions and 14 deletions.
  1. +4 −3 src/Iterators/CachingIterator.php
  2. +8 −8 src/Utils/Image.php
  3. +0 −3 tests/phpstan.neon
@@ -41,11 +41,12 @@ public function __construct($iterator)
do {
$iterator = $iterator->getIterator();
} while ($iterator instanceof \IteratorAggregate);
assert($iterator instanceof \Iterator);
} elseif ($iterator instanceof \Iterator) {
} elseif ($iterator instanceof \Traversable) {
if (!$iterator instanceof \Iterator) {
$iterator = new \IteratorIterator($iterator);
}
$iterator = new \IteratorIterator($iterator);
} else {
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', __CLASS__, is_object($iterator) ? get_class($iterator) : gettype($iterator)));
}
@@ -304,14 +304,14 @@ public function resize($width, $height, int $flags = self::FIT)
public static function calculateSize(int $srcWidth, int $srcHeight, $newWidth, $newHeight, int $flags = self::FIT): array
{
if (is_string($newWidth) && substr($newWidth, -1) === '%') {
$newWidth = (int) round($srcWidth / 100 * abs(substr($newWidth, 0, -1)));
$newWidth = (int) round($srcWidth / 100 * abs((int) substr($newWidth, 0, -1)));
$percents = true;
} else {
$newWidth = (int) abs($newWidth);
}
if (is_string($newHeight) && substr($newHeight, -1) === '%') {
$newHeight = (int) round($srcHeight / 100 * abs(substr($newHeight, 0, -1)));
$newHeight = (int) round($srcHeight / 100 * abs((int) substr($newHeight, 0, -1)));
$flags |= empty($percents) ? 0 : self::STRETCH;
} else {
$newHeight = (int) abs($newHeight);
@@ -386,16 +386,16 @@ public function crop($left, $top, $width, $height)
public static function calculateCutout(int $srcWidth, int $srcHeight, $left, $top, $newWidth, $newHeight): array
{
if (is_string($newWidth) && substr($newWidth, -1) === '%') {
$newWidth = (int) round($srcWidth / 100 * substr($newWidth, 0, -1));
$newWidth = (int) round($srcWidth / 100 * (int) substr($newWidth, 0, -1));
}
if (is_string($newHeight) && substr($newHeight, -1) === '%') {
$newHeight = (int) round($srcHeight / 100 * substr($newHeight, 0, -1));
$newHeight = (int) round($srcHeight / 100 * (int) substr($newHeight, 0, -1));
}
if (is_string($left) && substr($left, -1) === '%') {
$left = (int) round(($srcWidth - $newWidth) / 100 * substr($left, 0, -1));
$left = (int) round(($srcWidth - $newWidth) / 100 * (int) substr($left, 0, -1));
}
if (is_string($top) && substr($top, -1) === '%') {
$top = (int) round(($srcHeight - $newHeight) / 100 * substr($top, 0, -1));
$top = (int) round(($srcHeight - $newHeight) / 100 * (int) substr($top, 0, -1));
}
if ($left < 0) {
$newWidth += $left;
@@ -444,11 +444,11 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
$height = $image->getHeight();
if (is_string($left) && substr($left, -1) === '%') {
$left = (int) round(($this->getWidth() - $width) / 100 * substr($left, 0, -1));
$left = (int) round(($this->getWidth() - $width) / 100 * (int) substr($left, 0, -1));
}
if (is_string($top) && substr($top, -1) === '%') {
$top = (int) round(($this->getHeight() - $height) / 100 * substr($top, 0, -1));
$top = (int) round(($this->getHeight() - $height) / 100 * (int) substr($top, 0, -1));
}
$output = $input = $image->image;
@@ -7,6 +7,3 @@ parameters:

# PHPStan does not support RecursiveIteratorIterator proxying unknown method calls to inner iterator
- '#RecursiveIteratorIterator::getSubPathName\(\)#'

# PHPStan does not support comparing null
- '#Nette\\Utils\\Strings::substring\(\) expects int, int\|null given#'

0 comments on commit bc1df25

Please sign in to comment.
You can’t perform that action at this time.