CurrencyValidator::validate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
namespace Getloy\GetloyMagentoGateway\Gateway\Validator;
4
5
use Magento\Payment\Gateway\ConfigInterface;
6
use Magento\Payment\Gateway\Validator\AbstractValidator;
7
use Magento\Payment\Gateway\Validator\ResultInterface;
8
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\...\ResultInterfaceFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class CurrencyValidator extends AbstractValidator
11
{
12
    /**
13
     * @var \Magento\Payment\Gateway\ConfigInterface
14
     */
15
    private $config;
16
17
    /**
18
     * @param ResultInterfaceFactory $resultFactory
19
     * @param ConfigInterface        $config
20
     */
21
    public function __construct(
22
        ResultInterfaceFactory $resultFactory,
23
        ConfigInterface $config
24
    ) {
25
        $this->config = $config;
26
        parent::__construct($resultFactory);
27
    }
28
29
    /**
30
     * Performs domain-related validation for business object
31
     *
32
     * @param  array $validationSubject
33
     * @return ResultInterface
34
     */
35
    public function validate(array $validationSubject)
36
    {
37
        $isValid = true;
38
        $storeId = $validationSubject[ 'storeId' ];
39
        $currency = $validationSubject[ 'currency' ];
40
41
        if ($currency !== $this->config->getValue('currency', $storeId)) {
42
            $isValid = false;
43
        }
44
        if (!\in_array($currency, [ 'USD' ])) {
45
            $isValid = false;
46
        }
47
48
        return $this->createResult($isValid);
49
    }
50
}
51