Skip to content

Commit

Permalink
Updated PHPStan; min PHP version is 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Feb 24, 2023
1 parent 6e569c3 commit 99696a3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
8 changes: 8 additions & 0 deletions build/PHPStan/phpstan.neon
Expand Up @@ -38,6 +38,14 @@ parameters:
-
message: '~Negated boolean expression is always true~'
path: "../../src/common/lists/ImmutableArray.php"
-
message: '~Strict comparison using === between \*NEVER\* and 0 will always evaluate to false~'
path: "../../tests/src/Http/responder.php"

# Re flags & WTFs
- '~Parameter #4 \$flags of function preg_match expects TFlags of 0|256|512|768, int given.~'
- '~Method Dogma\\Re::match\(\) should return array<string>\|null but returns array<array<int, int\|string\|null>\|string\|null>.~'
- '~Method Dogma\\Re::submatch\(\) should return string\|null but returns array<int, int\|string\|null>\|string\|null.~'

# interface
- '~^PHPDoc tag @return with type Dogma\\Language\\Locale\\LocaleCollationOption is not subtype of native type Dogma\\Enum\\StringEnum~'
Expand Down
18 changes: 6 additions & 12 deletions composer.json
Expand Up @@ -11,14 +11,14 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^7.4|^8.0",
"ext-calendar":"*",
"nette/http": "~2.4|~3.0",
"nette/utils": "~2.4|~3.0|~4.0"
},
"require-dev": {
"dogma/dogma-dev": "0.1.29",
"phpstan/phpstan": "1.8.2"
"phpstan/phpstan": "1.10.2"
},
"suggest": {
"ext-dom": "for Dom (basic functionality)",
Expand Down Expand Up @@ -76,9 +76,7 @@
"php82 vendor/nette/tester/src/tester tests -c tests --colors 1",
"php81 vendor/nette/tester/src/tester tests -c tests --colors 1",
"php80 vendor/nette/tester/src/tester tests -c tests --colors 1",
"php74 vendor/nette/tester/src/tester tests -c tests --colors 1",
"php73 vendor/nette/tester/src/tester tests -c tests --colors 1",
"php72 vendor/nette/tester/src/tester tests -c tests --colors 1"
"php74 vendor/nette/tester/src/tester tests -c tests --colors 1"
],
"tests:coverage": "php vendor/nette/tester/src/tester tests -c tests --colors 1 -p phpdbg --coverage tests/coverage.html --coverage-src src",

Expand All @@ -87,19 +85,15 @@
"php82 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon",
"php81 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon",
"php80 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon",
"php74 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon",
"php73 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon",
"php72 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon"
"php74 vendor/phpstan/phpstan/phpstan analyse --memory-limit 256M -c build/PHPStan/phpstan.neon"
],

"lint:php": "php vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"lint:php-all": [
"php82 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"php81 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"php80 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"php74 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"php73 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests",
"php72 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests"
"php74 vendor/php-parallel-lint/php-parallel-lint/parallel-lint src tests"
],

"phpcs:all": [
Expand Down Expand Up @@ -156,7 +150,7 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"sllh/composer-versions-check": true
"sllh/composer-versions-check": false
}
}
}
4 changes: 3 additions & 1 deletion src/Dom/NodeList.php
Expand Up @@ -15,9 +15,10 @@
use DOMNode;
use DOMNodeList;
use Iterator;
use ReturnTypeWillChange;

/**
* @implements Iterator<int, DOMNode>
* @implements Iterator<int, Element|DOMNode>
*/
class NodeList implements Countable, Iterator
{
Expand Down Expand Up @@ -65,6 +66,7 @@ public function count(): int
/**
* @return Element|DOMNode
*/
#[ReturnTypeWillChange]
public function current()
{
/** @var DOMNode $item */
Expand Down
2 changes: 2 additions & 0 deletions src/Io/Filesystem/DirectoryIterator.php
Expand Up @@ -10,6 +10,7 @@
namespace Dogma\Io\Filesystem;

use FilesystemIterator;
use ReturnTypeWillChange;
use UnexpectedValueException;

class DirectoryIterator extends FilesystemIterator
Expand Down Expand Up @@ -53,6 +54,7 @@ public function setFlags($flags = null): void
/**
* @return FileInfo|mixed
*/
#[ReturnTypeWillChange]
public function current()
{
if (!($this->flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($this->flags & FilesystemIterator::CURRENT_AS_SELF)) {
Expand Down
6 changes: 4 additions & 2 deletions src/Io/Filesystem/RecursiveDirectoryIterator.php
Expand Up @@ -11,6 +11,7 @@

use FilesystemIterator;
use RecursiveDirectoryIterator as PhpRecursiveDirectoryIterator;
use ReturnTypeWillChange;
use UnexpectedValueException;

class RecursiveDirectoryIterator extends PhpRecursiveDirectoryIterator
Expand Down Expand Up @@ -44,7 +45,7 @@ public function __construct(string $path, ?int $flags = null)
public function setFlags($flags = null): void
{
$this->flags = $flags;
if ($flags & FilesystemIterator::CURRENT_AS_FILEINFO) {
if (!($flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($flags & FilesystemIterator::CURRENT_AS_SELF)) {
parent::setFlags($flags | FilesystemIterator::CURRENT_AS_PATHNAME);
} else {
parent::setFlags($flags);
Expand All @@ -54,9 +55,10 @@ public function setFlags($flags = null): void
/**
* @return FileInfo|mixed
*/
#[ReturnTypeWillChange]
public function current()
{
if ($this->flags & FilesystemIterator::CURRENT_AS_FILEINFO) {
if (!($this->flags & FilesystemIterator::CURRENT_AS_PATHNAME) && !($this->flags & FilesystemIterator::CURRENT_AS_SELF)) {
/** @var string $path */
$path = parent::current();

Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/MappingIterator.php
Expand Up @@ -15,6 +15,7 @@
use Dogma\Type;
use Iterator;
use IteratorAggregate;
use ReturnTypeWillChange;
use function is_array;

/**
Expand Down Expand Up @@ -77,6 +78,7 @@ public function valid(): bool
/**
* @return mixed|null
*/
#[ReturnTypeWillChange]
public function current()
{
if ($this->reverse) {
Expand Down
3 changes: 1 addition & 2 deletions src/common/Str.php
Expand Up @@ -14,14 +14,12 @@

use Collator as PhpCollator;
use Dogma\Language\Collator;
use Dogma\Language\Encoding;
use Dogma\Language\Locale\Locale;
use Dogma\Language\Transliterator;
use Dogma\Language\UnicodeCharacterCategory;
use Error;
use Nette\Utils\Strings;
use UConverter;
use const MB_CASE_TITLE;
use function array_keys;
use function array_pop;
use function array_shift;
Expand Down Expand Up @@ -53,6 +51,7 @@
use function strrpos;
use function strtolower;
use function substr;
use const MB_CASE_TITLE;

/**
* UTF-8 strings manipulation
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Http/responder.php
Expand Up @@ -143,7 +143,7 @@
if ($request['time']) {
$chunkSize = (int) ($request['size'] / $request['time']);
for ($n = 0; $n < $request['size']; $n++) {
if ($n % $chunkSize === 0) {
if (($n % $chunkSize) === 0) {
sleep(1);
}
if ($n % 100 === 0) {
Expand Down
5 changes: 5 additions & 0 deletions tests/src/common/Re.phpt
Expand Up @@ -12,3 +12,8 @@ pos:
Assert::same(Re::pos('abc@def', '~#~'), null);
Assert::same(Re::pos('abc@def', '~@~'), 3);
Assert::same(Re::pos('abc@def', '~@([def])~'), 3);

submatch:
Assert::same(Re::submatch('abc@def', '~(abc)~'), 'abc');
Assert::same(Re::submatch('abc@def', '~(def)~'), 'def');
Assert::same(Re::submatch('abc@def', '~(foo)~'), null);

0 comments on commit 99696a3

Please sign in to comment.