| Conditions | 25 |
| Paths | > 20000 |
| Total Lines | 158 |
| Code Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 147 | public static function yamlFieldToSchema(array $data): array |
||
| 148 | { |
||
| 149 | $column = []; |
||
| 150 | $key = (string) $data['key']; |
||
| 151 | $type = (string) $data['type']; |
||
| 152 | $column['key'] = $key; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Entrada: |
||
| 156 | * - type es el tipo lógico del campo y tiene que estar definido como índice en |
||
| 157 | * TYPES, o ser uno de los predefinidos como 'autoincrement', 'relationship', etc. |
||
| 158 | * |
||
| 159 | * Salida: |
||
| 160 | * - type queda intacto. |
||
| 161 | * - dbtype es como queda definido en la tabla, por ejemplo, varchar(20) |
||
| 162 | * - realtype es el tipo resultado, por ejemplo varchar (sin el tamaño) |
||
| 163 | * - generictype es uno de los índices de TYPE. P.E. autoincrement se cambiará por integer |
||
| 164 | * |
||
| 165 | */ |
||
| 166 | |||
| 167 | $column['type'] = $type; |
||
| 168 | switch ($type) { |
||
| 169 | case 'autoincrement': |
||
| 170 | case 'relationship': |
||
| 171 | $colType = DB::getIndexType(); |
||
| 172 | break; |
||
| 173 | default: |
||
| 174 | $colType = $type; |
||
| 175 | } |
||
| 176 | |||
| 177 | $typeArray = static::splitType($colType); |
||
| 178 | /** |
||
| 179 | * ^ array:4 [▼ |
||
| 180 | * "type" => "bigint" |
||
| 181 | * "length" => null |
||
| 182 | * "unsigned" => "yes" |
||
| 183 | * "zerofill" => "no" |
||
| 184 | * ] |
||
| 185 | */ |
||
| 186 | |||
| 187 | $type = $typeArray['type']; |
||
| 188 | $length = $typeArray['length'] ?? $data['length']; |
||
| 189 | $unsigned = $typeArray['unsigned'] === 'yes'; |
||
| 190 | $zerofill = $typeArray['zerofill'] === 'yes'; |
||
| 191 | $genericType = Schema::getTypeOf($type); |
||
| 192 | |||
| 193 | $column['dbtype'] = $colType; |
||
| 194 | $column['realtype'] = $type; |
||
| 195 | $column['generictype'] = $genericType; |
||
| 196 | |||
| 197 | $column['null'] = 'YES'; |
||
| 198 | if ($data['null'] && mb_strtolower($data['null']) == 'no') { |
||
| 199 | $column['null'] = 'NO'; |
||
| 200 | } |
||
| 201 | |||
| 202 | if (empty($data['default'])) { |
||
| 203 | $column['default'] = null; |
||
| 204 | } else { |
||
| 205 | $column['default'] = (string) $data['default']; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Pueden existir otras definiciones de limitaciones físicas como min y max |
||
| 210 | * De existir, tienen que ser contempladas en el método test y tener mayor peso que |
||
| 211 | * la limitación en plantilla. |
||
| 212 | */ |
||
| 213 | foreach (['min', 'max'] as $field) { |
||
| 214 | if (isset($data[$field])) { |
||
| 215 | $column[$field] = (string) $data[$field]; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | if (isset($data['comment'])) { |
||
| 220 | $column['comentario'] = (string) $data['comment']; |
||
| 221 | } |
||
| 222 | |||
| 223 | if (isset($data['default'])) { |
||
| 224 | if (is_bool($data['default'])) { |
||
| 225 | $column['default'] = $data['default'] ? '1' : '0'; |
||
| 226 | } else { |
||
| 227 | $column['default'] = trim($data['default'], " \"'`"); |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | switch ($genericType) { |
||
| 232 | case 'text': |
||
| 233 | $column['dbtype'] = 'varchar(' . $length . ')'; |
||
| 234 | $column['maxlength'] = $length; |
||
| 235 | break; |
||
| 236 | case 'integer': |
||
| 237 | /** |
||
| 238 | * Lo primero es ver la capacidad física máxima según el tipo de dato. |
||
| 239 | */ |
||
| 240 | $bytes = 4; |
||
| 241 | switch ($type) { |
||
| 242 | case 'tinyint': |
||
| 243 | $bytes = 1; |
||
| 244 | break; |
||
| 245 | case 'smallint': |
||
| 246 | $bytes = 2; |
||
| 247 | break; |
||
| 248 | case 'mediumint': |
||
| 249 | $bytes = 3; |
||
| 250 | break; |
||
| 251 | case 'int': |
||
| 252 | $bytes = 4; |
||
| 253 | break; |
||
| 254 | case 'bigint': |
||
| 255 | $bytes = 8; |
||
| 256 | break; |
||
| 257 | } |
||
| 258 | $bits = 8 * (int) $bytes; |
||
| 259 | $physicalMaxLength = 2 ** $bits; |
||
| 260 | |||
| 261 | /** |
||
| 262 | * $minDataLength y $maxDataLength contendrán el mínimo y máximo valor que puede contener el campo. |
||
| 263 | */ |
||
| 264 | $minDataLength = $unsigned ? 0 : -$physicalMaxLength / 2; |
||
| 265 | $maxDataLength = ($unsigned ? $physicalMaxLength : $physicalMaxLength / 2) - 1; |
||
| 266 | |||
| 267 | /** |
||
| 268 | * De momento, se asignan los límites máximos por el tipo de dato. |
||
| 269 | * En $min y $max, iremos arrastrando los límites conforme se vayan comprobando. |
||
| 270 | * $min nunca podrá ser menor que $minDataLength. |
||
| 271 | * $max nunca podrá ser mayor que $maxDataLength. |
||
| 272 | */ |
||
| 273 | $min = $minDataLength; |
||
| 274 | $max = $maxDataLength; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Se puede hacer una limitación física Se puede haber definido en el xml un min y un max. |
||
| 278 | * A todos los efectos, lo definido en el XML como min o max se toma como limitación |
||
| 279 | * física del campo. |
||
| 280 | */ |
||
| 281 | if (isset($data['min'])) { |
||
| 282 | $minXmlLength = $data['min']; |
||
| 283 | if ($minXmlLength > $minDataLength) { |
||
| 284 | $min = $minXmlLength; |
||
| 285 | } else { |
||
| 286 | Debug::message("({$key}): Se ha especificado un min {$minXmlLength} en el XML, pero por el tipo de datos, el mínimo es {$minDataLength}."); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | if (isset($data['max'])) { |
||
| 290 | $maxXmlLength = $data['max']; |
||
| 291 | if ($maxXmlLength < $maxDataLength) { |
||
| 292 | $max = $maxXmlLength; |
||
| 293 | } else { |
||
| 294 | Debug::message("({$key}): Se ha especificado un min {$maxXmlLength} en el XML, pero por el tipo de datos, el máximo es {$maxDataLength}."); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | $column['min'] = $min; |
||
| 299 | $column['max'] = $max; |
||
| 300 | break; |
||
| 301 | default: |
||
| 302 | // ??? |
||
| 303 | } |
||
| 304 | return $column; |
||
| 305 | } |
||
| 500 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths