Skip to content

Commit

Permalink
phpStan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 3, 2019
1 parent b7e6205 commit c110692
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/Iterators/CachingIterator.php
Expand Up @@ -41,11 +41,11 @@ 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)));
}
Expand Down
16 changes: 8 additions & 8 deletions src/Utils/Image.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions tests/phpstan.neon
Expand Up @@ -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 c110692

Please sign in to comment.