Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 487c7ca

Browse files
committed
Add InAnyClassScope scope
1 parent 6db6c4b commit 487c7ca

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

‎src/Analyser/InAnyClassScope.php‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Reflection\ClassMemberAccessAnswerer;
6+
use PHPStan\Reflection\ClassReflection;
7+
use PHPStan\Reflection\ConstantReflection;
8+
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\PropertyReflection;
10+
11+
class InAnyClassScope implements ClassMemberAccessAnswerer
12+
{
13+
14+
/** @api */
15+
public function __construct()
16+
{
17+
}
18+
19+
public function isInClass(): bool
20+
{
21+
return true;
22+
}
23+
24+
public function getClassReflection(): ?ClassReflection
25+
{
26+
return null;
27+
}
28+
29+
public function canAccessProperty(PropertyReflection $propertyReflection): bool
30+
{
31+
return $propertyReflection->isPublic();
32+
}
33+
34+
public function canCallMethod(MethodReflection $methodReflection): bool
35+
{
36+
return $methodReflection->isPublic();
37+
}
38+
39+
public function canAccessConstant(ConstantReflection $constantReflection): bool
40+
{
41+
return $constantReflection->isPublic();
42+
}
43+
44+
}

‎src/Type/Constant/ConstantArrayType.php‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPStan\Type\Constant;
44

5-
use PHPStan\Analyser\OutOfClassScope;
5+
use PHPStan\Analyser\InAnyClassScope;
66
use PHPStan\Reflection\ClassMemberAccessAnswerer;
77
use PHPStan\Reflection\InaccessibleMethod;
88
use PHPStan\Reflection\ParametersAcceptor;
@@ -316,13 +316,7 @@ public function equals(Type $type): bool
316316

317317
public function isCallable(): TrinaryLogic
318318
{
319-
// @todo is there a way to fetch the full scope here.
320-
// An OutOfClassScope causes frivolous errors when checking if a
321-
// non-static method was invoked statically in its own class, which
322-
// is allowed per: https://3v4l.org/mTa9S.
323-
// Should add an optional scope parameter to isCallable and if null,
324-
// create a new OutOfClassScope instance.
325-
$typeAndMethod = $this->findTypeAndMethodName(new OutOfClassScope());
319+
$typeAndMethod = $this->findTypeAndMethodName(new InAnyClassScope());
326320
if ($typeAndMethod === null) {
327321
return TrinaryLogic::createNo();
328322
}
@@ -397,7 +391,7 @@ public function findTypeAndMethodName(?ClassMemberAccessAnswerer $scope = null):
397391
$has = $has->and(TrinaryLogic::createMaybe());
398392
}
399393
if ($scope === null) {
400-
$scope = new OutOfClassScope();
394+
$scope = new InAnyClassScope();
401395
}
402396
if (
403397
$isClassString

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /