Skip to content

Commit 32fd477

Browse files
JanTvrdikdg
authored andcommitted
PHPStan: fixed some issues
1 parent e298f36 commit 32fd477

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

src/Utils/ArrayList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function offsetSet($index, $value): void
5454
throw new Nette\OutOfRangeException('Offset invalid or out of range');
5555

5656
} else {
57-
$this->list[(int) $index] = $value;
57+
$this->list[$index] = $value;
5858
}
5959
}
6060

@@ -70,7 +70,7 @@ public function offsetGet($index)
7070
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
7171
throw new Nette\OutOfRangeException('Offset invalid or out of range');
7272
}
73-
return $this->list[(int) $index];
73+
return $this->list[$index];
7474
}
7575

7676

@@ -94,7 +94,7 @@ public function offsetUnset($index): void
9494
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
9595
throw new Nette\OutOfRangeException('Offset invalid or out of range');
9696
}
97-
array_splice($this->list, (int) $index, 1);
97+
array_splice($this->list, $index, 1);
9898
}
9999

100100

src/Utils/DateTime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function from($time)
5252
if ($time <= self::YEAR) {
5353
$time += time();
5454
}
55-
return (new static('@' . $time))->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
55+
return (new static('@' . $time))->setTimezone(new \DateTimeZone(date_default_timezone_get()));
5656

5757
} else { // textual or null
5858
return new static($time);
@@ -98,7 +98,7 @@ public function setTimestamp($timestamp)
9898
{
9999
$zone = $this->getTimezone();
100100
$this->__construct('@' . $timestamp);
101-
return $this->setTimeZone($zone);
101+
return $this->setTimezone($zone);
102102
}
103103

104104

src/Utils/Html.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public static function el(string $name = null, $attrs = null)
8282
/**
8383
* Changes element's name.
8484
* @return static
85-
* @throws Nette\InvalidArgumentException
8685
*/
8786
final public function setName(string $name, bool $isEmpty = null)
8887
{
@@ -293,13 +292,9 @@ public function data(string $name, $value = null)
293292
* Sets element's HTML content.
294293
* @param IHtmlString|string
295294
* @return static
296-
* @throws Nette\InvalidArgumentException
297295
*/
298296
final public function setHtml($html)
299297
{
300-
if (is_array($html)) {
301-
throw new Nette\InvalidArgumentException(sprintf('Textual content must be a scalar, %s given.', gettype($html)));
302-
}
303298
$this->children = [(string) $html];
304299
return $this;
305300
}
@@ -318,7 +313,6 @@ final public function getHtml(): string
318313
* Sets element's textual content.
319314
* @param IHtmlString|string
320315
* @return static
321-
* @throws Nette\InvalidArgumentException
322316
*/
323317
final public function setText($text)
324318
{
@@ -352,7 +346,7 @@ final public function addHtml($child)
352346

353347
/**
354348
* Appends plain-text string to element content.
355-
* @param IHtmlString|string
349+
* @param IHtmlString|string|int|float
356350
* @return static
357351
*/
358352
public function addText($text)
@@ -380,21 +374,15 @@ final public function create(string $name, $attrs = null)
380374
* Inserts child node.
381375
* @param IHtmlString|string $child Html node or raw HTML string
382376
* @return static
383-
* @throws Nette\InvalidArgumentException
384377
*/
385378
public function insert(int $index = null, $child, bool $replace = false)
386379
{
387-
if ($child instanceof IHtmlString || is_scalar($child)) {
388-
$child = $child instanceof self ? $child : (string) $child;
389-
if ($index === null) { // append
390-
$this->children[] = $child;
380+
$child = $child instanceof self ? $child : (string) $child;
381+
if ($index === null) { // append
382+
$this->children[] = $child;
391383

392-
} else { // insert or replace
393-
array_splice($this->children, $index, $replace ? 1 : 0, [$child]);
394-
}
395-
396-
} else {
397-
throw new Nette\InvalidArgumentException(sprintf('Child node must be scalar or Html object, %s given.', is_object($child) ? get_class($child) : gettype($child)));
384+
} else { // insert or replace
385+
array_splice($this->children, $index, $replace ? 1 : 0, [$child]);
398386
}
399387

400388
return $this;
@@ -440,7 +428,7 @@ final public function offsetExists($index): bool
440428
public function offsetUnset($index): void
441429
{
442430
if (isset($this->children[$index])) {
443-
array_splice($this->children, (int) $index, 1);
431+
array_splice($this->children, $index, 1);
444432
}
445433
}
446434

@@ -494,7 +482,7 @@ final public function render(int $indent = null): string
494482
$indent++;
495483
}
496484
foreach ($this->children as $child) {
497-
if (is_object($child)) {
485+
if ($child instanceof self) {
498486
$s .= $child->render($indent);
499487
} else {
500488
$s .= $child;

src/Utils/Image.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function resize($width, $height, int $flags = self::FIT)
275275
[$newWidth, $newHeight] = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
276276

277277
if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) { // resize
278-
$newImage = static::fromBlank($newWidth, $newHeight, self::RGB(0, 0, 0, 127))->getImageResource();
278+
$newImage = static::fromBlank($newWidth, $newHeight, self::rgb(0, 0, 0, 127))->getImageResource();
279279
imagecopyresampled(
280280
$newImage, $this->image,
281281
0, 0, 0, 0,
@@ -450,6 +450,7 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
450450

451451
$output = $input = $image->image;
452452
if ($opacity < 100) {
453+
$tbl = [];
453454
for ($i = 0; $i < 128; $i++) {
454455
$tbl[$i] = round(127 - (127 - $i) * $opacity / 100);
455456
}

src/Utils/ObjectHelpers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static function getMagicProperties(string $class): array
126126

127127
/**
128128
* Finds the best suggestion (for 8-bit encoding).
129+
* @param (\ReflectionFunctionAbstract|\ReflectionParameter|\ReflectionClass|\ReflectionProperty|string)[]
129130
* @internal
130131
*/
131132
public static function getSuggestion(array $possibilities, string $value): ?string
@@ -163,7 +164,7 @@ private static function parseFullDoc(\ReflectionClass $rc, string $pattern): arr
163164

164165
/**
165166
* Checks if the public non-static property exists.
166-
* @return bool|'event'
167+
* @return bool|string returns 'event' if the property exists and has event like name
167168
* @internal
168169
*/
169170
public static function hasProperty(string $class, string $name)

0 commit comments

Comments
 (0)