SkipScriptByAttribute::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\DeferJs\Helper\Config;
13
use Hryvinskyi\DeferJs\Model\PassesValidator\ValidatorInterface;
14
use Magento\Framework\App\Response\Http;
15
16
/**
17
 * Class SkipScriptByAttribute
18
 */
19
class SkipScriptByAttribute implements ValidatorInterface
20
{
21
    /**
22
     * @var Config
23
     */
24
    private $config;
25
26
    /**
27
     * SkipScriptByAttribute constructor.
28
     *
29
     * @param Config $config
30
     */
31
    public function __construct(Config $config)
32
    {
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * Validator function, handle javascript or not
38
     *
39
     * @param string $script
40
     * @param Http $http
41
     *
42
     * @return bool
43
     */
44
    public function validate(string $script, Http $http): bool
45
    {
46
        $return = false;
47
48
        if (stripos($script, $this->config->getDisableAttribute()) !== false) {
49
            $return = true;
50
        }
51
52
        return $return;
53
    }
54
}
55