Skip to content

Commit

Permalink
Increase PHPStan rule level to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 17, 2024
1 parent c3d954c commit 4445658
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 9
level: 10
paths:
- src
- tests/unit
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Factory
private static ?Factory $instance = null;

/**
* @var list<Comparator>
* @var array<non-negative-int, Comparator>
*/
private array $customComparators = [];

Expand Down
4 changes: 4 additions & 0 deletions src/NumericComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace SebastianBergmann\Comparator;

use function abs;
use function assert;
use function is_float;
use function is_infinite;
use function is_nan;
Expand All @@ -32,6 +33,9 @@ public function accepts(mixed $expected, mixed $actual): bool
*/
public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void
{
assert(is_numeric($expected));
assert(is_numeric($actual));

if ($this->isInfinite($actual) && $this->isInfinite($expected)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/_fixture/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
class Author
{
// the order of properties is important for testing the cycle!
public $books = [];
private $name = '';
public array $books = [];
private string $name;

public function __construct($name)
public function __construct(string $name)
{
$this->name = $name;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/_fixture/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
class Book
{
// the order of properties is important for testing the cycle!
public $author;
public Author $author;
}
8 changes: 4 additions & 4 deletions tests/unit/ArrayComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ArrayComparatorTest extends TestCase
private ArrayComparator $comparator;

/**
* @return non-empty-list<array{0: ?array, 1: ?array}>
* @return non-empty-list<array{0: ?array<null>, 1: ?array<null>}>
*/
public static function acceptsFailsProvider(): array
{
Expand All @@ -35,7 +35,7 @@ public static function acceptsFailsProvider(): array
}

/**
* @return non-empty-list<array{0: array, 1: array, 2?: float, 3?: bool}>
* @return non-empty-list<array{0: array<mixed>, 1: array<mixed>, 2?: float, 3?: bool}>
*/
public static function assertEqualsSucceedsProvider(): array
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public static function assertEqualsSucceedsProvider(): array
}

/**
* @return non-empty-list<array{0: array, 1: array, 2?: float, 3?: bool}>
* @return non-empty-list<array{0: array<mixed>, 1: array<mixed>, 2?: float, 3?: bool}>
*/
public static function assertEqualsFailsProvider(): array
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public static function assertEqualsFailsProvider(): array
}

/**
* @return non-empty-list<array{0: string, 1: array, 2: array, 3?: float, 4?: bool}>
* @return non-empty-list<array{0: string, 1: array<string>, 2: array<string>, 3?: float, 4?: bool}>
*/
public static function assertEqualsFailsWithDiffProvider(): array
{
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/MockObjectComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public static function assertEqualsFailsProvider(): array
$book2->author->books[] = $book2;

$book3 = self::createMockForComparatorTest(Book::class);
$book3->author = 'Terry Pratchett';
$book3->author = new Author('Terry Pratchett');
$book4 = self::createMockForComparatorTest(stdClass::class);
$book4->author = 'Terry Pratchett';
$book4->author = new Author('Terry Pratchett');

$object1 = self::createMockForComparatorTest(SampleClass::class, [4, 8, 15]);
$object2 = self::createMockForComparatorTest(SampleClass::class, [16, 23, 42]);
Expand Down Expand Up @@ -174,7 +174,7 @@ public function testAssertEqualsFails(MockObject $expected, MockObject $actual,
* @template RealInstanceType of object
*
* @param class-string<RealInstanceType> $type
* @param array<mixed> $constructorArguments
* @param list<mixed> $constructorArguments
*
* @return MockObject&RealInstanceType
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ObjectComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public static function assertEqualsFailsProvider(): array
$book2->author->books[] = $book2;

$book3 = new Book;
$book3->author = 'Terry Pratchett';
$book3->author = new Author('Terry Pratchett');
$book4 = new stdClass;
$book4->author = 'Terry Pratchett';
$book4->author = new Author('Terry Pratchett');

$object1 = new SampleClass(4, 8, 15);
$object2 = new SampleClass(16, 23, 42);
Expand Down

0 comments on commit 4445658

Please sign in to comment.