Completed
Push — master ( 00856b...729400 )
by Gilles
36s queued 16s
created

TaxRuleQuery::getTaxCalculatorCollection()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 38
rs 8.6346
c 0
b 0
f 0
cc 7
nc 7
nop 3
1
<?php
2
3
namespace Thelia\Model;
4
5
use Propel\Runtime\ActiveQuery\Criteria;
6
use Thelia\Model\Base\TaxRuleQuery as BaseTaxRuleQuery;
0 ignored issues
show
Bug introduced by
The type Thelia\Model\Base\TaxRuleQuery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Thelia\Model\Map\TaxRuleCountryTableMap;
0 ignored issues
show
Bug introduced by
The type Thelia\Model\Map\TaxRuleCountryTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Skeleton subclass for performing query and update operations on the 'tax_rule' table.
11
 *
12
 *
13
 *
14
 * You should add additional methods to this class to meet the
15
 * application requirements.  This class will only be generated as
16
 * long as it does not already exist in the output directory.
17
 *
18
 */
19
class TaxRuleQuery extends BaseTaxRuleQuery
20
{
21
    const ALIAS_FOR_TAX_RULE_COUNTRY_POSITION = 'taxRuleCountryPosition';
22
23
    protected static $caches = [];
24
25
    /**
26
     * @param TaxRule $taxRule
27
     * @param Country $country
28
     *
29
     * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
30
     */
31
    public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country = null, State $state = null)
32
    {
33
        $key = sprintf(
34
            '%s-%s-%s',
35
            $taxRule->getId(),
36
            ($country !== null) ? $country->getId() : 0,
37
            ($state !== null) ? $state->getId() : 0
38
        );
39
40
        if (array_key_exists($key, self::$caches)) {
41
            return self::$caches[$key];
42
        }
43
44
        $taxRuleQuery = TaxRuleCountryQuery::create()
45
            ->filterByTaxRuleId($taxRule->getId());
46
47
        if (null !== $country) {
48
            $taxRuleQuery->filterByCountry($country, Criteria::EQUAL);
49
        }
50
51
        if (null !== $state) {
52
            $taxRuleCount = clone $taxRuleQuery;
53
54
            $taxRuleCount->filterByStateId($state->getId(), Criteria::EQUAL)
55
                ->count();
56
57
            if (0 === $taxRuleCount) {
0 ignored issues
show
introduced by
The condition 0 === $taxRuleCount is always false.
Loading history...
58
                $taxRuleQuery->filterByStateId(null, Criteria::EQUAL);
59
            }
60
        }
61
62
        $search = TaxQuery::create()
63
            ->filterByTaxRuleCountry($taxRuleQuery->find())
64
            ->withColumn(TaxRuleCountryTableMap::COL_POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)
65
            ->orderBy(self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION, Criteria::ASC);
66
        ;
67
68
        return self::$caches[$key] = $search->find();
69
    }
70
}
71
// TaxRuleQuery
72