Issues (1)

src/Tailwind.php (1 issue)

1
<?php
2
3
namespace Badworks\TailwindPreset;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Foundation\Console\Presets\Preset;
8
9
class Tailwind extends Preset
10
{
11
    public static function install()
12
    {
13
        static::ensureComponentDirectoryExists();
14
        static::updatePackages();
15
        static::updateStyles();
16
        static::updateJavaScript();
17
        static::updateTemplates();
18
        static::removeNodeModules();
19
        static::updateConfigurations();
20
    }
21
22
    protected static function updatePackageArrayDev(array $packages)
23
    {
24
        return array_merge([
25
            '@babel/plugin-proposal-class-properties' => '^7.4.4',
26
            '@babel/plugin-proposal-decorators' => '^7.4.4',
27
            'laravel-mix-purgecss' => '^4.x',
28
            'postcss-easy-import' => '^3.0.0',
29
            'postcss-preset-env' => '^6.6.0',
30
            'vue-template-compiler' => '^2.x',
31
        ], Arr::except($packages, [
32
            'stylelint-scss',
33
            'axios',
34
            'bootstrap',
35
            'bootstrap-sass',
36
            'jquery',
37
            'lodash',
38
            'popper.js',
39
            'sass',
40
            'sass-loader',
41
            'stylelint-scss',
42
            'vue',
43
        ]));
44
    }
45
46
    protected static function updatePackageArray()
47
    {
48
        return [
49
            'axios' => '^0.18',
50
            'tailwindcss' => '^1.0.1',
51
            'vue' => '^2.x',
52
            'vue-template-compiler' => '^2.x',
53
            'vue-property-decorator' => '^7.3.0',
54
        ];
55
    }
56
57
    protected static function updateStyles()
58
    {
59
        tap(new Filesystem(), function ($files) {
60
            $files->deleteDirectory(resource_path('sass'));
61
            $files->delete(public_path('css/app.pcss'));
62
            $files->copyDirectory(__DIR__.'/stubs/css', resource_path('css'));
63
        });
64
    }
65
66
    protected static function updateJavaScript()
67
    {
68
        tap(new Filesystem(), function ($files) {
69
            $files->deleteDirectory(resource_path('js'));
70
            $files->copyDirectory(__DIR__.'/stubs/js', resource_path('js'));
71
        });
72
    }
73
74
    protected static function updateTemplates()
75
    {
76
        tap(new Filesystem(), function ($files) {
77
            $files->delete(resource_path('views/home.blade.php'));
78
            $files->delete(resource_path('views/welcome.blade.php'));
79
            if (! $files->isDirectory($directory = resource_path('views/layouts'))) {
80
                $files->makeDirectory($directory, 0755, true);
81
            }
82
        });
83
        copy(__DIR__.'/stubs/views/layouts/base.blade.php', resource_path('views/layouts/base.blade.php'));
84
        copy(__DIR__.'/stubs/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
85
    }
86
87
    protected static function updateConfigurations()
88
    {
89
        copy(__DIR__.'/stubs/gitignore.stub', base_path('.gitignore'));
90
        copy(__DIR__.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
91
    }
92
93
    protected static function updatePackages($dev = true)
94
    {
95
        if (! file_exists(base_path('package.json'))) {
96
            return;
97
        }
98
        $packages = json_decode(file_get_contents(base_path('package.json')), true);
99
100
        $packages['devDependencies'] = static::updatePackageArrayDev(
101
            $packages['devDependencies']
102
        );
103
        ksort($packages['devDependencies']);
104
105
        $packages['dependencies'] = static::updatePackageArray($packages['dependencies'] ?? []);
0 ignored issues
show
The call to Badworks\TailwindPreset\...d::updatePackageArray() has too many arguments starting with $packages['dependencies'] ?? array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        /** @scrutinizer ignore-call */ 
106
        $packages['dependencies'] = static::updatePackageArray($packages['dependencies'] ?? []);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
106
        ksort($packages['dependencies']);
107
108
        file_put_contents(
109
            base_path('package.json'),
110
            json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL
111
        );
112
    }
113
}
114