Skip to content

Commit e04bf33

Browse files
committed
removed useless type juggling
1 parent d0041ba commit e04bf33

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

src/Utils/Html.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,8 @@ public static function el(string $name = NULL, $attrs = NULL)
8989
*/
9090
public function setName(string $name, bool $isEmpty = NULL)
9191
{
92-
if ($name !== NULL && !is_string($name)) {
93-
throw new Nette\InvalidArgumentException(sprintf('Name must be string or NULL, %s given.', gettype($name)));
94-
}
95-
9692
$this->name = $name;
97-
$this->isEmpty = $isEmpty === NULL ? isset(static::$emptyElements[$name]) : (bool) $isEmpty;
93+
$this->isEmpty = $isEmpty === NULL ? isset(static::$emptyElements[$name]) : $isEmpty;
9894
return $this;
9995
}
10096

@@ -351,7 +347,7 @@ public function setText($text)
351347
if (!is_array($text) && !$text instanceof self) {
352348
$text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8');
353349
}
354-
return $this->setHtml($text);
350+
return $this->setHtml((string) $text);
355351
}
356352

357353

@@ -416,7 +412,7 @@ public function insert(int $index = NULL, $child, bool $replace = FALSE)
416412
$this->children[] = $child;
417413

418414
} else { // insert or replace
419-
array_splice($this->children, (int) $index, $replace ? 1 : 0, [$child]);
415+
array_splice($this->children, $index, $replace ? 1 : 0, [$child]);
420416
}
421417

422418
} else {

src/Utils/Image.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ class Image
132132
public static function rgb(int $red, int $green, int $blue, int $transparency = 0): array
133133
{
134134
return [
135-
'red' => max(0, min(255, (int) $red)),
136-
'green' => max(0, min(255, (int) $green)),
137-
'blue' => max(0, min(255, (int) $blue)),
138-
'alpha' => max(0, min(127, (int) $transparency)),
135+
'red' => max(0, min(255, $red)),
136+
'green' => max(0, min(255, $green)),
137+
'blue' => max(0, min(255, $blue)),
138+
'alpha' => max(0, min(127, $transparency)),
139139
];
140140
}
141141

@@ -162,7 +162,7 @@ public static function fromFile(string $file, int &$format = NULL)
162162
$format = NULL;
163163
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");
164164
}
165-
return new static(Callback::invokeSafe('imagecreatefrom' . self::$formats[$format], [$file], function ($message) {
165+
return new static(Callback::invokeSafe('imagecreatefrom' . self::$formats[$format], [$file], function (string $message) {
166166
throw new ImageException($message);
167167
}));
168168
}
@@ -186,7 +186,7 @@ public static function fromString(string $s, int &$format = NULL)
186186
$format = isset(self::$formats[$tmp]) ? $tmp : NULL;
187187
}
188188

189-
return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function ($message) {
189+
return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message) {
190190
throw new ImageException($message);
191191
}));
192192
}
@@ -205,14 +205,12 @@ public static function fromBlank(int $width, int $height, array $color = NULL)
205205
throw new Nette\NotSupportedException('PHP extension GD is not loaded.');
206206
}
207207

208-
$width = (int) $width;
209-
$height = (int) $height;
210208
if ($width < 1 || $height < 1) {
211209
throw new Nette\InvalidArgumentException('Image width and height must be greater than zero.');
212210
}
213211

214212
$image = imagecreatetruecolor($width, $height);
215-
if (is_array($color)) {
213+
if ($color) {
216214
$color += ['alpha' => 0];
217215
$color = imagecolorresolvealpha($image, $color['red'], $color['green'], $color['blue'], $color['alpha']);
218216
imagealphablending($image, FALSE);
@@ -457,7 +455,7 @@ public function sharpen()
457455
*/
458456
public function place(Image $image, $left = 0, $top = 0, int $opacity = 100)
459457
{
460-
$opacity = max(0, min(100, (int) $opacity));
458+
$opacity = max(0, min(100, $opacity));
461459
if ($opacity === 0) {
462460
return $this;
463461
}
@@ -524,18 +522,18 @@ public function save(string $file = NULL, int $quality = NULL, int $type = NULL)
524522

525523
switch ($type) {
526524
case self::JPEG:
527-
$quality = $quality === NULL ? 85 : max(0, min(100, (int) $quality));
525+
$quality = $quality === NULL ? 85 : max(0, min(100, $quality));
528526
return imagejpeg($this->image, $file, $quality);
529527

530528
case self::PNG:
531-
$quality = $quality === NULL ? 9 : max(0, min(9, (int) $quality));
529+
$quality = $quality === NULL ? 9 : max(0, min(9, $quality));
532530
return imagepng($this->image, $file, $quality);
533531

534532
case self::GIF:
535533
return imagegif($this->image, $file);
536534

537535
case self::WEBP:
538-
$quality = $quality === NULL ? 80 : max(0, min(100, (int) $quality));
536+
$quality = $quality === NULL ? 80 : max(0, min(100, $quality));
539537
return imagewebp($this->image, $file, $quality);
540538

541539
default:

src/Utils/Paginator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Paginator
5252
*/
5353
public function setPage(int $page)
5454
{
55-
$this->page = (int) $page;
55+
$this->page = $page;
5656
return $this;
5757
}
5858

@@ -94,7 +94,7 @@ public function getLastPage()
9494
*/
9595
public function setBase(int $base)
9696
{
97-
$this->base = (int) $base;
97+
$this->base = $base;
9898
return $this;
9999
}
100100

@@ -157,7 +157,7 @@ public function getPageCount()
157157
*/
158158
public function setItemsPerPage(int $itemsPerPage)
159159
{
160-
$this->itemsPerPage = max(1, (int) $itemsPerPage);
160+
$this->itemsPerPage = max(1, $itemsPerPage);
161161
return $this;
162162
}
163163

@@ -179,7 +179,7 @@ public function getItemsPerPage(): int
179179
*/
180180
public function setItemCount(int $itemCount = NULL)
181181
{
182-
$this->itemCount = ($itemCount === FALSE || $itemCount === NULL) ? NULL : max(0, (int) $itemCount);
182+
$this->itemCount = $itemCount === NULL ? NULL : max(0, $itemCount);
183183
return $this;
184184
}
185185

src/Utils/Strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ public static function pcre(string $func, array $args)
586586
PREG_BAD_UTF8_OFFSET_ERROR => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point',
587587
6 => 'Failed due to limited JIT stack space', // PREG_JIT_STACKLIMIT_ERROR
588588
];
589-
$res = Callback::invokeSafe($func, $args, function ($message) use ($args) {
589+
$res = Callback::invokeSafe($func, $args, function (string $message) use ($args) {
590590
// compile-time error, not detectable by preg_last_error
591591
throw new RegexpException($message . ' in pattern: ' . implode(' or ', (array) $args[0]));
592592
});

0 commit comments

Comments
 (0)