We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 13 |
Paths | 4 |
Total Lines | 117 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
36 | public function handle() |
||
37 | { |
||
38 | $this->progressBar = $this->output->createProgressBar(15); |
||
39 | $this->progressBar->minSecondsBetweenRedraws(0); |
||
40 | $this->progressBar->maxSecondsBetweenRedraws(120); |
||
41 | $this->progressBar->setRedrawFrequency(1); |
||
42 | |||
43 | $this->progressBar->start(); |
||
44 | |||
45 | $this->info(' Requiring DevTools. Please wait...'); |
||
46 | $this->progressBar->advance(); |
||
47 | |||
48 | // Check if auth exists |
||
49 | $details = null; |
||
50 | $process = new Process(['composer', 'config', 'http-basic.backpackforlaravel.com']); |
||
51 | $process->run(function ($type, $buffer) use (&$details) { |
||
52 | if ($type !== Process::ERR && $buffer !== '') { |
||
53 | $details = json_decode($buffer); |
||
54 | } elseif (File::exists('auth.json')) { |
||
55 | $details = json_decode(File::get('auth.json'), true)['http-basic']['backpackforlaravel.com'] ?? false; |
||
56 | } |
||
57 | $this->progressBar->advance(); |
||
58 | }); |
||
59 | |||
60 | // Create an auth.json file |
||
61 | if (! $details) { |
||
62 | $this->info(' Creating auth.json file with your authentication token'); |
||
63 | |||
64 | $this->line(' (Find your access token details on https://backpackforlaravel.com/user/tokens)'); |
||
65 | $username = $this->ask('Access token username'); |
||
66 | $password = $this->ask('Access token password'); |
||
67 | |||
68 | $process = new Process(['composer', 'config', 'http-basic.backpackforlaravel.com', $username, $password]); |
||
69 | $process->run(function ($type, $buffer) use ($username, $password) { |
||
|
|||
70 | if ($type === Process::ERR) { |
||
71 | // Fallback |
||
72 | $authFile = [ |
||
73 | 'http-basic' => [ |
||
74 | 'backpackforlaravel.com' => [ |
||
75 | 'username' => $username, |
||
76 | 'password' => $password, |
||
77 | ], |
||
78 | ], |
||
79 | ]; |
||
80 | |||
81 | if (File::exists('auth.json')) { |
||
82 | $currentFile = json_decode(File::get('auth.json'), true); |
||
83 | if (! ($currentFile['http-basic']['backpackforlaravel.com'] ?? false)) { |
||
84 | $authFile = array_merge_recursive($authFile, $currentFile); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | File::put('auth.json', json_encode($authFile, JSON_PRETTY_PRINT)); |
||
89 | } |
||
90 | $this->progressBar->advance(); |
||
91 | }); |
||
92 | } |
||
93 | |||
94 | // Check if repositories exists |
||
95 | $details = null; |
||
96 | $process = new Process(['composer', 'config', 'repositories.backpack/devtools']); |
||
97 | $process->run(function ($type, $buffer) use (&$details) { |
||
98 | if ($type !== Process::ERR && $buffer !== '') { |
||
99 | $details = json_decode($buffer); |
||
100 | } else { |
||
101 | $details = json_decode(File::get('composer.json'), true)['repositories']['backpack/devtools'] ?? false; |
||
102 | } |
||
103 | $this->progressBar->advance(); |
||
104 | }); |
||
105 | |||
106 | // Create repositories |
||
107 | if (! $details) { |
||
108 | $this->info(' Creating repositories entry in composer.json'); |
||
109 | |||
110 | $process = new Process(['composer', 'config', 'repositories.backpack/devtools', 'composer', 'https://repo.backpackforlaravel.com']); |
||
111 | $process->run(function ($type, $buffer) { |
||
112 | if ($type === Process::ERR) { |
||
113 | // Fallback |
||
114 | $composerJson = Str::of(File::get('composer.json')); |
||
115 | |||
116 | $currentRepositories = json_decode($composerJson, true)['repositories'] ?? false; |
||
117 | |||
118 | $repositories = Str::of(json_encode([ |
||
119 | 'repositories' => [ |
||
120 | 'backpack/devtools' => [ |
||
121 | 'type' => 'composer', |
||
122 | 'url' => 'https://repo.backpackforlaravel.com', |
||
123 | ], |
||
124 | ], |
||
125 | ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
126 | |||
127 | $composerJson = $currentRepositories |
||
128 | // Replace current repositories |
||
129 | ? preg_replace('/"repositories":\s{\r?\n/', $repositories->match("/\{\n\s+([\s\S]+)\n\s{4}\}/m")->append(",\n"), $composerJson) |
||
130 | // Append to the end of the file |
||
131 | : preg_replace("/\r?\n}/", $repositories->replaceFirst('{', ','), $composerJson); |
||
132 | |||
133 | File::put('composer.json', $composerJson); |
||
134 | } |
||
135 | $this->progressBar->advance(); |
||
136 | }); |
||
137 | } |
||
138 | |||
139 | // Require package |
||
140 | $process = new Process(['composer', 'require', '--dev', '--with-all-dependencies', 'backpack/devtools']); |
||
141 | $process->run(function ($type, $buffer) { |
||
142 | $this->progressBar->advance(); |
||
143 | }); |
||
144 | |||
145 | // Finish |
||
146 | $this->progressBar->finish(); |
||
147 | $this->info(' DevTools is now required.'); |
||
148 | |||
149 | // DevTools inside installer |
||
150 | $this->info(''); |
||
151 | $this->info(' Now running the DevTools installation command.'); |
||
152 | $this->call('backpack:devtools:install'); |
||
153 | } |
||
155 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.