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

OptimizeController::actionClear()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 19
rs 9.2222
c 0
b 0
f 0
cc 6
nc 6
nop 0
1
<?php
2
/**
3
 * Image Optimize 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\console\controllers;
12
13
use nystudio107\imageoptimize\ImageOptimize;
14
15
use Craft;
16
use craft\base\Volume;
17
use craft\helpers\App;
18
use craft\helpers\FileHelper;
19
use craft\utilities\ClearCaches;
20
21
use yii\console\Controller;
22
23
/**
24
 * Optimize Command
25
 *
26
 * @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...
27
 * @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...
28
 * @since     1.2.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...
29
 */
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...
30
class OptimizeController extends Controller
31
{
32
    // Public Methods
33
    // =========================================================================
34
35
    /**
36
     * Create all of the OptimizedImages Field variants by creating all of the
37
     * responsive image variant transforms
38
     *
39
     * @param string|null $volumeHandle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
40
     *
41
     * @throws \yii\base\InvalidConfigException
42
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
43
    public function actionCreate($volumeHandle = null)
44
    {
45
        echo 'Creating optimized image variants'.PHP_EOL;
46
47
        if ($volumeHandle === null) {
48
            // Re-save all of the optimized image variants in all volumes
49
            ImageOptimize::$plugin->optimizedImages->resaveAllVolumesAssets();
50
        } else {
51
            // Re-save all of the optimized image variants in a specific volume
52
            $volumes = Craft::$app->getVolumes();
53
            $volume = $volumes->getVolumeByHandle($volumeHandle);
54
            if ($volume) {
55
                /** @var Volume $volume */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
56
                ImageOptimize::$plugin->optimizedImages->resaveVolumeAssets($volume);
57
            } else {
58
                echo 'Unknown Asset Volume handle: '.$volumeHandle.PHP_EOL;
59
            }
60
        }
61
        // This might take a while
62
        App::maxPowerCaptain();
63
        Craft::$app->getQueue()->run();
64
    }
65
}
66