| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Models\SmartProperties\Definitions\Definition; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Trait HasName |
||
| 7 | * @package ByTIC\Models\SmartProperties\Definitions\Traits |
||
| 8 | */ |
||
| 9 | trait HasName |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $name = null; |
||
| 16 | |||
| 17 | |||
| 18 | /** |
||
| 19 | * @return mixed |
||
| 20 | */ |
||
| 21 | public function getName(): ?string |
||
| 22 | { |
||
| 23 | if ($this->name === null) { |
||
| 24 | $this->initName(); |
||
| 25 | } |
||
| 26 | |||
| 27 | return $this->name; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param mixed $name |
||
| 32 | */ |
||
| 33 | public function setName($name) |
||
| 34 | { |
||
| 35 | $this->name = $name; |
||
| 36 | } |
||
| 37 | |||
| 38 | protected function initName() |
||
| 39 | { |
||
| 40 | $name = $this->getField(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | if (empty($name)) { |
||
| 42 | return; |
||
| 43 | } |
||
| 44 | $name = inflector()->classify($this->getField()); |
||
| 45 | $this->setName($name); |
||
| 46 | } |
||
| 47 | |||
| 48 | } |