YetiForceCompany/YetiForceCRM

View on GitHub
app/RecordCollectors/UkVatPayerStatusVerification.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method search has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function search(): array
    {
        if (!$this->isActive()) {
            return [];
        }
Severity: Minor
Found in app/RecordCollectors/UkVatPayerStatusVerification.php - About 1 hr to fix

    The method search uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $response['fields'] = [
                    '' => \App\Language::translate('LBL_UK_VAT_PAYER_NOT_CONFIRM', 'Other.RecordCollector')
                ];
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Avoid using static access to class '\App\Language' in method 'search'.
    Open

                    '' => \App\Language::translate('LBL_UK_VAT_PAYER_NOT_CONFIRM', 'Other.RecordCollector')

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Json' in method 'search'.
    Open

                $response = \App\Json::decode(\App\RequestHttp::getClient()->get($this->url . 'organisations/vat/check-vat-number/lookup/' . $vatNumber)
                    ->getBody()
                    ->getContents());

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Log' in method 'search'.
    Open

                \App\Log::warning($e->getMessage(), 'RecordCollectors');

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Language' in method 'search'.
    Open

                    '' => \App\Language::translate('LBL_UK_VAT_PAYER_CONFIRM', 'Other.RecordCollector'),

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
    Open

        protected string $addOnName = 'YetiForceRcUkVatPayerStatus';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'Vendors' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vatNumber' => 'vat_id',

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } catch (\GuzzleHttp\Exception\GuzzleException $e) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $modulesFieldsMap = [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    ->getBody()

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vatNumber' => 'vat_id',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vatNumber' => 'vat_id',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'Competition' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

        ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $allowedModules = ['Accounts', 'Leads', 'Vendors', 'Competition', 'Partners'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $description = 'LBL_UK_VAT_PAYER_DESC';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $docUrl = 'https://developer.service.hmrc.gov.uk/api-documentation';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected string $addOnName = 'YetiForceRcUkVatPayerStatus';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'Leads' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function search(): array

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $fields = [

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'vatNumber' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** @var string API sever address */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $response = [];

    Line exceeds 120 characters; contains 148 characters
    Open

                $response = \App\Json::decode(\App\RequestHttp::getClient()->get($this->url . 'organisations/vat/check-vat-number/lookup/' . $vatNumber)

    Spaces must be used to indent lines; tabs are not allowed
    Open

                \App\Log::warning($e->getMessage(), 'RecordCollectors');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'labelModule' => '_Base',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'Partners' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->response['error'] = $e->getMessage();

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $displayType = 'Summary';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!$this->isActive()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $label = 'LBL_UK_VAT_PAYER';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'label' => 'Vat ID',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            'Accounts' => [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $response = \App\Json::decode(\App\RequestHttp::getClient()->get($this->url . 'organisations/vat/check-vat-number/lookup/' . $vatNumber)

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'typeofdata' => 'V~M',

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    ->getContents());

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $vatNumber = str_replace([' ', ',', '.', '-'], '', $this->request->getByType('vatNumber', 'Text'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!$vatNumber) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            try {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ],

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $response['fields'] = [

    Line exceeds 120 characters; contains 195 characters
    Open

                    'Address' => $response['target']['address']['line1'] . $response['target']['address']['line2'] . $response['target']['address']['line3'] . $response['target']['address']['line4'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $url = 'https://api.service.hmrc.gov.uk/';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vatNumber' => 'vat_id',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    '' => \App\Language::translate('LBL_UK_VAT_PAYER_CONFIRM', 'Other.RecordCollector'),

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public $icon = 'yfi-vat-uk';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vatNumber' => 'vat_id',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Country' => $response['target']['address']['countryCode']

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $response;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $response['fields'] = [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    '' => \App\Language::translate('LBL_UK_VAT_PAYER_NOT_CONFIRM', 'Other.RecordCollector')

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (isset($response['target'])) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Address' => $response['target']['address']['line1'] . $response['target']['address']['line2'] . $response['target']['address']['line3'] . $response['target']['address']['line4'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Name' => $response['target']['name'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Vat ID' => $response['target']['vatNumber'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Postcode' => $response['target']['address']['postcode'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    There are no issues that match your filters.

    Category
    Status