Passed
Push — master ( c74e22...4ec3b5 )
by Володимир
04:11
created

SkipScriptByAttribute::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
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
        $this->config = $config;
33
    }
34
35
    /**
36
     * Validator function, handle javascript or not
37
     *
38
     * @param string $script
39
     * @param Http $http
40
     *
41
     * @return bool
42
     */
43
    public function validate(string $script, Http $http): bool
44
    {
45
        $return = false;
46
47
        if (stripos($script, $this->config->getDisableAttribute()) !== false) {
48
            $return = true;
49
        }
50
51
        return $return;
52
    }
53
}