Skip to content

Commit 7e5c4a2

Browse files
committed
Add conditional check when suffix option is given
1 parent 718dd4e commit 7e5c4a2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Commands/Generators/UserModelGenerator.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function run(array $params): void
6565

6666
$class = $params[0] ?? CLI::getSegment(2) ?? 'UserModel';
6767

68-
if (in_array(strtolower($class), ['shielduser', 'shieldusermodel'], true)) {
68+
if (! $this->verifyChosenModelClassName($class, $params)) {
6969
CLI::error('Cannot use `ShieldUserModel` as class name as this conflicts with the parent class.', 'light_gray', 'red');
7070

7171
return; // @TODO when CI4 is at v4.3+, change this to `return 1;` to signify failing exit
@@ -75,4 +75,18 @@ public function run(array $params): void
7575

7676
$this->execute($params);
7777
}
78+
79+
/**
80+
* The chosen class name should not conflict with the alias of the parent class.
81+
*/
82+
private function verifyChosenModelClassName(string $class, array $params): bool
83+
{
84+
helper('inflector');
85+
86+
if (array_key_exists('suffix', $params) && ! strripos($class, 'Model')) {
87+
$class .= 'Model';
88+
}
89+
90+
return strtolower(pascalize($class)) !== 'shieldusermodel';
91+
}
7892
}

0 commit comments

Comments
 (0)