Conditions | 27 |
Paths | > 20000 |
Total Lines | 141 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
72 | public function getByRule($Product = null, $ProductClass = null, $Pref = null, $Country = null) |
||
73 | { |
||
74 | if (!$this->app) { |
||
75 | throw new \LogicException(); |
||
76 | } |
||
77 | |||
78 | // Pref Country 設定 |
||
79 | if (!$Pref && !$Country && $this->app['security']->getToken() && $this->app['security']->isGranted('ROLE_USER')) { |
||
80 | /* @var $Customer \Eccube\Entity\Customer */ |
||
81 | $Customer = $this->app['security']->getToken()->getUser(); |
||
82 | $Pref = $Customer->getPref(); |
||
83 | $Country = $Customer->getCountry(); |
||
84 | } |
||
85 | |||
86 | // 商品単位税率設定がOFFの場合 |
||
87 | /** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
||
88 | $BaseInfo = $this->app['eccube.repository.base_info']->get(); |
||
89 | if ($BaseInfo->getOptionProductTaxRule() !== Constant::ENABLED) { |
||
90 | $Product = null; |
||
91 | $ProductClass = null; |
||
92 | } |
||
93 | |||
94 | // Cache Key 設定 |
||
95 | if ($Product instanceof \Eccube\Entity\Product) { |
||
|
|||
96 | $productId = $Product->getId(); |
||
97 | } elseif ($Product) { |
||
98 | $productId = $Product; |
||
99 | } else { |
||
100 | $productId = '0'; |
||
101 | } |
||
102 | if ($ProductClass instanceof \Eccube\Entity\ProductClass) { |
||
103 | $productClassId = $ProductClass->getId(); |
||
104 | } elseif ($ProductClass) { |
||
105 | $productClassId = $ProductClass; |
||
106 | } else { |
||
107 | $productClassId = '0'; |
||
108 | } |
||
109 | if ($Pref instanceof \Eccube\Entity\Master\Pref) { |
||
110 | $prefId = $Pref->getId(); |
||
111 | } elseif ($Pref) { |
||
112 | $prefId = $Pref; |
||
113 | } else { |
||
114 | $prefId = '0'; |
||
115 | } |
||
116 | if ($Country instanceof \Eccube\Entity\Master\Country) { |
||
117 | $countryId = $Country->getId(); |
||
118 | } elseif ($Country) { |
||
119 | $countryId = $Country; |
||
120 | } else { |
||
121 | $countryId = '0'; |
||
122 | } |
||
123 | $cacheKey = $productId.':'.$productClassId.':'.$prefId.':'.$countryId; |
||
124 | |||
125 | // すでに取得している場合はキャッシュから |
||
126 | if (isset($this->rules[$cacheKey])) { |
||
127 | return $this->rules[$cacheKey]; |
||
128 | } |
||
129 | |||
130 | $parameters = array(); |
||
131 | $qb = $this->createQueryBuilder('t') |
||
132 | ->where('t.apply_date < :apply_date'); |
||
133 | $parameters[':apply_date'] = new \DateTime(); |
||
134 | |||
135 | // Pref |
||
136 | if ($Pref) { |
||
137 | $qb->andWhere('t.Pref IS NULL OR t.Pref = :Pref'); |
||
138 | $parameters['Pref'] = $Pref; |
||
139 | } else { |
||
140 | $qb->andWhere('t.Pref IS NULL'); |
||
141 | } |
||
142 | |||
143 | // Country |
||
144 | if ($Country) { |
||
145 | $qb->andWhere('t.Country IS NULL OR t.Country = :Country'); |
||
146 | $parameters['Country'] = $Country; |
||
147 | } else { |
||
148 | $qb->andWhere('t.Country IS NULL'); |
||
149 | } |
||
150 | |||
151 | /* |
||
152 | * Product, ProductClass が persist される前に TaxRuleEventSubscriber によってアクセスされる |
||
153 | * 場合があるため、ID の存在もチェックする. |
||
154 | * https://github.com/EC-CUBE/ec-cube/issues/677 |
||
155 | */ |
||
156 | |||
157 | // Product |
||
158 | if ($Product && $productId > 0) { |
||
159 | $qb->andWhere('t.Product IS NULL OR t.Product = :Product'); |
||
160 | $parameters['Product'] = $Product; |
||
161 | } else { |
||
162 | $qb->andWhere('t.Product IS NULL'); |
||
163 | } |
||
164 | |||
165 | // ProductClass |
||
166 | if ($ProductClass && $productClassId > 0) { |
||
167 | $qb->andWhere('t.ProductClass IS NULL OR t.ProductClass = :ProductClass'); |
||
168 | $parameters['ProductClass'] = $ProductClass; |
||
169 | } else { |
||
170 | $qb->andWhere('t.ProductClass IS NULL'); |
||
171 | } |
||
172 | |||
173 | $TaxRules = $qb |
||
174 | ->setParameters($parameters) |
||
175 | ->orderBy('t.apply_date', 'DESC') // 実際は usort() でソートする |
||
176 | ->getQuery() |
||
177 | ->getResult(); |
||
178 | |||
179 | // 地域設定を優先するが、システムパラメーターなどに設定を持っていくか |
||
180 | // 後に書いてあるほど優先される |
||
181 | $priorityKeys = explode(',', $this->app['config']['tax_rule_priority']); |
||
182 | $priorityKeys = array(); |
||
183 | foreach (explode(',', $this->app['config']['tax_rule_priority']) as $key) { |
||
184 | $priorityKeys[] = str_replace('_', '', preg_replace('/_id\z/', '', $key)); |
||
185 | } |
||
186 | |||
187 | foreach ($TaxRules as $TaxRule) { |
||
188 | $rank = 0; |
||
189 | foreach ($priorityKeys as $index => $key) { |
||
190 | $arrayProperties = array_change_key_case($TaxRule->toArray()); |
||
191 | if ($arrayProperties[$key]) { |
||
192 | |||
193 | // 配列の数値添字を重みとして利用する |
||
194 | $rank += 1 << ($index + 1); |
||
195 | } |
||
196 | } |
||
197 | $TaxRule->setRank($rank); |
||
198 | } |
||
199 | |||
200 | // 適用日降順, rank 降順にソートする |
||
201 | usort($TaxRules, function($a, $b) { |
||
202 | return $a->compareTo($b); |
||
203 | }); |
||
204 | |||
205 | if (!empty($TaxRules)) { |
||
206 | $this->rules[$cacheKey] = $TaxRules[0]; |
||
207 | |||
208 | return $TaxRules[0]; |
||
209 | } else { |
||
210 | throw new NoResultException(); |
||
211 | } |
||
212 | } |
||
213 | |||
293 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.