Skip to content

Commit

Permalink
Updted PHPStan and fixed new issues
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Apr 3, 2022
1 parent 68472b5 commit a499af0
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 27 deletions.
12 changes: 1 addition & 11 deletions build/phpstan.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@
if (PHP_VERSION_ID >= 80000) {
$ignore[] = '~Parameter #1 \$objectOrClass of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given.~'; # in MethodTypeParser; temporary
$ignore[] = '~Strict comparison using === between CurlMultiHandle and false will always evaluate to false.~'; # in HttpChannelManager; probably a reflection bug
$ignore[] = '~Method Dogma\\\\Obj::dumpHash\(\) has parameter \$object with no typehint specified~';
}
// 8.0
if (PHP_VERSION_ID < 80100 && PHP_VERSION_ID >= 80000) {
$ignore[] = '~Attribute class ReturnTypeWillChange does not exist~';
}
// 7.1 - 8.0
if (PHP_VERSION_ID < 80000) {
$ignore[] = '~Parameter #1 \$argument of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given.~'; # you know nothing
$ignore[] = '~Method Dogma\\\\Arr::combine\(\) should return array but returns array\|false.~'; # in Arr
$ignore[] = '~Parameter #1 \$items of class Dogma\\\\ImmutableArray constructor expects array, array\|false given.~'; # in ImmutableArray
$ignore[] = '~has unknown class Curl(Multi)?Handle as its type.~'; # PHP 7 -> 8
$ignore[] = '~has invalid type Curl(Multi)?Handle.~'; # PHP 7 -> 8
$ignore[] = '~Method Dogma\\\\Obj::dumpHash\(\) has parameter \$object with no typehint specified~';
}
// 7.2+
if (PHP_VERSION_ID >= 70200) {
$ignore[] = '~Method Dogma\\\\Time\\\\DateTime::createFromAnyFormat\(\) should return static\(Dogma\\\\Time\\\\DateTime\) but return statement is missing.~'; # WTF?!
$ignore[] = '~has invalid return type Curl(Multi)?Handle~'; # PHP 7 -> 8
}

$excludePaths = [
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"php": "^7.1|^8.0",
"ext-calendar":"*",
"nette/http": "~2.4|~3.0",
"nette/utils": "~2.4|~3.0"
"nette/utils": "~2.4|~3.0",
"phpstan/phpstan": "1.4.10"

This comment has been minimized.

Copy link
@kukulich

kukulich Apr 14, 2022

Contributor

@paranoiq Nemělo by tohle být v require-dev ?

This comment has been minimized.

Copy link
@paranoiq

paranoiq Apr 14, 2022

Author Owner

fuck. mělo : ]

},
"require-dev": {
"dogma/dogma-dev": "0.1.27"
Expand Down
2 changes: 2 additions & 0 deletions src/Database/SimplePdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PDO;
use PDOException;
use PDOStatement;
use ReturnTypeWillChange;
use function array_shift;
use function array_values;
use function bin2hex;
Expand Down Expand Up @@ -145,6 +146,7 @@ public function query($query, ...$args): SimplePdoResult
* @param mixed ...$args
* @return void
*/
#[ReturnTypeWillChange]
public function exec($query, ...$args): void
{
$args = func_get_args();
Expand Down
2 changes: 2 additions & 0 deletions src/Database/SimplePdoResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Iterator;
use PDO;
use PDOStatement;
use ReturnTypeWillChange;
use function is_array;
use function is_int;

Expand Down Expand Up @@ -113,6 +114,7 @@ public function rewind(): void
$this->current = $this->fetch();
}

#[ReturnTypeWillChange]
public function next(): bool
{
$this->key++;
Expand Down
2 changes: 2 additions & 0 deletions src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use DOMDocument;
use DOMElement;
use DOMNode;
use ReturnTypeWillChange;
use function libxml_clear_errors;
use function libxml_get_last_error;
use function libxml_use_internal_errors;
Expand Down Expand Up @@ -134,6 +135,7 @@ private function error(string $message, bool $previousState): void
* @param string $id
* @return Element|DOMNode|null
*/
#[ReturnTypeWillChange]
public function getElementById($id)
{
$element = parent::getElementById($id);
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Channel/HttpMultiChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class HttpMultiChannel
/** @var int */
private $lastIndex = -1;

/** @var string[][] (string $subJobName => (string $channelName => string $jobName)) */
/** @var array<array<int|string>> ($subJobName => ($channelName => $jobName)) */
private $queue = [];

/** @var HttpResponse[][] (string $jobName => (string $channelName => Response $response)) */
/** @var array<array<HttpResponse>> ($jobName => ($channelName => $response)) */
private $finished = [];

/** @var callable|null */
Expand Down
7 changes: 6 additions & 1 deletion src/Io/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class File implements Path
use NonCloneableMixin;
use NonSerializableMixin;

/** @var int */
/** @var positive-int */
public static $defaultChunkSize = 8192;

/** @var string */
Expand Down Expand Up @@ -227,6 +227,9 @@ public function endOfFileReached(): bool
return $feof;
}

/**
* @param positive-int|null $length
*/
public function read(?int $length = null): string
{
$this->checkOpened();
Expand Down Expand Up @@ -264,6 +267,7 @@ public function copyData($destination, ?int $start = null, int $length = 0, ?int
}

$done = 0;
/** @var positive-int $chunk */
$chunk = $length ? min($length - $done, $chunkSize) : $chunkSize;
while (!$this->endOfFileReached() && (!$length || $done < $length)) {
$buff = $this->read($chunk);
Expand Down Expand Up @@ -311,6 +315,7 @@ public function write(string $data): void

/**
* Truncate file and move pointer at the end
* @param int<0, max> $size
*/
public function truncate(int $size = 0): void
{
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/Type/ConstructorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/

// phpcs:disable SlevomatCodingStandard.TypeHints.ReturnTypeHint

namespace Dogma\Mapping\Type;

use Dogma\Mapping\Mapper;
Expand Down
2 changes: 1 addition & 1 deletion src/Time/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ public function fillValues(DateTimeValues $values): void
$values->year = (int) $results[0];
$values->leapYear = (bool) $results[1];
$values->dayOfYear = (int) $results[2];
$values->quarter = (int) ($results[3] / 3);
$values->month = (int) $results[3];
$values->quarter = (int) ($values->month / 3);
$values->day = (int) $results[4];
$values->dayOfWeek = (int) $results[5];
$values->weekOfYear = (int) $results[6];
Expand Down
7 changes: 5 additions & 2 deletions src/Time/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Dogma\Dumpable;
use Dogma\Equalable;
use Dogma\InvalidValueException;
use Dogma\LogicException;
use Dogma\Obj;
use Dogma\Str;
use Dogma\StrictBehaviorMixin;
Expand Down Expand Up @@ -115,7 +116,7 @@ public static function createFromFormat($format, $timeString, $timeZone = null):
}

/**
* @param string[] $formats
* @param non-empty-array<string> $formats
* @return static
*/
public static function createFromAnyFormat(array $formats, string $timeString, ?DateTimeZone $timeZone = null): self
Expand All @@ -133,6 +134,8 @@ public static function createFromAnyFormat(array $formats, string $timeString, ?

if ($e !== null) {
throw $e;
} else {
throw new LogicException('No formats supplied.');
}
}

Expand Down Expand Up @@ -748,8 +751,8 @@ public function fillValues(DateTimeValues $values): void
$values->year = (int) $results[0];
$values->leapYear = (bool) $results[1];
$values->dayOfYear = (int) $results[2];
$values->quarter = (int) ($results[3] / 3);
$values->month = (int) $results[3];
$values->quarter = (int) ($values->month / 3);
$values->day = (int) $results[4];
$values->dayOfWeek = (int) $results[5];
$values->weekOfYear = (int) $results[6];
Expand Down
5 changes: 4 additions & 1 deletion src/common/Obj.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/

// phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint
// phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint

namespace Dogma;

Expand All @@ -19,6 +19,9 @@ class Obj
{
use StaticClassMixin;

/**
* @param object $object
*/
public static function dumpHash($object): string
{
return substr(md5(spl_object_hash($object)), 0, 4);
Expand Down
1 change: 1 addition & 0 deletions src/common/lists/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ public static function slice(array $array, int $from, ?int $length = null): arra

/**
* @param mixed[] $array
* @param int<1, max> $size
* @return mixed[]
*/
public static function chunks(array $array, int $size): array
Expand Down
3 changes: 3 additions & 0 deletions src/common/lists/ImmutableArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ public function slice(int $from, ?int $length = null): self
return new static(array_slice($this->toArray(), $from, $length, self::PRESERVE_KEYS));
}

/**
* @param int<1, max> $size
*/
public function chunks(int $size): self
{
$res = new static(array_chunk($this->toArray(), $size, self::PRESERVE_KEYS));
Expand Down
8 changes: 1 addition & 7 deletions src/common/mixins/NonSerializableMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Dogma;

use const PHP_VERSION;

trait NonSerializableMixin
{

Expand All @@ -21,11 +19,7 @@ trait NonSerializableMixin
*/
final public function __sleep(): array
{
if (PHP_VERSION !== '') {
throw new NonSerializableObjectException(static::class);
}

return [];
throw new NonSerializableObjectException(static::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Http/responder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
[$min, $max] = [$max, $min];
}

$request[$option] = random_int($min, $max);
$request[$option] = random_int($min, $max); // @phpstan-ignore-line
} else {
$size = abs((int) $_GET[$option]);
if (strpos($_GET[$option], 'K') !== false) {
Expand Down

0 comments on commit a499af0

Please sign in to comment.