| 1 | <?php |
||
| 20 | trait TrackingRenamerTrait |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Renamed variables |
||
| 24 | * |
||
| 25 | * @var string[] |
||
| 26 | **/ |
||
| 27 | private $renamed = array(); |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Record renaming of method |
||
| 31 | * |
||
| 32 | * @param string $method |
||
| 33 | * @param string $newName |
||
| 34 | * @return SkipTrait |
||
|
|
|||
| 35 | **/ |
||
| 36 | protected function renamed($method, $newName) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Has a method been renamed? |
||
| 45 | * |
||
| 46 | * @param string $method |
||
| 47 | * @return bool |
||
| 48 | **/ |
||
| 49 | protected function isRenamed($method) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get new name of a method |
||
| 65 | * |
||
| 66 | * @param string $method |
||
| 67 | * @return string |
||
| 68 | **/ |
||
| 69 | protected function getNewName($method) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Reset renamed list |
||
| 83 | * |
||
| 84 | * @return SkipTrait |
||
| 85 | **/ |
||
| 86 | protected function resetRenamed() |
||
| 92 | } |
||
| 93 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.