Issues (10)

Helper/AbstractConfig.php (1 issue)

Labels
Severity
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\InvisibleCaptcha\Helper;
11
12
use Hryvinskyi\InvisibleCaptcha\Model\Area\ConfigInterface as AreaConfigInterface;
13
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
14
use Magento\Framework\App\Config\ScopeConfigInterface;
15
use Magento\Framework\App\Helper\AbstractHelper;
16
use Magento\Framework\App\Helper\Context;
17
use Magento\Framework\App\ObjectManager;
18
use Magento\Store\Model\ScopeInterface;
19
20
/**
21
 * Class AbstractConfig
22
 */
23
abstract class AbstractConfig extends AbstractHelper implements AreaConfigInterface
24
{
25
    /**
26
     * @var ConfigInterface
27
     */
28
    private $config;
29
30
    /**
31
     * General constructor.
32
     *
33
     * @param Context $context
34
     * @param ConfigInterface $config
35
     */
36
    public function __construct(
37
        Context $context,
38
        ConfigInterface $config = null
39
    ) {
40
        $this->config = $config ?: ObjectManager::getInstance()->get(ConfigInterface::class);
41
42
        parent::__construct($context);
43
    }
44
45
    /**
46
     * Is captcha enable
47
     *
48
     * @param string $scopeType
49
     * @param mixed $scopeCode
50
     *
51
     * @return bool
52
     */
53
    abstract public function hasEnabled(
54
        string $scopeType = ScopeInterface::SCOPE_WEBSITES,
55
        $scopeCode = null
56
    ): bool;
57
58
    /**
59
     * Disable captcha by area
60
     *
61
     * @param null|string $website
62
     */
63
    public function disableCaptcha(string $website = null): void
64
    {
65
        if (!$this->hasEnabled(ScopeInterface::SCOPE_WEBSITES, $website)) {
66
            return;
67
        }
68
69
        $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
70
        $scopeId = 0;
71
72
        if ($website !== null) {
73
            $scope = ScopeInterface::SCOPE_WEBSITES;
74
            $scopeId = $website;
75
        }
76
77
        $this->config->saveConfig(
78
            $this->disableConfigPath(),
79
            0,
80
            $scope,
81
            $scopeId
0 ignored issues
show
It seems like $scopeId can also be of type string; however, parameter $scopeId of Magento\Framework\App\Co...Interface::saveConfig() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
            /** @scrutinizer ignore-type */ $scopeId
Loading history...
82
        );
83
    }
84
}
85