| 1 | <?php  | 
            ||
| 19 | trait GameMode  | 
            ||
| 20 | { | 
            ||
| 21 | //<editor-fold desc="Fields">  | 
            ||
| 22 | /**  | 
            ||
| 23 | * @ORM\Column(type="smallint", nullable=true)  | 
            ||
| 24 | * @var int|null  | 
            ||
| 25 | */  | 
            ||
| 26 | private $gameMode;  | 
            ||
| 27 | //</editor-fold desc="Fields">  | 
            ||
| 28 | |||
| 29 | //<editor-fold desc="Public Methods">  | 
            ||
| 30 | /**  | 
            ||
| 31 | * @return int|null  | 
            ||
| 32 | */  | 
            ||
| 33 | public function getGameMode(): ?int  | 
            ||
| 37 | |||
| 38 | /**  | 
            ||
| 39 | * @param int|null $gameMode  | 
            ||
| 40 | * @return $this|GameMode  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 41 | * @throws ValueNotValid  | 
            ||
| 42 | */  | 
            ||
| 43 | public function setGameMode(?int $gameMode)  | 
            ||
| 51 | //</editor-fold desc="Public Methods">  | 
            ||
| 52 | }  | 
            
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.