Passed
Push — develop ( 164850...0d721c )
by Andrew
04:24
created

ManifestController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 9
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionResource() 0 10 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace nystudio107\imageoptimize\controllers;
4
5
use nystudio107\imageoptimize\assetbundles\imageoptimize\ImageOptimizeAsset;
6
7
use Craft;
8
use craft\web\Controller;
9
10
use yii\web\Response;
11
12
class ManifestController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing class doc comment
Loading history...
13
{
14
    // Protected Properties
15
    // =========================================================================
16
17
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
     * @var    bool|array
19
     */
20
    protected $allowAnonymous = [
21
        'resource'
22
    ];
23
24
    // Public Methods
25
    // =========================================================================
26
27
    /**
28
     * Make webpack async bundle loading work out of published AssetBundles
29
     *
30
     * @param string $resourceType
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
31
     * @param string $fileName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
32
     *
33
     * @return Response
34
     */
35
    public function actionResource(string $resourceType = '', string $fileName = ''): Response
36
    {
37
        $bundle = new ImageOptimizeAsset();
38
        $baseAssetsUrl = Craft::$app->assetManager->getPublishedUrl(
39
            $bundle->sourcePath,
40
            true
41
        );
42
        $url = "{$baseAssetsUrl}/{$resourceType}/{$fileName}";
43
44
        return $this->redirect($url);
45
    }
46
47
    // Protected Methods
48
    // =========================================================================
49
}
50