1 | <?php |
||
2 | |||
3 | namespace ArcherZdip\LaravelApiAuth\Console\Commands; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
0 ignored issues
–
show
|
|||
6 | use ArcherZdip\LaravelApiAuth\Models\AppClient; |
||
7 | |||
8 | class GenerateAppAuth extends Command |
||
9 | { |
||
10 | /** |
||
11 | * Error messages |
||
12 | */ |
||
13 | const MESSAGE_ERROR_INVALID_NAME_FORMAT = 'Invalid name. Must be a lowercase alphabetic characters, numbers and hyphens less than 255 characters long.'; |
||
14 | const MESSAGE_ERROR_NAME_ALREADY_USED = 'Name is unavailable.'; |
||
15 | /** |
||
16 | * The name and signature of the console command. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $signature = 'apikey:generate {name}'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = "Generate a new appId"; |
||
28 | |||
29 | /** |
||
30 | * Create a new command instance. |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function __construct() |
||
35 | { |
||
36 | parent::__construct(); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Execute the console command. |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function handle() |
||
45 | { |
||
46 | $name = $this->argument('name'); |
||
47 | |||
48 | $this->validateName($name); |
||
49 | |||
50 | $attributes = [ |
||
51 | 'name' => $name, |
||
52 | 'appid' => AppClient::generateAppId(), |
||
53 | 'secret' => AppClient::generateSecret(), |
||
54 | ]; |
||
55 | |||
56 | /** @var AppClient $appClient */ |
||
57 | $appClient = AppClient::forceCreate($attributes); |
||
58 | $headers = ['AppName', 'appId', 'secret', 'CreateAt']; |
||
59 | $rows = [ |
||
60 | $appClient->name, |
||
61 | $appClient->appid, |
||
62 | $appClient->secret, |
||
63 | $appClient->created_at |
||
64 | ]; |
||
65 | $this->table($headers, [$rows]); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * validate name |
||
70 | * |
||
71 | * @param string $name |
||
72 | * @return null |
||
73 | */ |
||
74 | protected function validateName(string $name) |
||
75 | { |
||
76 | if (!AppClient::isValidName($name)) { |
||
77 | $this->error(self::MESSAGE_ERROR_INVALID_NAME_FORMAT); |
||
78 | exit(); |
||
0 ignored issues
–
show
|
|||
79 | } |
||
80 | |||
81 | if (AppClient::nameExists($name)) { |
||
82 | $this->error(self::MESSAGE_ERROR_NAME_ALREADY_USED); |
||
83 | exit(); |
||
0 ignored issues
–
show
|
|||
84 | } |
||
85 | |||
86 | return null; |
||
87 | } |
||
88 | } |
||
89 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths