Skip to content

Commit b853e39

Browse files
authored
Merge pull request #958 from ergebnis/fix/describe
Fix: Adjust `CallLikes\NoNamedArgumentRule` to describe known calls only
2 parents d572714 + 13efbb5 commit b853e39

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For a full diff see [`2.10.4...main`][2.10.4...main].
1111
### Fixed
1212

1313
- Adjusted `Methods\NoNamedArgumentRule` to handle calls to constructors of variable class names ([#957]), by [@localheinz]
14+
- Adjusted `Methods\NoNamedArgumentRule` to describe known calls only ([#958]), by [@localheinz]
1415

1516
## [`2.10.4`][2.10.4]
1617

@@ -706,6 +707,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
706707
[#949]: https://github.com/ergebnis/phpstan-rules/pull/949
707708
[#951]: https://github.com/ergebnis/phpstan-rules/pull/951
708709
[#957]: https://github.com/ergebnis/phpstan-rules/pull/957
710+
[#958]: https://github.com/ergebnis/phpstan-rules/pull/958
709711

710712
[@cosmastech]: https://github.com/cosmastech
711713
[@enumag]: https://github.com/enumag

src/CallLikes/NoNamedArgumentRule.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,54 +101,60 @@ private static function describeCallLike(
101101
}
102102

103103
if ($node instanceof Node\Expr\MethodCall) {
104-
/** @var Node\Identifier $methodName */
105104
$methodName = $node->name;
106105

107-
$objectType = $scope->getType($node->var);
106+
if ($methodName instanceof Node\Identifier) {
107+
$objectType = $scope->getType($node->var);
108108

109-
$methodReflection = $scope->getMethodReflection(
110-
$objectType,
111-
$methodName->name,
112-
);
109+
$methodReflection = $scope->getMethodReflection(
110+
$objectType,
111+
$methodName->name,
112+
);
113113

114-
if (null === $methodReflection) {
115-
throw new ShouldNotHappenException();
116-
}
114+
if (null === $methodReflection) {
115+
throw new ShouldNotHappenException();
116+
}
117117

118-
$declaringClass = $methodReflection->getDeclaringClass();
118+
$declaringClass = $methodReflection->getDeclaringClass();
119+
120+
if ($declaringClass->isAnonymous()) {
121+
return \sprintf(
122+
'Method %s() of anonymous class',
123+
$methodName->toString(),
124+
);
125+
}
119126

120-
if ($declaringClass->isAnonymous()) {
121127
return \sprintf(
122-
'Method %s() of anonymous class',
123-
$methodName,
128+
'Method %s::%s()',
129+
$declaringClass->getName(),
130+
$methodName->toString(),
124131
);
125132
}
126133

127-
return \sprintf(
128-
'Method %s::%s()',
129-
$declaringClass->getName(),
130-
$methodName,
131-
);
134+
return 'Method';
132135
}
133136

134137
if ($node instanceof Node\Expr\StaticCall) {
135-
$className = $node->class;
136-
137-
/** @var Node\Identifier $methodName */
138138
$methodName = $node->name;
139139

140-
if ($className instanceof Node\Expr\Variable) {
140+
if ($methodName instanceof Node\Identifier) {
141+
$className = $node->class;
142+
143+
if ($className instanceof Node\Name) {
144+
return \sprintf(
145+
'Method %s::%s()',
146+
$className->toString(),
147+
$methodName->toString(),
148+
);
149+
}
150+
141151
return \sprintf(
142152
'Method %s()',
143-
$methodName,
153+
$methodName->toString(),
144154
);
145155
}
146156

147-
return \sprintf(
148-
'Method %s::%s()',
149-
$className,
150-
$methodName,
151-
);
157+
return 'Method';
152158
}
153159

154160
if ($node instanceof Node\Expr\New_) {

0 commit comments

Comments
 (0)