1 | <?php |
||||
2 | |||||
3 | namespace Noitran\CsFixer\Console; |
||||
4 | |||||
5 | use Illuminate\Console\Command; |
||||
6 | use Symfony\Component\Process\Process; |
||||
7 | use Symfony\Component\Process\Exception\ProcessFailedException; |
||||
8 | |||||
9 | /** |
||||
10 | * Class HookSetupCommand |
||||
11 | */ |
||||
12 | class HookSetupCommand extends Command |
||||
13 | { |
||||
14 | /** |
||||
15 | * The console command name. |
||||
16 | * |
||||
17 | * @var string |
||||
18 | */ |
||||
19 | protected $name = 'phpcs:install-hook'; |
||||
20 | |||||
21 | /** |
||||
22 | * The name and signature of the console command. |
||||
23 | * |
||||
24 | * @var string |
||||
25 | */ |
||||
26 | protected $signature = 'phpcs:install-hook'; |
||||
27 | |||||
28 | /** |
||||
29 | * The console command description. |
||||
30 | * |
||||
31 | * @var string |
||||
32 | */ |
||||
33 | protected $description = 'Installs pre-commit git hook to run phpcs every on code changes.'; |
||||
34 | |||||
35 | /** |
||||
36 | * Handles the Command |
||||
37 | */ |
||||
38 | public function handle(): void |
||||
39 | { |
||||
40 | $hookFile = config('phpcs.git_pre_commit_file'); |
||||
41 | $gitHooksPath = config('phpcs.git_hooks_path'); |
||||
42 | |||||
43 | $this->copyPreCommitHook($hookFile, $gitHooksPath); |
||||
44 | $this->setPermissions($gitHooksPath); |
||||
45 | } |
||||
46 | |||||
47 | /** |
||||
48 | * @param $hookFile |
||||
49 | * @param $gitHooksPath |
||||
50 | * |
||||
51 | * @return void |
||||
52 | */ |
||||
53 | protected function copyPreCommitHook($hookFile, $gitHooksPath): void |
||||
54 | { |
||||
55 | $process = new Process('cp ' . $hookFile . ' ' . $gitHooksPath . '/'); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
56 | $process->run(); |
||||
57 | |||||
58 | if (! $process->isSuccessful()) { |
||||
59 | throw new ProcessFailedException($process); |
||||
60 | } |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * @param $gitHooksPath |
||||
65 | * |
||||
66 | * @return void |
||||
67 | */ |
||||
68 | protected function setPermissions($gitHooksPath): void |
||||
69 | { |
||||
70 | $process = new Process('chmod +x ' . $gitHooksPath . '/pre-commit'); |
||||
0 ignored issues
–
show
'chmod +x ' . $gitHooksPath . '/pre-commit' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
71 | $process->run(); |
||||
72 | |||||
73 | if (! $process->isSuccessful()) { |
||||
74 | throw new ProcessFailedException($process); |
||||
75 | } |
||||
76 | } |
||||
77 | } |
||||
78 |