| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 54 | public function boot(TokenizerBootloader $tokenizer): void |
||
| 55 | { |
||
| 56 | $this->config->setDefaults( |
||
| 57 | 'validation', |
||
| 58 | [ |
||
| 59 | // Checkers are resolved using container and provide ability to isolate some validation rules |
||
| 60 | // under common name and class. You can register new checkers at any moment without any |
||
| 61 | // performance issues. |
||
| 62 | 'checkers' => [ |
||
| 63 | 'type' => Checker\TypeChecker::class, |
||
| 64 | 'number' => Checker\NumberChecker::class, |
||
| 65 | 'mixed' => Checker\MixedChecker::class, |
||
| 66 | 'address' => Checker\AddressChecker::class, |
||
| 67 | 'string' => Checker\StringChecker::class, |
||
| 68 | 'file' => Checker\FileChecker::class, |
||
| 69 | 'image' => Checker\ImageChecker::class, |
||
| 70 | 'datetime' => Checker\DatetimeChecker::class, |
||
| 71 | 'entity' => Checker\EntityChecker::class, |
||
| 72 | ], |
||
| 73 | |||
| 74 | // Enable/disable validation conditions |
||
| 75 | 'conditions' => [ |
||
| 76 | 'absent' => Condition\AbsentCondition::class, |
||
| 77 | 'present' => Condition\PresentCondition::class, |
||
| 78 | 'anyOf' => Condition\AnyOfCondition::class, |
||
| 79 | 'noneOf' => Condition\NoneOfCondition::class, |
||
| 80 | 'withAny' => Condition\WithAnyCondition::class, |
||
| 81 | 'withoutAny' => Condition\WithoutAnyCondition::class, |
||
| 82 | 'withAll' => Condition\WithAllCondition::class, |
||
| 83 | 'withoutAll' => Condition\WithoutAllCondition::class, |
||
| 84 | ], |
||
| 85 | |||
| 86 | // Aliases are only used to simplify developer life. |
||
| 87 | 'aliases' => [ |
||
| 88 | 'notEmpty' => 'type::notEmpty', |
||
| 89 | 'notNull' => 'type::notNull', |
||
| 90 | 'required' => 'type::notEmpty', |
||
| 91 | 'datetime' => 'type::datetime', |
||
| 92 | 'timezone' => 'type::timezone', |
||
| 93 | 'bool' => 'type::boolean', |
||
| 94 | 'boolean' => 'type::boolean', |
||
| 95 | 'arrayOf' => 'type::arrayOf', |
||
| 96 | 'cardNumber' => 'mixed::cardNumber', |
||
| 97 | 'regexp' => 'string::regexp', |
||
| 98 | 'email' => 'address::email', |
||
| 99 | 'url' => 'address::url', |
||
| 100 | 'file' => 'file::exists', |
||
| 101 | 'uploaded' => 'file::uploaded', |
||
| 102 | 'filesize' => 'file::size', |
||
| 103 | 'image' => 'image::valid', |
||
| 104 | 'array' => 'is_array', |
||
| 105 | 'callable' => 'is_callable', |
||
| 106 | 'double' => 'is_double', |
||
| 107 | 'float' => 'is_float', |
||
| 108 | 'int' => 'is_int', |
||
| 109 | 'integer' => 'is_integer', |
||
| 110 | 'numeric' => 'is_numeric', |
||
| 111 | 'long' => 'is_long', |
||
| 112 | 'null' => 'is_null', |
||
| 113 | 'object' => 'is_object', |
||
| 114 | 'real' => 'is_real', |
||
| 115 | 'resource' => 'is_resource', |
||
| 116 | 'scalar' => 'is_scalar', |
||
| 117 | 'string' => 'is_string', |
||
| 118 | 'match' => 'mixed::match', |
||
| 119 | ], |
||
| 120 | ] |
||
| 121 | ); |
||
| 122 | |||
| 123 | |||
| 124 | $tokenizer->addDirectory(\dirname( |
||
| 125 | (new \ReflectionClass(ValidatorInterface::class)) |
||
| 126 | ->getFileName() |
||
| 127 | )); |
||
| 157 |