| Total Complexity | 5 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class ResolveModelName extends Action |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Model|string |
||
| 14 | */ |
||
| 15 | private $model; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var bool |
||
| 19 | */ |
||
| 20 | private $short; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * ResolveModelName constructor. |
||
| 24 | * |
||
| 25 | * @param Model|string $model |
||
| 26 | * @param bool $short |
||
| 27 | */ |
||
| 28 | public function __construct($model, bool $short = true) |
||
| 29 | { |
||
| 30 | $this->model = $model; |
||
| 31 | $this->short = $short; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Retrieve the Model class's short name (without namespace). |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public function execute(): string |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Retrieve the name from the Model's class name or the table name. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | private function getClassName(): string |
||
| 51 | { |
||
| 52 | return LaravelHelpers::getClassName( |
||
| 53 | $this->model, |
||
| 54 | $this->short, |
||
| 55 | ! is_string($this->model) ? $this->getTableCamelCase() : null |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Convert table name to a CamelCase string for consistency with Model names. |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | private function getTableCamelCase(): string |
||
| 73 | ) |
||
| 74 | ); |
||
| 77 |