YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebservicePremium/Record.php

Summary

Maintainability
A
2 hrs
Test Coverage
C
73%

Missing class import via use statement (line '29', column '21').
Open

        $returnVal = (new \App\Db\Query())

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 '\Vtiger_Inventory_Model' in method 'getTaxParam'.
Open

        $globalTaxes = \Vtiger_Inventory_Model::getGlobalTaxes();

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 '\Vtiger_Inventory_Model' in method 'getTaxParam'.
Open

        $taxConfig = \Vtiger_Inventory_Model::getTaxesConfig();

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\Fields\Double' in method 'getTaxParam'.
Open

            $taxParam['regionalTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['value']);

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\Fields\Double' in method 'getTaxParam'.
Open

            $taxParam['groupTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['value']);

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

Call to undeclared method \App\Db\Query::select
Open

        $returnVal = (new \App\Db\Query())

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

        if (\in_array('LBL_REGIONAL_TAX', $availableTaxes) && !empty($regionalTaxes) && \in_array(3, $taxConfig['taxs'])) {
            $taxParam['aggregationType'][] = 'regional';
            $taxId = explode(',', $regionalTaxes)[0];
            $taxParam['regionalTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['value']);
        }
Severity: Major
Found in api/webservice/WebservicePremium/Record.php and 1 other location - About 1 hr to fix
api/webservice/WebservicePremium/Record.php on lines 59..63

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 101.

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

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

        if (\in_array('LBL_GROUP_TAX', $availableTaxes) && !empty($groupTaxes) && \in_array(1, $taxConfig['taxs'])) {
            $taxParam['aggregationType'][] = 'group';
            $taxId = explode(',', $groupTaxes)[0];
            $taxParam['groupTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['value']);
        }
Severity: Major
Found in api/webservice/WebservicePremium/Record.php and 1 other location - About 1 hr to fix
api/webservice/WebservicePremium/Record.php on lines 54..58

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 101.

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

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

            ->where(['vtiger_account.accountid' => $accountId])

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

     * @param string $groupTaxes

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

     *

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

        $taxConfig = \Vtiger_Inventory_Model::getTaxesConfig();

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

     * Returns taxparam.

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

     *

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

        $returnVal = (new \App\Db\Query())

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

        $availableTaxes = explode(' |##| ', $availableTaxes);

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

            ->leftJoin('vtiger_pricebookproductrel', 'vtiger_pricebookproductrel.pricebookid = vtiger_account.pricebook_id')

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

            ->andWhere(['vtiger_pricebookproductrel.productid' => $productId])

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

        $globalTaxes = \Vtiger_Inventory_Model::getGlobalTaxes();

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 float|null

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

     * @param string $availableTaxes

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

     * @param string $regionalTaxes

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

     * Get the price from the pricebook.

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

    {

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

            ->scalar();

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

            ->from('vtiger_account')

Line exceeds 120 characters; contains 124 characters
Open

            ->leftJoin('vtiger_pricebookproductrel', 'vtiger_pricebookproductrel.pricebookid = vtiger_account.pricebook_id')

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

        return false === $returnVal ? null : (float) $returnVal;

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 static function getTaxParam(string $availableTaxes, string $groupTaxes, string $regionalTaxes): 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

        $taxParam = [];

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

        if (\in_array('LBL_REGIONAL_TAX', $availableTaxes) && !empty($regionalTaxes) && \in_array(3, $taxConfig['taxs'])) {

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 (\in_array('LBL_GROUP_TAX', $availableTaxes) && !empty($groupTaxes) && \in_array(1, $taxConfig['taxs'])) {

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

            $taxParam['aggregationType'][] = 'group';

Line exceeds 120 characters; contains 123 characters
Open

        if (\in_array('LBL_REGIONAL_TAX', $availableTaxes) && !empty($regionalTaxes) && \in_array(3, $taxConfig['taxs'])) {

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

            $taxParam['regionalTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['value']);

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

     * @param int $accountId

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

     * @param int $productId

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

    public static function getPriceFromPricebook(int $accountId, int $productId): ?float

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

            ->select(['vtiger_pricebookproductrel.listprice'])

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

            $taxId = explode(',', $groupTaxes)[0];

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

            $taxParam['aggregationType'][] = 'regional';

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

            $taxId = explode(',', $regionalTaxes)[0];

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

        }

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

            $taxParam['groupTax'] = \App\Fields\Double::formatToDb($globalTaxes[$taxId]['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

        return $taxParam;

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

        }

There are no issues that match your filters.

Category
Status