YetiForceCompany/YetiForceCRM

View on GitHub
app/RecordCollectors/Vies.php

Summary

Maintainability
A
1 hr
Test Coverage
D
60%

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

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

    Function search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

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

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Missing class import via use statement (line '133', column '22').
    Open

                if ($client = new \SoapClient($this->url, \App\RequestHttp::getSoapOptions())) {
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class '\App\Fields\Country' in method 'getFields'.
    Open

                if (!$this->request->isEmpty($value, true) && ($code = \App\Fields\Country::getCountryCode($this->request->getByType($value, 'Text')))) {
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    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\RequestHttp' in method 'search'.
    Open

                if ($client = new \SoapClient($this->url, \App\RequestHttp::getSoapOptions())) {
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    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->faultstring, 'RecordCollectors');
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    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 assigning values to variables in if clauses and the like (line '133', column '8').
    Open

        public function search(): array
        {
            if (!$this->isActive()) {
                return [];
            }
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid assigning values to variables in if clauses and the like (line '112', column '51').
    Open

        public function getFields(): array
        {
            $fieldsModels = parent::getFields();
            foreach (['addresslevel1a', 'addresslevel1b', 'addresslevel1c'] as $value) {
                if (!$this->request->isEmpty($value, true) && ($code = \App\Fields\Country::getCountryCode($this->request->getByType($value, 'Text')))) {
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

        protected bool $paid = false;
    Severity: Critical
    Found in app/RecordCollectors/Vies.php by phan

    Avoid variables with short names like $r. Configured minimum length is 3.
    Open

                    $r = $client->checkVatApprox([
    Severity: Minor
    Found in app/RecordCollectors/Vies.php by phpmd

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

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

        public $label = 'LBL_VIES';

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

        public $docUrl = 'https://ec.europa.eu/taxation_customs/vies/technicalInformation.html';

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

                    'DK' => 'Denmark',

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

                    'LT' => 'Lithuania',

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

                    'SE' => 'Sweden',

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

            ],

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

                'typeofdata' => 'V~M',

    Line exceeds 120 characters; contains 149 characters
    Open

                if (!$this->request->isEmpty($value, true) && ($code = \App\Fields\Country::getCountryCode($this->request->getByType($value, 'Text')))) {

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

                    'CZ' => 'Czech Republic',

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

                    'RO' => 'Romania',

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

                    'SK' => 'Slovakia',

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

        ];

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

                    'CY' => 'Cyprus',

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

                    'DE' => 'Germany',

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

                    'GB' => 'United Kingdom',

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

                    'IE' => 'Ireland',

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

        {

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

                    break;

    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

        public $displayType = 'Summary';

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

                    'AT' => 'Austria',

    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

        protected $modulesFieldsMap = [

    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

        {

    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

                'picklistModule' => 'Other.Country',

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

                    'PT' => 'Portugal',

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

            ],

    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

            foreach (['addresslevel1a', 'addresslevel1b', 'addresslevel1c'] as $value) {

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

                if (!$this->request->isEmpty($value, true) && ($code = \App\Fields\Country::getCountryCode($this->request->getByType($value, 'Text')))) {

    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

        public $description = 'LBL_VIES_DESC';

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

                    'EE' => 'Estonia',

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

                    'LV' => 'Latvia',

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

                    'MT' => 'Malta',

    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

            }

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

                    'NL' => 'Netherlands',

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

        protected bool $paid = false;

    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

        public $icon = 'yfi yfi-vies';

    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

                    'BE' => 'Belgium',

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

                    'FR' => 'France',

    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

            'Accounts' => [

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

        public function getFields(): array

    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

        /** {@inheritdoc} */

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

        /** @var string Vies server address. */

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

                    'PL' => 'Poland',

    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

            'Vendors' => [

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

        protected $url = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';

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

                'label' => 'Country',

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

                    'ES' => 'Spain',

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

                    'LU' => 'Luxembourg',

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

            ],

    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

            return $fieldsModels;

    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

                    $fieldsModels['countryCode']->set('fieldvalue', $code);

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

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

    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

                    'BG' => 'Bulgaria',

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

                    'HU' => 'Hungary',

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

                    'IT' => 'Italy',

    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

                'vatNumber' => 'vat_id',

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

                    'HR' => 'Croatia',

    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

        /** {@inheritdoc} */

    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

            'countryCode' => [

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

                    'FI' => 'Finland',

    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

            ],

    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

                return [];

    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

                'uitype' => 16,

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

                'picklistValues' => [

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

                    'EL' => 'Greece',

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

                    'SI' => 'Slovenia',

    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

            'Leads' => [

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

            $fieldsModels = parent::getFields();

    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

                        'countryCode' => $countryCode,

    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

                            'Address details' => $r->traderAddress,

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

                if ($client = new \SoapClient($this->url, \App\RequestHttp::getSoapOptions())) {

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

                    if ($r->valid) {

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

            }

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

            $countryCode = $this->request->getByType('countryCode', 'Standard');

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

            $response = [];

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

                        'requesterCountryCode' => $countryCode,

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

                            'Country' => $r->countryCode,

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

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

    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

                            'LBL_REQUEST_DATE' => $r->requestDate,

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

            } catch (\SoapFault $e) {

    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

                return [];

    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

                            'LBL_REQUEST_ID' => $r->requestIdentifier

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

                        'vatNumber' => $vatNumber,

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

                        'requesterVatNumber' => $vatNumber

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

                            'Vat ID' => $r->countryCode . $r->vatNumber,

    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

                    ]);

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

                $response['error'] = $e->faultstring;

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

                    $r = $client->checkVatApprox([

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

                            'LBL_COMPANY_NAME' => $r->traderName,

    There are no issues that match your filters.

    Category
    Status