We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 7 |
Paths | 22 |
Total Lines | 61 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
28 | public function handle() |
||
29 | { |
||
30 | $appName = $this->ask('Whats the application name ?', 'Backpack'); |
||
31 | $appUrl = $this->ask('Whats the application url ?', config('app.url')); |
||
32 | $backpackPrefix = config('backpack.base.route_prefix'); |
||
33 | $appColor = $this->ask('Whats the application color ?', '#605ca8'); |
||
34 | $pathPrefix = $this->ask('Where should icon files be published relative to public folder?'); |
||
35 | |||
36 | if ( $pathPrefix) { |
||
37 | $pathPrefix = Str::finish($pathPrefix, '/'); |
||
38 | } |
||
39 | |||
40 | $fileToPublish = [ |
||
41 | public_path($pathPrefix.'manifest.json') => __DIR__.'/../../../resources/stubs/manifest.stub', |
||
42 | public_path($pathPrefix.'site.webmanifest') => __DIR__.'/../../../resources/stubs/manifest.stub', |
||
43 | resource_path('views/vendor/backpack/ui/inc/header_metas.blade.php') => __DIR__.'/../../../resources/stubs/header_metas.stub', |
||
44 | public_path($pathPrefix.'android-chrome-192x192.png'), |
||
45 | public_path($pathPrefix.'android-chrome-512x512.png'), |
||
46 | public_path($pathPrefix.'apple-touch-icon.png'), |
||
47 | public_path($pathPrefix.'favicon-16x16.png'), |
||
48 | public_path($pathPrefix.'favicon-32x32.png'), |
||
49 | public_path($pathPrefix.'favicon.ico'), |
||
50 | public_path($pathPrefix.'safari-pinned-tab.svg'), |
||
51 | ]; |
||
52 | |||
53 | foreach ($fileToPublish as $destination => $stub) { |
||
54 | if (! is_string($destination)) { |
||
55 | $destination = $stub; |
||
56 | $stub = null; |
||
57 | } |
||
58 | |||
59 | if (File::exists($destination)) { |
||
60 | $this->comment("The file {$destination} already exists. Skipping."); |
||
61 | |||
62 | continue; |
||
63 | } |
||
64 | |||
65 | if (! File::isDirectory(dirname($destination))) { |
||
66 | File::makeDirectory(dirname($destination), 0755, true); |
||
67 | } |
||
68 | |||
69 | if (! $stub) { |
||
70 | File::copy(__DIR__.'/../../../public/'.basename($destination), $destination); |
||
71 | $this->info("File {$destination} published."); |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | $stub = File::get($stub); |
||
76 | |||
77 | $stub = str_replace('__APP_NAME__', $appName, $stub); |
||
78 | $stub = str_replace('__APP_URL__', $appUrl, $stub); |
||
79 | $stub = str_replace('__APP_COLOR__', $appColor, $stub); |
||
80 | $stub = str_replace('__BACKPACK_PREFIX__', $backpackPrefix, $stub); |
||
81 | $stub = str_replace('__PATH_PREFIX__', $pathPrefix, $stub); |
||
82 | |||
83 | File::put($destination, $stub); |
||
84 | |||
85 | $this->info("File {$destination} published."); |
||
86 | } |
||
87 | |||
88 | $this->info('Metas and assets published successfully.'); |
||
89 | } |
||
91 |