| 1 | <?php |
||
| 16 | trait NameEntity |
||
| 17 | { |
||
| 18 | //<editor-fold desc="Fields"> |
||
| 19 | /** |
||
| 20 | * @ORM\Column(type="string") |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $name; |
||
| 24 | //</editor-fold desc="Fields"> |
||
| 25 | |||
| 26 | //<editor-fold desc="Public Methods"> |
||
| 27 | /** |
||
| 28 | * @return string |
||
| 29 | */ |
||
| 30 | public function getName(): string |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $name |
||
| 37 | * @return $this|NameEntity |
||
|
|
|||
| 38 | */ |
||
| 39 | public function setName(string $name) |
||
| 44 | //</editor-fold desc="Public Methods"> |
||
| 45 | } |
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.