We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 11 |
| Total Lines | 69 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 2 | 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('What is the application name ?', config('app.name').' Backoffice'); |
||
| 31 | $backpackPrefix = config('backpack.base.route_prefix'); |
||
| 32 | $appColor = $this->ask('What is the application color ?', '#161c2d'); |
||
| 33 | $pathPrefix = $this->ask('Where should icon files be published relative to public folder?'); |
||
| 34 | |||
| 35 | $pathPrefix = Str::start(Str::finish($pathPrefix ?? '', '/'), '/'); |
||
| 36 | |||
| 37 | // laravel adds a dummy favicon with 0 bytes. we need to remove it otherwise our script would skip publishing the favicon on new Laravel installations. |
||
| 38 | // we will check the favicon file size, to make sure it's not a "valid" favicon. we will only delete the favicon if it has 0 bytes in size. |
||
| 39 | $this->checkIfFaviconIsLaravelDefault($pathPrefix); |
||
| 40 | |||
| 41 | $stubPath = __DIR__.'/../../../resources/stubs/'; |
||
| 42 | |||
| 43 | $filesToPublish = [ |
||
| 44 | public_path($pathPrefix.'site.webmanifest') => $stubPath.'manifest.stub', |
||
| 45 | resource_path('views/vendor/backpack/ui/inc/header_metas.blade.php') => $stubPath.'header_metas.stub', |
||
| 46 | public_path($pathPrefix.'browserconfig.xml') => $stubPath.'browserconfig.stub', |
||
| 47 | public_path($pathPrefix.'android-chrome-192x192.png') => __DIR__.'/../../../public/android-chrome-192x192.png', |
||
| 48 | public_path($pathPrefix.'android-chrome-192x192.png'), |
||
| 49 | public_path($pathPrefix.'android-chrome-512x512.png'), |
||
| 50 | public_path($pathPrefix.'apple-touch-icon.png'), |
||
| 51 | public_path($pathPrefix.'favicon-16x16.png'), |
||
| 52 | public_path($pathPrefix.'favicon-32x32.png'), |
||
| 53 | public_path($pathPrefix.'favicon.ico'), |
||
| 54 | public_path($pathPrefix.'safari-pinned-tab.svg'), |
||
| 55 | public_path($pathPrefix.'mstile-70x70.png'), |
||
| 56 | public_path($pathPrefix.'mstile-144x144.png'), |
||
| 57 | public_path($pathPrefix.'mstile-150x150.png'), |
||
| 58 | public_path($pathPrefix.'mstile-310x150.png'), |
||
| 59 | public_path($pathPrefix.'mstile-310x310.png'), |
||
| 60 | ]; |
||
| 61 | |||
| 62 | foreach ($filesToPublish as $destination => $stub) { |
||
| 63 | if (! is_string($destination)) { |
||
| 64 | $destination = $stub; |
||
| 65 | $stub = null; |
||
| 66 | } |
||
| 67 | |||
| 68 | if (File::exists($destination)) { |
||
| 69 | $this->comment("The file {$destination} already exists. Skipping."); |
||
| 70 | |||
| 71 | continue; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (! File::isDirectory(dirname($destination))) { |
||
| 75 | File::makeDirectory(dirname($destination), 0755, true); |
||
| 76 | } |
||
| 77 | |||
| 78 | if (! $stub) { |
||
| 79 | File::copy(__DIR__.'/../../../public/'.basename($destination), $destination); |
||
| 80 | $this->info("File {$destination} published."); |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | $stub = File::get($stub); |
||
| 85 | |||
| 86 | $stub = str_replace('__APP_NAME__', $appName, $stub); |
||
| 87 | $stub = str_replace('__APP_COLOR__', $appColor, $stub); |
||
| 88 | $stub = str_replace('__BACKPACK_PREFIX__', $backpackPrefix, $stub); |
||
| 89 | $stub = str_replace('__PATH_PREFIX__', $pathPrefix, $stub); |
||
| 90 | |||
| 91 | File::put($destination, $stub); |
||
| 92 | |||
| 93 | $this->info("File {$destination} published."); |
||
| 94 | } |
||
| 95 | |||
| 96 | $this->comment('[DONE] Metas and favicon assets published successfully.'); |
||
| 97 | } |
||
| 110 |