Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — add-all-select-option-on-check... ( 105cf5...a52589 )
by Pedro
11:29
created

PublishHeaderMetas   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
eloc 52
c 3
b 2
f 1
dl 0
loc 97
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIfFaviconIsLaravelDefault() 0 7 3
B handle() 0 69 6
1
<?php
2
3
namespace Backpack\CRUD\app\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\File;
7
use Illuminate\Support\Str;
8
9
class PublishHeaderMetas extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'backpack:publish-header-metas';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Publishes the header metas and favicon assets.';
24
25
    /**
26
     * Execute the console command.
27
     */
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::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
    }
98
99
    private function checkIfFaviconIsLaravelDefault(string $path)
100
    {
101
        if (File::exists(public_path($path.'favicon.ico'))) {
102
            // check the file size. if it's 0 it's the laravel dummy favicon, remove it.
103
            if (filesize(public_path($path.'favicon.ico')) === 0) {
104
                File::delete(public_path($path.'favicon.ico'));
105
                $this->comment('[INFO] We deleted the Laravel dummy favicon. Publishing assets now.');
106
            }
107
        }
108
    }
109
}
110