-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARPHP-1476 S1144 should not raise an issue when a magic method is …
…available via a trait (#1152)
- Loading branch information
1 parent
0f1aaca
commit 5f84cac
Showing
3 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
php-checks/src/test/resources/checks/UnusedPrivateMethodCheckWithTraits.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
class MagicMethodCallBase | ||
{ | ||
use MyTraitWithMagicMethodCallWithCallUserFuncArrayFunction; | ||
|
||
private function bar() | ||
{ | ||
// Compliant as bar() can be called in the trait | ||
} | ||
} | ||
|
||
class MagicMethodCallChild extends MagicMethodCallBase | ||
{ | ||
|
||
// TODO SONARPHP-1482 FP because we can't access traits of a superclass in symbols | ||
private function foo() // Noncompliant | ||
{ | ||
} | ||
} | ||
|
||
trait MyTraitWithMagicMethodCallWithCallUserFuncArrayFunction | ||
{ | ||
public function __call($method, $arguments) | ||
{ | ||
if (method_exists($this, $method)) { | ||
return call_user_func_array([$this, $method], $arguments); | ||
} | ||
trigger_error('Call to undefined method '.__CLASS__.'::'.$method.'()', E_USER_ERROR); | ||
} | ||
} | ||
|
||
class MagicMethodCallFalseNegativeBase | ||
{ | ||
use MyTraitWithMagicMethodCallWithoutBody; | ||
|
||
// TODO SONARPHP-1481 FN because in trait in __call the call of call_user_func_array or call_user_func is missing | ||
private function bar() | ||
{ | ||
} | ||
} | ||
|
||
trait MyTraitWithMagicMethodCallWithoutBody | ||
{ | ||
public function __call($method, $arguments) | ||
{ | ||
// The call of call_user_func_array or call_user_func is missing | ||
} | ||
} | ||
|
||
class MagicMethodCallBase2 | ||
{ | ||
use MyTraitWithoutMagicMethodCall; | ||
|
||
private function bar() // Noncompliant | ||
{ | ||
} | ||
} | ||
|
||
class MagicMethodCallChild2 extends MagicMethodCallBase2 | ||
{ | ||
private function foo() // Noncompliant | ||
{ | ||
} | ||
} | ||
|
||
trait MyTraitWithoutMagicMethodCall | ||
{ | ||
public function foo() | ||
{ | ||
} | ||
} | ||
|
||
class MagicMethodCall3 | ||
{ | ||
use NonExistingTrait; | ||
|
||
private function bar() // Noncompliant | ||
{ | ||
} | ||
} | ||
|
||
class MagicMethodCall4 extends MagicMethodCall3 | ||
{ | ||
private function foo() // Noncompliant | ||
{ | ||
} | ||
} |