| 1 | <?php  | 
            ||
| 9 | trait RecordsTrait  | 
            ||
| 10 | { | 
            ||
| 11 | /**  | 
            ||
| 12 | * @var null|string  | 
            ||
| 13 | */  | 
            ||
| 14 | protected $foreignKey = null;  | 
            ||
| 15 | |||
| 16 | /**  | 
            ||
| 17 | * The name of the field used as a foreign key in other tables  | 
            ||
| 18 | * @return string  | 
            ||
| 19 | */  | 
            ||
| 20 | 8 | public function getPrimaryFK()  | 
            |
| 28 | |||
| 29 | 6 | public function initPrimaryFK()  | 
            |
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * @param string $foreignKey  | 
            ||
| 36 | */  | 
            ||
| 37 | 6 | public function setForeignKey($foreignKey)  | 
            |
| 41 | |||
| 42 | /**  | 
            ||
| 43 | * @return string  | 
            ||
| 44 | */  | 
            ||
| 45 | 5 | public function generatePrimaryFK()  | 
            |
| 51 | |||
| 52 | /**  | 
            ||
| 53 | * @param $fk  | 
            ||
| 54 | */  | 
            ||
| 55 | 3 | public function setPrimaryFK($fk)  | 
            |
| 59 | }  | 
            ||
| 60 | 
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.