Passed
Push[email protected] ( 0362d7...c8bbec )
by Bruno
03:06
created

aroundGetAttributeValidationClass()   C

Complexity

Conditions 12
Paths 10

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 20
c 1
b 0
f 0
nc 10
nop 3
dl 0
loc 29
rs 6.9666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright © O2TI. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace O2TI\TaxDocumentValidationBr\Plugin;
10
11
use Magento\Customer\Helper\Address;
12
use O2TI\TaxDocumentValidationBr\Helper\Config;
13
14
/**
15
 * Class CustomerTaxDocumentValidationBrAddRule - Add classes for validation atribute.
16
 */
17
class CustomerTaxDocumentValidationBrAddRule
18
{
19
    /**
20
     * @var Config
21
     */
22
    private $config;
23
24
    /**
25
     * TaxDocumentValidationBrAddRule constructor.
26
     *
27
     * @param Config $config
28
     */
29
    public function __construct(
30
        Config $config
31
    ) {
32
        $this->config = $config;
33
    }
34
35
    /**
36
     * Add Class to VatId.
37
     *
38
     * @param Address   $subject
39
     * @param callable  $proceed
40
     * @param string    $args
41
     *
42
     * @return string
43
     */
44
    public function aroundGetAttributeValidationClass(Address $subject, callable $proceed, string $args): string
0 ignored issues
show
Unused Code introduced by
The parameter $subject is not used and could be removed. ( Ignorable by Annotation )

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

44
    public function aroundGetAttributeValidationClass(/** @scrutinizer ignore-unused */ Address $subject, callable $proceed, string $args): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        $result = $proceed($args);
47
        if ($args == 'vat_id') {
48
            if ($this->config->isEnabled()) {
49
                $add = 'required-entry ';
50
                if ($this->config->getConfigByVatId('enabled_cpf') && $this->config->getConfigByVatId('enabled_cnpj')) {
51
                    $add .= Config::VAT_CPF_OR_CNPJ;
52
                } elseif ($this->config->getConfigByVatId('enabled_cpf')) {
53
                    $add .= Config::VAT_ONLY_CPF;
54
                } elseif ($this->config->getConfigByVatId('enabled_cnpj')) {
55
                    $add .= Config::VAT_ONLY_CNPJ;
56
                }
57
58
                $result .= $add;
59
            }
60
        } elseif ($args == 'taxvat') {
61
            if ($this->config->getConfigByTaxvat('enabled_cpf') && $this->config->getConfigByTaxvat('enabled_cnpj')) {
62
                $add = Config::VAT_CPF_OR_CNPJ;
63
            } elseif ($this->config->getConfigByTaxvat('enabled_cpf')) {
64
                $add = Config::VAT_ONLY_CPF;
65
            } elseif ($this->config->getConfigByTaxvat('enabled_cnpj')) {
66
                $add = Config::VAT_ONLY_CNPJ;
67
            }
68
69
            $result .= $add;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $add does not seem to be defined for all execution paths leading up to this point.
Loading history...
70
        }
71
72
        return $result;
73
    }
74
}
75