| Conditions | 1 |
| Paths | 1 |
| Total Lines | 182 |
| Code Lines | 108 |
| 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 |
||
| 71 | public function validateDataProvider() |
||
| 72 | { |
||
| 73 | $constraint = new CategoriesConstraint(); |
||
| 74 | |||
| 75 | return [ |
||
| 76 | 'not collection' => [null, RFMMetricCategory::TYPE_FREQUENCY], |
||
| 77 | 'count violation' => [ |
||
| 78 | 'collection' => $this->getCollection( |
||
| 79 | [ |
||
| 80 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 100), |
||
| 81 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 100, null), |
||
| 82 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 1000, null), |
||
| 83 | ] |
||
| 84 | ), |
||
| 85 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 86 | 'expectedViolationsMessages' => |
||
| 87 | [ |
||
| 88 | $constraint->blankMessage, |
||
| 89 | ] |
||
| 90 | ], |
||
| 91 | 'ordered' => [ |
||
| 92 | 'collection' => $this->getCollection( |
||
| 93 | [ |
||
| 94 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 20), |
||
| 95 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 96 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 30, null), |
||
| 97 | ] |
||
| 98 | ), |
||
| 99 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 100 | ], |
||
| 101 | 'asc order violation' => [ |
||
| 102 | 'collection' => $this->getCollection( |
||
| 103 | [ |
||
| 104 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 20), |
||
| 105 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 106 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 10, 40), |
||
| 107 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 4, 40, null), |
||
| 108 | ] |
||
| 109 | ), |
||
| 110 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 111 | 'expectedViolationsMessage' => [ |
||
| 112 | $constraint->message |
||
| 113 | ], |
||
| 114 | ], |
||
| 115 | 'desc order' => [ |
||
| 116 | 'collection' => $this->getCollection( |
||
| 117 | [ |
||
| 118 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, 30, null), |
||
| 119 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 120 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, null, 20), |
||
| 121 | ] |
||
| 122 | ), |
||
| 123 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 124 | ], |
||
| 125 | 'desc order violation' => [ |
||
| 126 | 'collection' => $this->getCollection( |
||
| 127 | [ |
||
| 128 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, 30, null), |
||
| 129 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 130 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 25, 20), |
||
| 131 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 4, null, 10), |
||
| 132 | ] |
||
| 133 | ), |
||
| 134 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 135 | 'expectedViolationsMessage' => [ |
||
| 136 | $constraint->message |
||
| 137 | ], |
||
| 138 | ], |
||
| 139 | 'desc order same value violation' => [ |
||
| 140 | 'collection' => $this->getCollection( |
||
| 141 | [ |
||
| 142 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, 30, null), |
||
| 143 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 144 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 20, 20), |
||
| 145 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 4, null, 10), |
||
| 146 | ] |
||
| 147 | ), |
||
| 148 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 149 | 'expectedViolationsMessage' => [ |
||
| 150 | $constraint->message |
||
| 151 | ], |
||
| 152 | ], |
||
| 153 | 'asc order same value violation' => [ |
||
| 154 | 'collection' => $this->getCollection( |
||
| 155 | [ |
||
| 156 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 20), |
||
| 157 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 20, 30), |
||
| 158 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 30, 30), |
||
| 159 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 4, 40, null), |
||
| 160 | ] |
||
| 161 | ), |
||
| 162 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 163 | 'expectedViolationsMessage' => [ |
||
| 164 | $constraint->message |
||
| 165 | ], |
||
| 166 | ], |
||
| 167 | 'blank value violation asc mid' => [ |
||
| 168 | 'collection' => $this->getCollection( |
||
| 169 | [ |
||
| 170 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 100), |
||
| 171 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 100, null), |
||
| 172 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 1000, null), |
||
| 173 | ] |
||
| 174 | ), |
||
| 175 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 176 | 'expectedViolationsMessages' => |
||
| 177 | [ |
||
| 178 | $constraint->blankMessage, |
||
| 179 | ] |
||
| 180 | ], |
||
| 181 | 'blank value violation desc mid' => [ |
||
| 182 | 'collection' => $this->getCollection( |
||
| 183 | [ |
||
| 184 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, 1000, null), |
||
| 185 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, null, 1000), |
||
| 186 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, null, 100), |
||
| 187 | ] |
||
| 188 | ), |
||
| 189 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 190 | 'expectedViolationsMessages' => |
||
| 191 | [ |
||
| 192 | $constraint->blankMessage, |
||
| 193 | ] |
||
| 194 | ], |
||
| 195 | 'blank value violation asc first empty' => [ |
||
| 196 | 'collection' => $this->getCollection( |
||
| 197 | [ |
||
| 198 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, null), |
||
| 199 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 100, 1000), |
||
| 200 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, 1000, null), |
||
| 201 | ] |
||
| 202 | ), |
||
| 203 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 204 | 'expectedViolationsMessages' => |
||
| 205 | [ |
||
| 206 | $constraint->blankMessage, |
||
| 207 | ] |
||
| 208 | ], |
||
| 209 | 'blank value violation asc last empty' => [ |
||
| 210 | 'collection' => $this->getCollection( |
||
| 211 | [ |
||
| 212 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, 100), |
||
| 213 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 100, 1000), |
||
| 214 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, null, null), |
||
| 215 | ] |
||
| 216 | ), |
||
| 217 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 218 | 'expectedViolationsMessages' => |
||
| 219 | [ |
||
| 220 | $constraint->blankMessage, |
||
| 221 | ] |
||
| 222 | ], |
||
| 223 | 'blank value violation desc first empty' => [ |
||
| 224 | 'collection' => $this->getCollection( |
||
| 225 | [ |
||
| 226 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, null, null), |
||
| 227 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 1000, 1000), |
||
| 228 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, null, 100), |
||
| 229 | ] |
||
| 230 | ), |
||
| 231 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 232 | 'expectedViolationsMessages' => |
||
| 233 | [ |
||
| 234 | $constraint->blankMessage, |
||
| 235 | ] |
||
| 236 | ], |
||
| 237 | 'blank value violation desc last empty' => [ |
||
| 238 | 'collection' => $this->getCollection( |
||
| 239 | [ |
||
| 240 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 1, 1000, null), |
||
| 241 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 2, 1000, 1000), |
||
| 242 | $this->getCategory(RFMMetricCategory::TYPE_FREQUENCY, 3, null, null), |
||
| 243 | ] |
||
| 244 | ), |
||
| 245 | 'type' => RFMMetricCategory::TYPE_FREQUENCY, |
||
| 246 | 'expectedViolationsMessages' => |
||
| 247 | [ |
||
| 248 | $constraint->blankMessage, |
||
| 249 | ] |
||
| 250 | ] |
||
| 251 | ]; |
||
| 252 | } |
||
| 253 | |||
| 297 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.