Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<Node\Expr\ClassConstFetch>
Expand Down Expand Up @@ -71,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$referencedClasses = $classTypeResult->getReferencedClasses();
$referencedClasses = TypeCombinator::intersect($classTypeResult->getType(), new ObjectWithoutClassType())->getObjectClassNames();
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<MethodCallableNode>
Expand Down Expand Up @@ -52,7 +54,7 @@ public function processNode(Node $node, Scope $scope): array

$methodName = $node->getName()->name;
$methodCalledOnType = $scope->getType($node->getVar());
$referencedClasses = $methodCalledOnType->getObjectClassNames();
$referencedClasses = TypeCombinator::intersect($methodCalledOnType, new ObjectWithoutClassType())->getObjectClassNames();

$errors = [];

Expand Down
4 changes: 3 additions & 1 deletion src/Rules/RestrictedUsage/RestrictedMethodUsageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<MethodCall>
Expand Down Expand Up @@ -52,7 +54,7 @@ public function processNode(Node $node, Scope $scope): array

$methodName = $node->name->name;
$methodCalledOnType = $scope->getType($node->var);
$referencedClasses = $methodCalledOnType->getObjectClassNames();
$referencedClasses = TypeCombinator::intersect($methodCalledOnType, new ObjectWithoutClassType())->getObjectClassNames();

$errors = [];

Expand Down
4 changes: 3 additions & 1 deletion src/Rules/RestrictedUsage/RestrictedPropertyUsageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<Node\Expr\PropertyFetch>
Expand Down Expand Up @@ -51,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array

$propertyName = $node->name->name;
$propertyCalledOnType = $scope->getType($node->var);
$referencedClasses = $propertyCalledOnType->getObjectClassNames();
$referencedClasses = TypeCombinator::intersect($propertyCalledOnType, new ObjectWithoutClassType())->getObjectClassNames();

$errors = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<StaticMethodCallableNode>
Expand Down Expand Up @@ -72,7 +74,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$referencedClasses = $classTypeResult->getReferencedClasses();
$referencedClasses = TypeCombinator::intersect($classTypeResult->getType(), new ObjectWithoutClassType())->getObjectClassNames();
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<Node\Expr\StaticCall>
Expand Down Expand Up @@ -71,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$referencedClasses = $classTypeResult->getReferencedClasses();
$referencedClasses = TypeCombinator::intersect($classTypeResult->getType(), new ObjectWithoutClassType())->getObjectClassNames();
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<Node\Expr\StaticPropertyFetch>
Expand Down Expand Up @@ -71,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$referencedClasses = $classTypeResult->getReferencedClasses();
$referencedClasses = TypeCombinator::intersect($classTypeResult->getType(), new ObjectWithoutClassType())->getObjectClassNames();
}

$errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\TypeCombinator;

/**
* @implements Rule<Cast\String_>
Expand Down Expand Up @@ -43,7 +45,7 @@ public function processNode(Node $node, Scope $scope): array
}

$exprType = $scope->getType($node->expr);
$referencedClasses = $exprType->getObjectClassNames();
$referencedClasses = TypeCombinator::intersect($exprType, new ObjectWithoutClassType())->getObjectClassNames();

$errors = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;

/**
* @extends RuleTestCase<RestrictedClassConstantUsageRule>
Expand Down Expand Up @@ -41,6 +42,17 @@ public function testRule(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot access FOO',
53,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public function testRule(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot call doFoo',
50,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Rules\Rule as TRule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;

/**
* @extends RuleTestCase<RestrictedMethodUsageRule>
Expand All @@ -29,6 +30,33 @@ public function testRule(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot call doFoo',
48,
],
[
'Cannot call doFoo',
49,
],
[
'Cannot call doFoo',
57,
],
[
'Cannot call doFoo',
57,
],
[
'Cannot call doFoo',
59,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Rules\Rule as TRule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;

/**
* @extends RuleTestCase<RestrictedPropertyUsageRule>
Expand All @@ -29,6 +30,33 @@ public function testRule(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot access $foo',
51,
],
[
'Cannot access $foo',
52,
],
[
'Cannot access $foo',
58,
],
[
'Cannot access $foo',
58,
],
[
'Cannot access $foo',
60,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public function testBug12951(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot call doFoo',
55,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public function testBug12951(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot call doFoo',
54,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Rules\Rule as TRule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;

/**
* @extends RuleTestCase<RestrictedStaticPropertyUsageRule>
Expand Down Expand Up @@ -52,6 +53,17 @@ public function testBug12951(): void
]);
}

#[RequiresPhp('>= 8.1.0')]
public function testNullable(): void
{
$this->analyse([__DIR__ . '/data/restricted-nullable.php'], [
[
'Cannot access $foo',
56,
],
]);
}

public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function testRule(): void
'Cannot call __toString',
11,
],
[
'Cannot call __toString',
26,
],
]);
}

Expand Down
Loading
Loading