YetiForceCompany/YetiForceCRM

View on GitHub
app/RecordCollectors/FrEnterpriseGouv.php

Summary

Maintainability
A
35 mins
Test Coverage
C
71%

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

    public function search(): array
    {
        if (!$this->isActive()) {
            return [];
        }
Severity: Minor
Found in app/RecordCollectors/FrEnterpriseGouv.php - About 35 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

Avoid using static access to class '\App\Log' in method 'getDataFromApi'.
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\Json' in method 'getDataFromApi'.
Open

        $data = isset($response) ? \App\Json::decode($response->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\Utils' in method 'parseData'.
Open

        return \App\Utils::flattenKeys($data, 'ucfirst');

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 = 'YetiForceRcFrEnterpriseGouv';
Severity: Critical
Found in app/RecordCollectors/FrEnterpriseGouv.php by phan

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

    public $formFieldsToRecordMap = [
        'Accounts' => [
            'nom_complet' => 'accountname',
            'siren' => 'vat_id',
            'siegeActivite_principale' => 'siccode',

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

    const LIMIT = 4;

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 $icon = 'yfi-entreprise-gouv-fr';

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

    /** @var int Number of items returned */

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

            'siegeSiret' => 'registration_number_1',

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

            'siegeAdresse_complete_secondaire' => 'buildingnumbera',

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

            'nom_complet' => 'subject',

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

            'siegeAdresse_complete' => 'addresslevel8a',

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

            'companyName' => 'accountname',

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

            'companyName' => 'subject',

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

        }

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

        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

        foreach ($data['results'] as $key => $result) {

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

    public $description = 'LBL_FR_ENTERPRISE_GOUV_DESC';

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

            'siegeAdresse_complete_secondaire' => 'buildingnumbera',

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

        'sicCode' => [

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

        '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

     * @return array

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

            $query['q'] = $vatNumber;

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

            $query['q'] = $companyName;

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

            $query['activite_principale'] = $sicCode;

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

     * @param array $data

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

            'labelModule' => '_Base',

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

     * Function fetching company data by params.

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

            'siren' => '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

            'siren' => 'vat_id',

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' => 'vat_id'

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

    /** @var string Server address */

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

        if (!empty($vatNumber)) {

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

     * Function parsing data to fields from API.

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

            'siegeAdresse_complete_secondaire' => 'buildingnumbera',

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

            'siren' => 'vat_id',

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

            'siegeLibelle_commune' => 'addresslevel4a'

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

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

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

     * @param array $query

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

        if (empty($data)) {

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

            'siegeActivite_principale' => 'siccode',

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

            'siegeLibelle_commune' => 'addresslevel4a'

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

    protected string $addOnName = 'YetiForceRcFrEnterpriseGouv';

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

        ],

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

            'companyName' => 'vendorname',

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

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

        if (!empty($sicCode)) {

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

        $this->getDataFromApi($query);

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

    private function getDataFromApi(array $query): void

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

            'nom_complet' => 'accountname',

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

            'siren' => 'vat_id',

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

            'siegeLibelle_commune' => 'addresslevel4a'

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

            'siegeAdresse_complete_secondaire' => 'buildingnumbera',

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' => 'VAT',

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

            'companyName' => 'subject',

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

    public $allowedModules = ['Accounts', 'Leads', 'Vendors', 'Partners', '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

            'siegeAdresse_complete' => 'addresslevel8a',

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

        'companyName' => [

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 void

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

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

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

            'siren' => 'vat_id',

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

            'sicCode' => 'siccode',

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

        $query = [];

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

        }

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

            'siegeSiret' => 'registration_number_1',

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

            'siegeAdresse_complete' => 'addresslevel8a',

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

            'siegeSiret' => '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

    /** {@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

        ],

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

        $companyName = $this->request->getByType('companyName', 'Text');

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

            'nom_complet' => 'vendorname',

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

            'siegeAdresse_complete' => 'addresslevel8a',

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

        'Accounts' => [

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

        if (empty($vatNumber) && empty($sicCode) && empty($companyName)) {

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->data[$key] = $this->parseData($result);

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

    public $docUrl = 'https://api.gouv.fr/les-api/api-entreprise/';

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

        ],

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

        $query['per_page'] = self::LIMIT;

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

            'siegeAdresse_complete' => 'addresslevel8a',

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

            'nom_complet' => 'subject',

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

            'siegeLibelle_commune' => 'addresslevel4a'

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

            'label' => 'SIC code',

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

            'companyName' => 'company',

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

    private $url = 'https://recherche-entreprises.api.gouv.fr/';

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

        } elseif (!empty($companyName) && empty($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

    {

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

            'siegeAdresse_complete_secondaire' => 'buildingnumbera',

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

            'siegeLibelle_commune' => 'addresslevel4a'

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

        ],

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

            'vatNumber' => 'vat_id'

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

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

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 $label = 'LBL_FR_ENTERPRISE_GOUV';

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

            'activite_principale' => 'siccode',

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

            'nom_complet' => 'company',

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

            'label' => 'Account name',

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

            $response = \App\RequestHttp::getClient()->get($this->url . 'search?' . http_build_query($query));

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

        }

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

        $data = isset($response) ? \App\Json::decode($response->getBody()->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

    }

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

        return \App\Utils::flattenKeys($data, 'ucfirst');

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(array $data): array

There are no issues that match your filters.

Category
Status