Passed
Push — v5 ( 848feb...023ea9 )
by Andrew
29:11 queued 22:46
created

ViteVariableTrait::integrity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Vite plugin for Craft CMS
4
 *
5
 * Allows the use of the Vite.js next generation frontend tooling with Craft CMS
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2021 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\pluginvite\variables;
12
13
use craft\helpers\Template;
14
use nystudio107\pluginvite\services\ViteService;
15
use Twig\Markup;
16
use yii\base\InvalidConfigException;
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Vite
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.0.4
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
trait ViteVariableTrait
24
{
25
    // Public Properties
26
    // =========================================================================
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var null|ViteService the Vite service
30
     */
31
    public ?ViteService $viteService = null;
32
33
    // Public Methods
34
    // =========================================================================
35
36
    /**
37
     * Return the appropriate tags to load the Vite script, either via the dev server or
38
     * extracting it from the manifest.json file
39
     *
40
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
41
     * @param bool $asyncCss
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
42
     * @param array $scriptTagAttrs
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
43
     * @param array $cssTagAttrs
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
44
     *
45
     * @return Markup
46
     */
47
    public function script(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): Markup
48
    {
49
        return Template::raw(
50
            $this->viteService->script($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs)
0 ignored issues
show
Bug introduced by
The method script() does not exist on null. ( Ignorable by Annotation )

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

50
            $this->viteService->/** @scrutinizer ignore-call */ 
51
                                script($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        );
52
    }
53
54
    /**
55
     * Register the appropriate tags to the Craft View to load the Vite script, either via the dev server or
56
     * extracting it from the manifest.json file
57
     *
58
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
59
     * @param bool $asyncCss
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
60
     * @param array $scriptTagAttrs
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
61
     * @param array $cssTagAttrs
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
62
     *
63
     * @return Markup
64
     * @throws InvalidConfigException
65
     */
66
    public function register(string $path, bool $asyncCss = true, array $scriptTagAttrs = [], array $cssTagAttrs = []): Markup
67
    {
68
        $this->viteService->register($path, $asyncCss, $scriptTagAttrs, $cssTagAttrs);
69
70
        return Template::raw('');
71
    }
72
73
    /**
74
     * Return the URL for the given entry
75
     *
76
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
77
     *
78
     * @return Markup
79
     */
80
    public function entry(string $path): Markup
81
    {
82
        return Template::raw(
83
            $this->viteService->entry($path)
84
        );
85
    }
86
87
    /**
88
     * Return the integrity hash (or an empty string if not present) for the given entry
89
     *
90
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
91
     *
92
     * @return string
93
     */
94
    public function integrity(string $path): string
95
    {
96
        return Template::raw(
97
            $this->viteService->integrity($path)
98
        );
99
    }
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $public should have a doc-comment as per coding-style.
Loading history...
102
     * Return the URL for the given asset
103
     *
104
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
105
     *
106
     * @return Markup
107
     */
108
    public function asset(string $path, bool $public = false): Markup
109
    {
110
        return Template::raw(
111
            $this->viteService->asset($path, $public)
112
        );
113
    }
114
115
    /**
116
     * Inline the contents of a local file (via path) or remote file (via URL) in your templates.
117
     * Yii2 aliases and/or environment variables may be used
118
     *
119
     * @param string $pathOrUrl
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
120
     *
121
     * @return Markup
122
     */
123
    public function inline(string $pathOrUrl): Markup
124
    {
125
        $file = $this->viteService->fetch($pathOrUrl);
126
        if ($file === null) {
127
            $file = '';
128
        }
129
130
        return Template::raw($file);
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type array; however, parameter $value of craft\helpers\Template::raw() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

130
        return Template::raw(/** @scrutinizer ignore-type */ $file);
Loading history...
131
    }
132
133
    /**
134
     * Determine whether the Vite dev server is running
135
     *
136
     * @return bool
137
     */
138
    public function devServerRunning(): bool
139
    {
140
        return $this->viteService->devServerRunning();
141
    }
142
}
143