Passed
Push — master ( d775ca...750957 )
by Володимир
04:15 queued 10s
created

SkipScriptsByPath   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 2
A __construct() 0 6 1
1
<?php
2
/**
3
 * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
declare(strict_types=1);
9
10
namespace Hryvinskyi\DeferJs\Model\PassesValidator\Validators;
11
12
use Hryvinskyi\Base\Helper\ArrayHelper;
13
use Hryvinskyi\Base\Helper\Json;
14
use Hryvinskyi\DeferJs\Helper\Config;
15
use Hryvinskyi\DeferJs\Model\PassesValidator\ValidatorInterface;
16
use Magento\Framework\App\Request\Http as RequestHttp;
17
use Magento\Framework\App\Response\Http;
18
19
/**
20
 * Class SkipScriptsByPath
21
 */
22
class SkipScriptsByPath implements ValidatorInterface
23
{
24
    /**
25
     * @var Config
26
     */
27
    private $config;
28
29
    /**
30
     * @var RequestHttp
31
     */
32
    private $request;
33
34
    /**
35
     * SkipScriptsByController constructor.
36
     *
37
     * @param Config $config
38
     * @param RequestHttp $request
39
     */
40
    public function __construct(
41
        Config $config,
42
        RequestHttp $request
43
    ) {
44
        $this->config = $config;
45
        $this->request = $request;
46
    }
47
48
    /**
49
     * Validator function, handle javascript or not
50
     *
51
     * @param string $script
52
     * @param Http $http
53
     *
54
     * @return bool
55
     */
56
    public function validate(string $script, Http $http): bool
57
    {
58
        $paths = Json::decode($this->config->getExcludePaths());
59
        $paths = ArrayHelper::getColumn($paths, 'path', false);
60
61
        $return = false;
62
63
        if (in_array($this->request->getRequestUri(), $paths)) {
64
            $return = true;
65
        }
66
67
        return $return;
68
    }
69
}
70