YetiForceCompany/YetiForceCRM

View on GitHub
app/RecordCollectors/PlKrs.php

Summary

Maintainability
A
25 mins
Test Coverage
B
82%

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

    private function parseData(): void
    {
        if (empty($this->data)) {
            return;
        }
Severity: Minor
Found in app/RecordCollectors/PlKrs.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 '151', column '25').
Open

            $responseData = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))
Severity: Minor
Found in app/RecordCollectors/PlKrs.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\Log' in method 'getDataFromApi'.
Open

            \App\Log::warning($e->getMessage(), 'RecordCollectors');
Severity: Minor
Found in app/RecordCollectors/PlKrs.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\Json' in method 'getDataFromApi'.
Open

}
Severity: Minor
Found in app/RecordCollectors/PlKrs.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\Utils' in method 'parseData'.
Open

        $this->data = \App\Utils::flattenKeys($this->data, 'ucfirst');
Severity: Minor
Found in app/RecordCollectors/PlKrs.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 'getDataFromApi'.
Open

            $responseData = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))
Severity: Minor
Found in app/RecordCollectors/PlKrs.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

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

    protected string $addOnName = 'YetiForceRcPlKrs';
Severity: Critical
Found in app/RecordCollectors/PlKrs.php by phan

Avoid excessively long variable names like $formFieldsToRecordMap. Keep variable name length under 20.
Open

    public $formFieldsToRecordMap = [
        'Accounts' => [
            'daneDzial1DanePodmiotuNazwa' => 'accountname',
            'daneDzial1DanePodmiotuIdentyfikatoryRegon' => 'registration_number_2',
            'naglowekANumerKRS' => 'registration_number_1',
Severity: Minor
Found in app/RecordCollectors/PlKrs.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

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

            'daneDzial1DanePodmiotuNazwa' => 'accountname',

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

            'daneDzial1SiedzibaIAdresAdresKodPocztowy' => 'addresslevel7a',

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

    /** {@inheritdoc} */

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

    public $docUrl = 'https://prs.ms.gov.pl/krs/openApi';

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

    public $formFieldsToRecordMap = [

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

            'daneDzial1SiedzibaIAdresSiedzibaWojewodztwo' => 'addresslevel2a',

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

            'daneDzial1SiedzibaIAdresAdresStronyInternetowej' => 'website',

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

            'daneDzial1SiedzibaIAdresAdresKodPocztowy' => 'addresslevel7a',

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

        ]

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

            'dane_dzial1_siedzibaIAdres_siedziba_miejscowosc' => 'addresslevel5a',

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

            'daneDzial1SiedzibaIAdresSiedzibaPowiat' => 'addresslevel3a',

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

            'daneDzial1SiedzibaIAdresAdresKraj' => 'addresslevel1a',

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

        'ncr' => [

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 $icon = 'yfi-krs-pl';

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

            'daneDzial3PrzedmiotDzialalnosciPrzedmiotPrzewazajacejDzialalnosci0' => 'siccode',

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

            'daneDzial3PrzedmiotDzialalnosciPrzedmiotPozostalejDzialalnosci0' => 'siccode',

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

            'daneDzial1SiedzibaIAdresAdresNrDomu' => 'buildingnumbera',

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

            'daneDzial1SiedzibaIAdresAdresKodPocztowy' => 'addresslevel7a',

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

            'daneDzial1SiedzibaIAdresSiedzibaKraj' => 'addresslevel1a',

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

            'daneDzial1SiedzibaIAdresSiedzibaKraj' => 'addresslevel1a',

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

            'naglowekANumerKRS' => 'registration_number_1',

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

            'daneDzial1SiedzibaIAdresAdresUlica' => 'addresslevel8a',

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

            'dane_dzial1_siedzibaIAdres_siedziba_miejscowosc' => 'addresslevel5a',

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

            'daneDzial1SiedzibaIAdresAdresUlica' => 'addresslevel8a',

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

            'daneDzial1SiedzibaIAdresAdresKraj' => 'addresslevel1a',

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

            'daneDzial1DanePodmiotuIdentyfikatoryRegon' => 'registration_number_2',

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

        ]

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

            'label' => 'Registration number 1',

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

    /** {@inheritdoc} */

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

    public $displayType = 'FillFields';

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

            'naglowekANumerKRS' => 'registration_number_1',

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

        ],

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

            'dane_dzial1_siedzibaIAdres_adres_miejscowosc' => 'addresslevel5a',

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

    /** @var string KRS sever address */

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

            'daneDzial1SiedzibaIAdresAdresUlica' => 'addresslevel8a',

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

            'daneDzial1DanePodmiotuIdentyfikatoryRegon' => 'registration_number_2',

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

        $this->parseData();

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

        $this->loadData();

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

        }

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

            'dane_dzial1_siedzibaIAdres_adres_miejscowosc' => 'addresslevel5a',

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

            'typeofdata' => 'V~M',

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

            'ncr' => 'registration_number_1',

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

    /**

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

     *

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

        if (empty($this->data)) {

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

    private function convertPkd(array &$pkd): void

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

            'Annual revenue' => 'annual_revenue',

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

            'Annual revenue' => 'annualrevenue',

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

            'daneDzial1SiedzibaIAdresSiedzibaWojewodztwo' => 'addresslevel2a',

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

        }

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

     * @param mixed $ncr

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

     * Function parsing data to fields from Polish National Court Register API.

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->convertPkd($value);

Line exceeds 120 characters; contains 125 characters
Open

            $this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPozostalejDzialalnosciAll'] = rtrim($all, ', ');

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

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

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

            'daneDzial1SiedzibaIAdresSiedzibaPowiat' => 'addresslevel3a',

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

            'daneDzial1DanePodmiotuIdentyfikatoryNip' => 'vat_id',

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

            'daneDzial1SiedzibaIAdresSiedzibaGmina' => 'addresslevel4a',

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

            'ncr' => 'registration_number_1',

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

     * @return void

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

            $this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPozostalejDzialalnosciAll'] = rtrim($all, ', ');

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

            'daneDzial1SiedzibaIAdresAdresStronyInternetowej' => 'website',

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

            'daneDzial1SiedzibaIAdresAdresKraj' => 'addresslevel1a',

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

        ],

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

            'daneDzial1DanePodmiotuIdentyfikatoryRegon' => 'registration_number_2',

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

    protected string $addOnName = 'YetiForceRcPlKrs';

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

    protected $url = 'https://api-krs.ms.gov.pl/api/krs/OdpisAktualny/';

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

     *

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

            }

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

            'daneDzial1DanePodmiotuIdentyfikatoryNip' => 'vat_id',

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

            'daneDzial1SiedzibaIAdresSiedzibaWojewodztwo' => 'addresslevel2a',

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

            'daneDzial1SiedzibaIAdresSiedzibaKraj' => 'addresslevel1a',

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

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

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

        if (isset($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPozostalejDzialalnosci'])) {

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

    }

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

        $this->moduleName = $this->request->getModule();

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

        $this->getDataFromApi($ncr);

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

            $responseData = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))

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

            foreach ($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPozostalejDzialalnosci'] as &$value) {

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

        if (isset($this->data['dane']['dzial1']['kapital'])) {

Line exceeds 120 characters; contains 135 characters
Open

            $this->data['Annual revenue'] = (float) $this->data['dane']['dzial1']['kapital']['wysokoscKapitaluZakladowego']['wartosc'];

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

    public $description = 'LBL_PL_KRS_DESC';

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

            'dane_dzial1_siedzibaIAdres_adres_miejscowosc' => 'addresslevel5a',

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

            'daneDzial1DanePodmiotuNazwa' => 'company',

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

            'daneDzial1DanePodmiotuIdentyfikatoryNip' => 'vat_id',

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

            'daneDzial1DanePodmiotuNazwa' => 'vendorname',

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

            'naglowekANumerKRS' => 'registration_number_1',

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

     * Function fetching from Polish National Court Register API.

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\Log::warning($e->getMessage(), 'RecordCollectors');

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

                $all .= "$value, ";

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

    public $label = 'LBL_PL_KRS';

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

            'daneDzial1SiedzibaIAdresSiedzibaGmina' => 'addresslevel4a',

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

            'daneDzial1SiedzibaIAdresSiedzibaPowiat' => 'addresslevel3a',

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

            'ncr' => 'registration_number_1',

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

        if (!$ncr) {

Line exceeds 120 characters; contains 127 characters
Open

            $this->convertPkd($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPrzewazajacejDzialalnosci'][0]);

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

     * Convert PKD value.

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

        $pkd = $pkd['kodDzial'] . '.' . $pkd['kodKlasa'] . '.' . $pkd['kodPodklasa'];

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

    private function getDataFromApi($ncr): void

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

            $this->data = \App\Json::decode($responseData->getBody()->getContents())['odpis'] ?? [];

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

        }

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

            unset($this->data['dane']['dzial1']['kapital']['wysokoscKapitaluZakladowego']['wartosc']);

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

            'daneDzial1SiedzibaIAdresSiedzibaGmina' => 'addresslevel4a',

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

            'daneDzial1SiedzibaIAdresAdresStronyInternetowej' => 'website',

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

            'dane_dzial1_siedzibaIAdres_siedziba_miejscowosc' => 'addresslevel5a',

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

            $this->data['Annual revenue'] = (float) $this->data['dane']['dzial1']['kapital']['wysokoscKapitaluZakladowego']['wartosc'];

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

        $this->data = \App\Utils::flattenKeys($this->data, 'ucfirst');

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

     * @param array $pkd

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

     * @return void

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

        }

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 function search(): array

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

        }

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

    private function parseData(): void

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

            $all = '';

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

        } catch (\GuzzleHttp\Exception\GuzzleException $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

        if (isset($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPrzewazajacejDzialalnosci'][0])) {

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

            $this->convertPkd($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPrzewazajacejDzialalnosci'][0]);

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

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

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

        return $this->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

        }

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

                ->request('GET', "{$this->url}{$ncr}?rejestr=P&format=json");

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

     * @return void

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

    {

Line exceeds 120 characters; contains 124 characters
Open

            foreach ($this->data['dane']['dzial3']['przedmiotDzialalnosci']['przedmiotPozostalejDzialalnosci'] as &$value) {

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

    /**

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

     *

There are no issues that match your filters.

Category
Status