| Conditions | 1 |
| Paths | 1 |
| Total Lines | 145 |
| Code Lines | 97 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 4 |
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 |
||
| 58 | public function schemaConstraintDataProvider() |
||
| 59 | { |
||
| 60 | return [ |
||
| 61 | |||
| 62 | // Choice |
||
| 63 | |||
| 64 | 'choice-string' => [ |
||
| 65 | 'field' => 'choiceString', |
||
| 66 | 'acceptedValue' => 'a lo mejor', |
||
| 67 | 'rejectedValue' => 'no puedo', |
||
| 68 | 'errorMessage' => 'Does not have a value in the enumeration ["si","no","a lo mejor","mas"]' |
||
| 69 | ], |
||
| 70 | 'choice-integer' => [ |
||
| 71 | 'field' => 'choiceInteger', |
||
| 72 | 'acceptedValue' => 0, |
||
| 73 | 'rejectedValue' => 5, |
||
| 74 | 'errorMessage' => 'Does not have a value in the enumeration [0,1,2]' |
||
| 75 | ], |
||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | 'email' => [ |
||
| 80 | 'field' => 'email', |
||
| 81 | 'acceptedValue' => '[email protected]', |
||
| 82 | 'rejectedValue' => 'invalidemail@sss.', |
||
| 83 | 'errorMessage' => 'Invalid email' |
||
| 84 | ], |
||
| 85 | |||
| 86 | // Url |
||
| 87 | |||
| 88 | 'url' => [ |
||
| 89 | 'field' => 'url', |
||
| 90 | 'acceptedValue' => 'https://github.com/libgraviton/graviton', |
||
| 91 | 'rejectedValue' => 'jjj--no-url', |
||
| 92 | 'errorMessage' => 'Invalid URL format' |
||
| 93 | ], |
||
| 94 | |||
| 95 | // Range |
||
| 96 | |||
| 97 | 'range-integer-lower-bound' => [ |
||
| 98 | 'field' => 'rangeInteger', |
||
| 99 | 'acceptedValue' => 5, |
||
| 100 | 'rejectedValue' => 4, |
||
| 101 | 'errorMessage' => 'Must have a minimum value of 5' |
||
| 102 | ], |
||
| 103 | 'range-integer-upper-bound' => [ |
||
| 104 | 'field' => 'rangeInteger', |
||
| 105 | 'acceptedValue' => 9, |
||
| 106 | 'rejectedValue' => 10, |
||
| 107 | 'errorMessage' => 'Must have a maximum value of 9' |
||
| 108 | ], |
||
| 109 | 'range-double-lower-bound' => [ |
||
| 110 | 'field' => 'rangeDouble', |
||
| 111 | 'acceptedValue' => 0.0, |
||
| 112 | 'rejectedValue' => -0.0001, |
||
| 113 | 'errorMessage' => 'Must have a minimum value of 0' |
||
| 114 | ], |
||
| 115 | 'range-double-upper-bound' => [ |
||
| 116 | 'field' => 'rangeDouble', |
||
| 117 | 'acceptedValue' => 1.0, |
||
| 118 | 'rejectedValue' => 1.0000001, |
||
| 119 | 'errorMessage' => 'Must have a maximum value of 1' |
||
| 120 | ], |
||
| 121 | 'range-integer-only-min' => [ |
||
| 122 | 'field' => 'rangeIntegerOnlyMin', |
||
| 123 | 'acceptedValue' => 5, |
||
| 124 | 'rejectedValue' => 4, |
||
| 125 | 'errorMessage' => 'Must have a minimum value of 5' |
||
| 126 | ], |
||
| 127 | 'range-integer-only-max' => [ |
||
| 128 | 'field' => 'rangeIntegerOnlyMax', |
||
| 129 | 'acceptedValue' => 5, |
||
| 130 | 'rejectedValue' => 6, |
||
| 131 | 'errorMessage' => 'Must have a maximum value of 5' |
||
| 132 | ], |
||
| 133 | |||
| 134 | // GreatherThanOrEqual |
||
| 135 | |||
| 136 | 'greaterthan-integer' => [ |
||
| 137 | 'field' => 'greaterThanOrEqualInt', |
||
| 138 | 'acceptedValue' => 0, |
||
| 139 | 'rejectedValue' => -1, |
||
| 140 | 'errorMessage' => 'Must have a minimum value of 0' |
||
| 141 | ], |
||
| 142 | 'greaterthan-double' => [ |
||
| 143 | 'field' => 'greaterThanOrEqualDouble', |
||
| 144 | 'acceptedValue' => 0.1, |
||
| 145 | 'rejectedValue' => 0, |
||
| 146 | 'errorMessage' => 'Must have a minimum value of 0.1' |
||
| 147 | ], |
||
| 148 | |||
| 149 | // LessThanOrEqual |
||
| 150 | |||
| 151 | 'lessthan-integer' => [ |
||
| 152 | 'field' => 'lessThanOrEqualInt', |
||
| 153 | 'acceptedValue' => 0, |
||
| 154 | 'rejectedValue' => 1, |
||
| 155 | 'errorMessage' => 'Must have a maximum value of 0' |
||
| 156 | ], |
||
| 157 | 'lessthan-double' => [ |
||
| 158 | 'field' => 'lessThanOrEqualDouble', |
||
| 159 | 'acceptedValue' => 0.1, |
||
| 160 | 'rejectedValue' => 0.1000001, |
||
| 161 | 'errorMessage' => 'Must have a maximum value of 0.1' |
||
| 162 | ], |
||
| 163 | |||
| 164 | // Decimal (a decimal formatted string field) |
||
| 165 | |||
| 166 | 'decimal-string' => [ |
||
| 167 | 'field' => 'decimalField', |
||
| 168 | 'acceptedValue' => '1000000000.5555', |
||
| 169 | 'rejectedValue' => '1.55555', // too much precision |
||
| 170 | 'errorMessage' => 'Does not match the regex pattern ^[+\-]?\d+(\.\d{0,4})?$' |
||
| 171 | ], |
||
| 172 | 'decimal-string-notation' => [ |
||
| 173 | 'field' => 'decimalField', |
||
| 174 | 'acceptedValue' => '1000000000', |
||
| 175 | 'rejectedValue' => '1,0', // wrong separator |
||
| 176 | 'errorMessage' => 'Does not match the regex pattern ^[+\-]?\d+(\.\d{0,4})?$' |
||
| 177 | ], |
||
| 178 | 'decimal-string-string' => [ |
||
| 179 | 'field' => 'decimalField', |
||
| 180 | 'acceptedValue' => '0', |
||
| 181 | 'rejectedValue' => 'somestring', // string |
||
| 182 | 'errorMessage' => 'Does not match the regex pattern ^[+\-]?\d+(\.\d{0,4})?$' |
||
| 183 | ], |
||
| 184 | |||
| 185 | // Count (number of array elements) |
||
| 186 | |||
| 187 | 'count-array-lower' => [ |
||
| 188 | 'field' => 'arrayCount', |
||
| 189 | 'acceptedValue' => ['a'], |
||
| 190 | 'rejectedValue' => [], |
||
| 191 | 'errorMessage' => 'There must be a minimum of 1 items in the array' |
||
| 192 | ], |
||
| 193 | 'count-array-lower' => [ |
||
| 194 | 'field' => 'arrayCount', |
||
| 195 | 'acceptedValue' => ['a', 'b', 'c'], |
||
| 196 | 'rejectedValue' => ['a', 'b', 'c', 'd'], |
||
| 197 | 'errorMessage' => 'There must be a maximum of 3 items in the array' |
||
| 198 | ] |
||
| 199 | |||
| 200 | |||
| 201 | ]; |
||
| 202 | } |
||
| 203 | } |
||
| 204 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.