YetiForceCompany/YetiForceCRM

View on GitHub
app/Integrations/Magento/Synchronizer/Maps/Invoice.php

Summary

Maintainability
C
7 hrs
Test Coverage
F
0%

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

    public function getDataCrm(bool $onEdit = false): array
    {
        $parsedData = parent::getDataCrm($onEdit);
        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
            $parsedData = \array_replace_recursive($parsedData, $shippingAddress);
Severity: Minor
Found in app/Integrations/Magento/Synchronizer/Maps/Invoice.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

The method getDataCrm has a boolean flag argument $onEdit, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getDataCrm(bool $onEdit = false): array

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

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

        } else {
            $data = $this->data['billing_address'] ?? [];
        }

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

    public function getDataCrm(bool $onEdit = false): array
    {
        $parsedData = parent::getDataCrm($onEdit);
        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
            $parsedData = \array_replace_recursive($parsedData, $shippingAddress);

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 '89', column '14').
Open

    public function getDataCrm(bool $onEdit = false): array
    {
        $parsedData = parent::getDataCrm($onEdit);
        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
            $parsedData = \array_replace_recursive($parsedData, $shippingAddress);

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

Define a constant instead of duplicating this literal "shipping" 3 times.
Open

        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    public function getDataCrm(bool $onEdit = false): array
    {
        $parsedData = parent::getDataCrm($onEdit);
        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
            $parsedData = \array_replace_recursive($parsedData, $shippingAddress);
Severity: Major
Found in app/Integrations/Magento/Synchronizer/Maps/Invoice.php and 1 other location - About 7 hrs to fix
app/Integrations/Magento/Synchronizer/Maps/Order.php on lines 184..206

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 224.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

The property $finvoice_status is not named in camelCase.
Open

class Invoice extends Inventory
{
    /** {@inheritdoc} */
    protected $moduleName = 'FInvoice';
    /** {@inheritdoc} */

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $payment_methods is not named in camelCase.
Open

class Invoice extends Inventory
{
    /** {@inheritdoc} */
    protected $moduleName = 'FInvoice';
    /** {@inheritdoc} */

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

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

    public static $additionalFieldsCrm = [

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

        'sum_discount' => '',

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

        'price' => 'price',

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

     *

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

        'cashondelivery' => 'PLL_CASH_ON_DELIVERY',

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

            $parsedData = $this->parsePhone('phone_b', $parsedData);

Line exceeds 120 characters; contains 182 characters
Open

 * The file is part of the paid functionality. Using the file is allowed only after purchasing a subscription. File modification allowed only with the consent of the system producer.

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

        'sum_gross' => '',

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

    ];

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

        'subject' => 'increment_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

     */

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

        'discount' => 'discount_invoiced',

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

    /**

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

     * Payment method value map.

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

        if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {

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

            $parsedData = $this->parsePhone('phone_a', $parsedData);

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

        'finvoice_type' => 'PLL_DOMESTIC_INVOICE',

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

     */

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

            $parsedData = $this->parsePhone('phone', $parsedData);

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 static $mappedFields = [

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

        'payment_methods' => 'payment|method',

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 static $payment_methods = [

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

            $data = $this->data['billing_address'] ?? [];

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

        'issue_time' => 'date',

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

    ];

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

        'paypal_express' => 'PLL_PAYPAL_EXPRESS',

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

        $parsedData = parent::getDataCrm($onEdit);

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

        if ('shipping' === $addressType) {

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

        'sum_total' => '',

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

        '1' => 'PLL_AWAITING_REALIZATION',

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

        if (!empty($parsedData['phone_b'])) {

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

        'sum_net' => '',

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

        'qty' => 'qty_invoiced',

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

    public static $finvoice_status = [

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

        '2' => 'PLL_ACCEPTED',

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

        if (!empty($parsedData['phone'])) {

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

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

        'name' => 'product_id',

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

    public static $fieldsType = [

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

    ];

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

        'banktransfer' => 'PLL_TRANSFER',

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

        if (!empty($parsedData['phone_a'])) {

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

        'sum_tax' => '',

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

        'addresslevel1a' => 'country',

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 getDataCrm(bool $onEdit = false): array

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

        'finvoice_status' => 'state',

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

            $parsedData = \array_replace_recursive($parsedData, $shippingAddress);

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 = $this->data['extension_attributes']['shipping_assignments'][0]['shipping']['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

        'finvoice_status' => 'map',

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

        'saledate' => 'date',

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

        if (!empty($billingAddress = $this->getAddressDataCrm('billing'))) {

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

            $parsedData = $this->parsePhone('mobile', $parsedData);

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

    }

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

        'issue_time' => 'created_at',

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

    public static $mappedFieldsInv = [

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

        'addresslevel1b' => 'country',

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

     * Invoice status map.

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

        '3' => 'PLL_CANCELLED',

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

        'payment_methods' => 'mapAndAddNew',

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 getAddressDataByType(string $addressType)

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

     * @var array

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

     * @var array

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

        'redsys' => 'PLL_REDSYS',

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

    {

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

            $parsedData = \array_replace_recursive($parsedData, $billingAddress);

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 $this->dataCrm = $parsedData;

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

        } else {

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

    protected $moduleName = 'FInvoice';

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

        'saledate' => 'created_at',

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

        if (!empty($parsedData['mobile'])) {

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

        }

There are no issues that match your filters.

Category
Status