Skip to content

Commit 8801915

Browse files
Missing
1 parent c32624c commit 8801915

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/Reflection/MethodReflection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ public function getThrowType(): ?Type;
3030

3131
public function hasSideEffects(): TrinaryLogic;
3232

33+
/**
34+
* Has the #[\NoDiscard] attribute - on PHP 8.5+ if the function's return
35+
* value is unused at runtime a warning is emitted, phpstan will emit the
36+
* warning during analysis and on older PHP versions too
37+
*/
38+
public function hasNoDiscardAttribute(): TrinaryLogic;
39+
3340
}

src/Reflection/Native/NativeFunctionReflection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,14 @@ public function getAttributes(): array
150150
return $this->attributes;
151151
}
152152

153+
public function hasNoDiscardAttribute(): TrinaryLogic
154+
{
155+
foreach ($this->attributes as $attrib) {
156+
if ($attrib->getName() === 'NoDiscard') {
157+
return TrinaryLogic::createYes();
158+
}
159+
}
160+
return TrinaryLogic::createNo();
161+
}
162+
153163
}

src/Reflection/Native/NativeMethodReflection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,14 @@ public function getAttributes(): array
227227
return $this->attributes;
228228
}
229229

230+
public function hasNoDiscardAttribute(): TrinaryLogic
231+
{
232+
foreach ($this->attributes as $attrib) {
233+
if ($attrib->getName() === 'NoDiscard') {
234+
return TrinaryLogic::createYes();
235+
}
236+
}
237+
return TrinaryLogic::createNo();
238+
}
239+
230240
}

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,4 +520,14 @@ public function getAttributes(): array
520520
return $this->attributes;
521521
}
522522

523+
public function hasNoDiscardAttribute(): TrinaryLogic
524+
{
525+
foreach ($this->attributes as $attrib) {
526+
if ($attrib->getName() === 'NoDiscard') {
527+
return TrinaryLogic::createYes();
528+
}
529+
}
530+
return TrinaryLogic::createNo();
531+
}
532+
523533
}

0 commit comments

Comments
 (0)