| 1 | <?php |
||
| 18 | abstract class AbstractTarget implements TargetInterface |
||
| 19 | { |
||
| 20 | protected $id; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var TypeInterface |
||
| 24 | */ |
||
| 25 | protected $type; |
||
| 26 | |||
| 27 | 3 | public function __construct($id, TypeInterface $type) |
|
| 28 | { |
||
| 29 | 3 | $this->id = $id; |
|
| 30 | 3 | $this->type = $type; |
|
| 31 | 3 | $this->uniqId = $type->getName() . ':' . $id; |
|
|
|
|||
| 32 | 3 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @return int |
||
| 36 | */ |
||
| 37 | public function getId() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | public function getType() |
||
| 46 | { |
||
| 47 | return $this->type; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 2 | public function getUniqId() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | 2 | public function equals(TargetInterface $other) |
|
| 65 | |||
| 66 | public function jsonSerialize() |
||
| 70 | } |
||
| 71 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: