| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 26 |
| 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 |
||
| 61 | protected function registerClasses() |
||
| 62 | { |
||
| 63 | //region Annotations |
||
| 64 | AnnotationRegistry::registerLoader('class_exists'); |
||
| 65 | |||
| 66 | $this->app->singleton('app.annotation_reader', function (Application $app) { |
||
|
|
|||
| 67 | return new AnnotationReader; |
||
| 68 | }); |
||
| 69 | //endregion |
||
| 70 | |||
| 71 | //region Serializer |
||
| 72 | $this->app->singleton('api.serializer', function (Application $app) { |
||
| 73 | return $this->prepareSerializer()->build(); |
||
| 74 | }); |
||
| 75 | //endregion |
||
| 76 | |||
| 77 | //region JSON Schema Constraint |
||
| 78 | $this->app->singleton('api.schema.constraint', function (Application $app) { |
||
| 79 | $fileRetriever = new FileGetContents; |
||
| 80 | $fileRetriever->setBasePath(config(self::CONFIG_KEY . '.request.schema_path') . DIRECTORY_SEPARATOR); |
||
| 81 | |||
| 82 | $retriever = (new UriRetriever) |
||
| 83 | ->setUriRetriever($fileRetriever); |
||
| 84 | |||
| 85 | $constraintFactory = new Factory(new SchemaStorage($retriever)); |
||
| 86 | $constraintFactory->setConfig(Constraint::CHECK_MODE_APPLY_DEFAULTS | Constraint::CHECK_MODE_COERCE_TYPES); |
||
| 87 | |||
| 88 | return $constraintFactory; |
||
| 89 | }); |
||
| 90 | //endregion |
||
| 91 | |||
| 92 | //region JSON Schema Validator |
||
| 93 | $this->app->singleton('api.schema.validator', function (Application $app) { |
||
| 94 | return new Validator( |
||
| 95 | $app->make('api.schema.constraint') |
||
| 96 | ); |
||
| 97 | }); |
||
| 98 | //endregion |
||
| 99 | |||
| 100 | //region RequestHandler |
||
| 101 | $this->app->singleton(RequestHandler::class, function (Application $app) { |
||
| 102 | $serializer = $this->prepareSerializer() |
||
| 103 | ->configureListeners(function (EventDispatcher $dispatcher) use ($app) { |
||
| 104 | $dispatcher->addSubscriber( |
||
| 105 | new RequestDeserializationHandler( |
||
| 106 | $app->make('api.schema.validator'), |
||
| 107 | $app->make('purifier') |
||
| 108 | ) |
||
| 109 | ); |
||
| 110 | }) |
||
| 111 | ->build(); |
||
| 112 | |||
| 113 | return new RequestHandler($serializer); |
||
| 114 | }); |
||
| 115 | //endregion |
||
| 116 | } |
||
| 117 | |||
| 158 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.