Passed
Push — v1 ( b5a719...67f63c )
by Andrew
12:46 queued 05:01
created

ServicesTrait::getPlaceholder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * ImageOptimize plugin for Craft CMS
4
 *
5
 * Automatically optimize images after they've been transformed
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) 2022 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\imageoptimize\services;
12
13
use craft\helpers\ArrayHelper;
14
use nystudio107\imageoptimize\assetbundles\imageoptimize\ImageOptimizeAsset;
15
use nystudio107\imageoptimize\services\Optimize as OptimizeService;
16
use nystudio107\imageoptimize\services\OptimizedImages as OptimizedImagesService;
17
use nystudio107\imageoptimize\services\Placeholder as PlaceholderService;
18
use nystudio107\pluginvite\services\VitePluginService;
19
use yii\base\InvalidConfigException;
20
21
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
 * @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...
23
 * @package   ImageOptimize
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
24
 * @since     1.6.49
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...
25
 *
26
 * @property OptimizeService $optimize
27
 * @property PlaceholderService $placeholder
28
 * @property OptimizedImagesService $optimizedImages
29
 * @property VitePluginService $vite
30
 */
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...
31
trait ServicesTrait
32
{
33
    // Public Methods
34
    // =========================================================================
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $id should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $parent should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $config should have a doc-comment as per coding-style.
Loading history...
37
     * @inheritdoc
38
     */
39
    public function __construct($id, $parent = null, array $config = [])
40
    {
41
        // Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['vite']
42
        // ref: https://github.com/craftcms/cms/issues/1989
43
        $config = ArrayHelper::merge([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
44
            'components' => [
45
                'optimize' => OptimizeService::class,
46
                'optimizedImages' => OptimizedImagesService::class,
47
                'placeholder' => PlaceholderService::class,
48
                // Register the vite service
49
                'vite' => [
50
                    'class' => VitePluginService::class,
51
                    'assetClass' => ImageOptimizeAsset::class,
52
                    'useDevServer' => true,
53
                    'devServerPublic' => 'http://localhost:3001',
54
                    'serverPublic' => 'http://localhost:8000',
55
                    'errorEntry' => 'src/js/ImageOptimize.js',
56
                    'devServerInternal' => 'http://craft-imageoptimize-buildchain:3001',
57
                    'checkDevServer' => true,
58
                ],
59
            ]
60
        ], $config);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
61
62
        parent::__construct($id, $parent, $config);
63
    }
64
65
    /**
66
     * Returns the optimize service
67
     *
68
     * @return OptimizeService The optimize service
69
     * @throws InvalidConfigException
70
     */
71
    public function getOptimize(): OptimizeService
72
    {
73
        return $this->get('optimize');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

73
        return $this->/** @scrutinizer ignore-call */ get('optimize');
Loading history...
74
    }
75
76
    /**
77
     * Returns the optimizedImages service
78
     *
79
     * @return OptimizedImagesService The optimizedImages service
80
     * @throws InvalidConfigException
81
     */
82
    public function getOptimizedImages(): OptimizedImagesService
83
    {
84
        return $this->get('optimizedImages');
85
    }
86
87
    /**
88
     * Returns the placeholder service
89
     *
90
     * @return PlaceholderService The placeholder service
91
     * @throws InvalidConfigException
92
     */
93
    public function getPlaceholder(): PlaceholderService
94
    {
95
        return $this->get('placeholder');
96
    }
97
98
    /**
99
     * Returns the vite service
100
     *
101
     * @return VitePluginService The vite service
102
     * @throws InvalidConfigException
103
     */
104
    public function getVite(): VitePluginService
105
    {
106
        return $this->get('vite');
107
    }
108
}
109