| Total Complexity | 4 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class ResolveModelName extends AbstractAction |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var AbstractModel |
||
| 16 | */ |
||
| 17 | private $model; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var bool |
||
| 21 | */ |
||
| 22 | private $short; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * ResolveModelName constructor. |
||
| 26 | * |
||
| 27 | * @param AbstractModel $model |
||
| 28 | * @param bool $short |
||
| 29 | */ |
||
| 30 | public function __construct(AbstractModel $model, bool $short = true) |
||
| 31 | { |
||
| 32 | $this->model = $model; |
||
| 33 | $this->short = $short; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Retrieve the Model class's short name (without namespace). |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function execute() |
||
| 42 | { |
||
| 43 | // Split string on upper case characters |
||
| 44 | return implode(' ', (new StringHelpers($this->getClassName()))->camelCaseSplit()); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Retrieve the name from the Model's class name or the table name. |
||
| 49 | * |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | private function getClassName(): string |
||
| 53 | { |
||
| 54 | return LaravelHelpers::getClassName($this->model, $this->short, $this->getTableCamelCase()); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Convert table name to a CamelCase string for consistency with Model names. |
||
| 59 | * |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | private function getTableCamelCase(): string |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | } |
||
| 75 |