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 18, 2024
1 parent 5d5e186 commit 6351aa6
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 25 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
10 changes: 2 additions & 8 deletions src/ReflectionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public function fromParameterTypes(ReflectionFunction|ReflectionMethod $reflecto
foreach ($reflector->getParameters() as $parameter) {
$name = $parameter->getName();

assert($name !== '');

if (!$parameter->hasType()) {
$parameters[] = new Parameter($name, new UnknownType);

Expand Down Expand Up @@ -90,9 +88,7 @@ public function fromReturnType(ReflectionFunction|ReflectionMethod $reflector):
return $this->mapUnionType($returnType, $reflector);
}

if ($returnType instanceof ReflectionIntersectionType) {
return $this->mapIntersectionType($returnType, $reflector);
}
return $this->mapIntersectionType($returnType, $reflector);
}

public function fromPropertyType(ReflectionProperty $reflector): Type
Expand All @@ -113,9 +109,7 @@ public function fromPropertyType(ReflectionProperty $reflector): Type
return $this->mapUnionType($propertyType, $reflector);
}

if ($propertyType instanceof ReflectionIntersectionType) {
return $this->mapIntersectionType($propertyType, $reflector);
}
return $this->mapIntersectionType($propertyType, $reflector);
}

private function mapNamedType(ReflectionNamedType $type, ReflectionFunction|ReflectionMethod|ReflectionProperty $reflector): Type
Expand Down
6 changes: 0 additions & 6 deletions src/type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ private function isClassCallback(SimpleType $type): bool
[$className, $methodName] = $type->value();
}

/** @phpstan-ignore isset.variable */
assert(isset($className));

/** @phpstan-ignore isset.variable */
assert(isset($methodName));

if (!class_exists($className)) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace SebastianBergmann\Type;

use function array_is_list;
use function assert;
use function count;
use function implode;
Expand All @@ -35,7 +34,7 @@ public function __construct(Type ...$types)
$this->ensureOnlyValidTypes(...$types);
$this->ensureNoDuplicateTypes(...$types);

assert(array_is_list($types) && !empty($types));
assert(!empty($types));

$this->types = $types;
}
Expand Down
10 changes: 2 additions & 8 deletions src/type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace SebastianBergmann\Type;

use function array_is_list;
use function assert;
use function count;
use function implode;
Expand All @@ -33,7 +32,7 @@ public function __construct(Type ...$types)
$this->ensureMinimumOfTwoTypes(...$types);
$this->ensureOnlyValidTypes(...$types);

assert(array_is_list($types) && !empty($types));
assert(!empty($types));

$this->types = $types;
}
Expand Down Expand Up @@ -76,12 +75,7 @@ public function name(): string

sort($types);

$name = implode('|', $types);

/** @phpstan-ignore empty.variable */
assert(!empty($name));

return $name;
return implode('|', $types);
}

public function allowsNull(): bool
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/CallableTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public function testObjectWithoutInvokeMethodCannotBeAssignedToCallable(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isCallable());

$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isGenericObject());
$this->assertFalse($this->type->isIntersection());
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/FalseTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testCanBeQueriedForType(): void
{
$type = new FalseType;

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isFalse());

/** @phpstan-ignore method.impossibleType */
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/GenericObjectTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public function testNonObjectCannotBeAssignedToGenericObject(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isGenericObject());

$this->assertFalse($this->type->isCallable());
$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isIntersection());
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/IntersectionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function testTypesCanBeQueried(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isIntersection());

$this->assertFalse($this->type->isCallable());
$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isGenericObject());
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/IterableTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function testSomethingThatIsNotIterableCannotBeAssignedToIterable(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isIterable());

$this->assertFalse($this->type->isCallable());
$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isGenericObject());
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/MixedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testCanBeQueriedForType(): void
{
$type = new MixedType;

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isMixed());

/** @phpstan-ignore method.impossibleType */
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/NeverTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testCanBeQueriedForType(): void
{
$type = new NeverType;

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isNever());

/** @phpstan-ignore method.impossibleType */
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/NullTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public function testCanBeRepresentedAsString(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isNull());

$this->assertFalse($this->type->isCallable());
$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isGenericObject());
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/ObjectTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public function testHasClassName(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->childClass->isObject());

$this->assertFalse($this->childClass->isCallable());
$this->assertFalse($this->childClass->isFalse());
$this->assertFalse($this->childClass->isGenericObject());
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/SimpleTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function testCanBeQueriedForType(): void
{
$type = new SimpleType('bool', false);

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isSimple());

/** @phpstan-ignore method.impossibleType */
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/StaticTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function testCanBeQueriedForType(): void
{
$type = new StaticType(TypeName::fromQualifiedName(stdClass::class), false);

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isStatic());

/** @phpstan-ignore method.impossibleType */
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/TrueTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testCanBeQueriedForType(): void
{
$type = new TrueType;

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isTrue());

/** @phpstan-ignore method.impossibleType */
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/UnionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public function testCanBeQueriedForType(): void
new SimpleType('string', false),
);

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isUnion());

/** @phpstan-ignore method.impossibleType */
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/type/UnknownTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function testCanBeRepresentedAsString(): void

public function testCanBeQueriedForType(): void
{
/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($this->type->isUnknown());

$this->assertFalse($this->type->isCallable());
$this->assertFalse($this->type->isFalse());
$this->assertFalse($this->type->isGenericObject());
Expand Down
1 change: 1 addition & 0 deletions tests/unit/type/VoidTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testCanBeQueriedForType(): void
{
$type = new VoidType;

/** @phpstan-ignore method.alreadyNarrowedType */
$this->assertTrue($type->isVoid());

/** @phpstan-ignore method.impossibleType */
Expand Down

0 comments on commit 6351aa6

Please sign in to comment.