Skip to content

Commit

Permalink
Upgrade PHPStan version
Browse files Browse the repository at this point in the history
Also install "phpstan/extension-installer" to make it simpler to install
extensions.
  • Loading branch information
henriquemoody committed Nov 29, 2024
1 parent a974c0c commit 60840c0
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 19 deletions.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"require": {
Expand All @@ -28,9 +29,10 @@
"malukenho/docheader": "^1.0",
"mikey179/vfsstream": "^1.6",
"nette/php-generator": "^4.1",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5",
"psr/http-message": "^1.0 || ^2.0",
"respect/coding-standard": "^4.0",
Expand Down
1 change: 0 additions & 1 deletion library/Rules/ContainsAny.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class ContainsAny extends Envelope
/** @param non-empty-array<mixed> $needles */
public function __construct(array $needles, bool $identical = false)
{
// @phpstan-ignore-next-line
if (empty($needles)) {
throw new InvalidRuleConstructorException('At least one value must be provided');
}
Expand Down
4 changes: 2 additions & 2 deletions library/Rules/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ private function parseRange(string $input): void
if (mb_strpos($input, '-') !== false) {
[$this->startAddress, $this->endAddress] = explode('-', $input);

if ($this->startAddress !== null && !$this->verifyAddress($this->startAddress)) {
if (is_string($this->startAddress) && !$this->verifyAddress($this->startAddress)) {
throw new InvalidRuleConstructorException('Invalid network range');
}

if ($this->endAddress !== null && !$this->verifyAddress($this->endAddress)) {
if (is_string($this->endAddress) && !$this->verifyAddress($this->endAddress)) {
throw new InvalidRuleConstructorException('Invalid network range');
}

Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Nif.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ private function validateCif(string $number, string $control): bool
{
$code = 0;
$position = 1;
/** @var int $digit */
foreach (str_split($number) as $digit) {
$digit = (int) $digit;
$increaser = $digit;
if ($position % 2 !== 0) {
$increaser = array_sum(str_split((string) ($digit * 2)));
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/NotBlank.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function isBlank(mixed $input): bool
}

if (is_array($input)) {
$input = array_filter($input, __METHOD__);
$input = array_filter($input, fn($value) => $this->isBlank($value));
}

return !empty($input);
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
fileExtensions:
- php
Expand Down Expand Up @@ -34,6 +30,7 @@ parameters:
- message: '/Call to an undefined static method Respect\\Validation\\Validator::type\(\)./'
path: tests/integration/transformers/deprecated_type.phpt
level: 8
treatPhpDocTypesAsCertain: false
paths:
- library/
- tests/
6 changes: 6 additions & 0 deletions tests/library/Stubs/CountableStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

final class CountableStub implements Countable
{
/**
* @param positive-int $value
*/
public function __construct(
private readonly int $value
) {
}

/**
* @return positive-int
*/
public function count(): int
{
return $this->value;
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#[CoversClass(Validator::class)]
final class ValidatorTest extends TestCase
{
#[Test]
public function staticCreateShouldReturnNewValidator(): void
{
self::assertInstanceOf(Validator::class, Validator::create());
}

#[Test]
public function invalidRuleClassShouldThrowComponentException(): void
{
Expand Down

0 comments on commit 60840c0

Please sign in to comment.