Passed
Push — develop ( ba8028...b93325 )
by Andrew
11:03
created

CraftImageTransform   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 20
c 1
b 0
f 0
dl 0
loc 91
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A displayName() 0 3 1
A init() 0 5 1
A getSettingsHtml() 0 9 1
A rules() 0 7 1
A getTransformUrl() 0 7 1
A getWebPUrl() 0 5 1
A fields() 0 3 1
1
<?php
2
/**
3
 * ImageOptimize plugin for Craft CMS 3.x
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) 2018 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\imagetransforms;
12
13
use nystudio107\imageoptimize\ImageOptimize;
14
15
use Craft;
16
use craft\elements\Asset;
17
use craft\models\AssetTransform;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @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...
21
 * @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...
22
 * @since     1.6.0
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...
23
 */
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...
24
class CraftImageTransform extends ImageTransform
25
{
26
    // Static Methods
27
    // =========================================================================
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @inheritdoc
31
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
32
    public static function displayName(): string
33
    {
34
        return Craft::t('image-optimize', 'Craft');
35
    }
36
37
    // Public Properties
38
    // =========================================================================
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @var bool
42
     */
43
    public $generateTransformsBeforePageLoad;
44
45
    // Public Methods
46
    // =========================================================================
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @inheritDoc
50
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
51
    public function init()
52
    {
53
        $settings = ImageOptimize::$plugin->getSettings();
54
        // Get our $generateTransformsBeforePageLoad setting
55
        $this->generateTransformsBeforePageLoad = $settings->generateTransformsBeforePageLoad ?? true;
56
    }
57
58
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $asset should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $transform should have a doc-comment as per coding-style.
Loading history...
59
     * @inheritDoc
60
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
61
    public function getTransformUrl(Asset $asset, $transform)
62
    {
63
        // Generate the URLs to the optimized images
64
        $assets = Craft::$app->getAssets();
65
        $url = $assets->getAssetUrl($asset, $transform, $this->generateTransformsBeforePageLoad);
66
67
        return $url;
68
    }
69
70
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $url should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $asset should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $transform should have a doc-comment as per coding-style.
Loading history...
71
     * @inheritDoc
72
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
73
    public function getWebPUrl(string $url, Asset $asset, $transform): string
74
    {
75
        $url = $this->appendExtension($url, '.webp');
76
77
        return $url;
78
    }
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @inheritdoc
82
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
83
    public function getSettingsHtml()
84
    {
85
        $imageProcessors = ImageOptimize::$plugin->optimize->getActiveImageProcessors();
86
        $variantCreators = ImageOptimize::$plugin->optimize->getActiveVariantCreators();
87
88
        return Craft::$app->getView()->renderTemplate('craft-image-transform/settings/image-transforms/craft.twig', [
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...
89
            'imageTransform' => $this,
90
            'imageProcessors' => $imageProcessors,
91
            'variantCreators' => $variantCreators,
92
        ]);
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...
93
    }
94
95
    /**
96
     * No savable fields for this component
97
     *
98
     * @return array
99
     */
100
    public function fields()
101
    {
102
        return [];
103
    }
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
106
     * @inheritdoc
107
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
108
    public function rules()
109
    {
110
        $rules = parent::rules();
111
        $rules = array_merge($rules, [
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...
112
        ]);
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...
113
114
        return $rules;
115
    }
116
}
117