Passed
Push — v1 ( b1dea4...d09897 )
by Andrew
15:26 queued 07:45
created

ManifestController::actionResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 doc comment for class ManifestController
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
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 4
Loading history...
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