| Total Lines | 71 |
| Code Lines | 35 |
| 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 |
||
| 39 | private function registerRequests() |
||
| 40 | { |
||
| 41 | // The server request |
||
| 42 | $this->set(ServerRequestCreator::class, function() { |
||
| 43 | $xRequestFactory = new Psr17Factory(); |
||
| 44 | return new ServerRequestCreator( |
||
| 45 | $xRequestFactory, // ServerRequestFactory |
||
| 46 | $xRequestFactory, // UriFactory |
||
| 47 | $xRequestFactory, // UploadedFileFactory |
||
| 48 | $xRequestFactory // StreamFactory |
||
| 49 | ); |
||
| 50 | }); |
||
| 51 | $this->set(ServerRequestInterface::class, function($c) { |
||
| 52 | return $c->g(ServerRequestCreator::class)->fromGlobals(); |
||
| 53 | }); |
||
| 54 | // The parameter reader |
||
| 55 | $this->set(ParameterReader::class, function($c) { |
||
| 56 | return new ParameterReader($c->g(Container::class), $c->g(ConfigManager::class), |
||
| 57 | $c->g(Translator::class), $c->g(UriDetector::class)); |
||
| 58 | }); |
||
| 59 | // Callback Manager |
||
| 60 | $this->set(CallbackManager::class, function() { |
||
| 61 | return new CallbackManager(); |
||
| 62 | }); |
||
| 63 | // Request Handler |
||
| 64 | $this->set(RequestHandler::class, function($c) { |
||
| 65 | return new RequestHandler($c->g(Container::class), $c->g(PluginManager::class), |
||
| 66 | $c->g(ResponseManager::class), $c->g(CallbackManager::class), |
||
| 67 | $c->g(UploadHandler::class), $c->g(DataBagPlugin::class)); |
||
| 68 | }); |
||
| 69 | // Upload file and dir name generator |
||
| 70 | $this->set(NameGeneratorInterface::class, function() { |
||
| 71 | return new class implements NameGeneratorInterface |
||
| 72 | { |
||
| 73 | public function random(int $nLength): string |
||
| 74 | { |
||
| 75 | return bin2hex(random_bytes((int)($nLength / 2))); |
||
| 76 | /*try |
||
| 77 | { |
||
| 78 | return bin2hex(random_bytes((int)($nLength / 2))); |
||
| 79 | } |
||
| 80 | catch(Exception $e){} |
||
| 81 | // Generate the name |
||
| 82 | $sChars = '0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz'; |
||
| 83 | return substr(str_shuffle($sChars), 0, $nLength);*/ |
||
| 84 | } |
||
| 85 | }; |
||
| 86 | }); |
||
| 87 | // File upload manager |
||
| 88 | $this->set(UploadManager::class, function($c) { |
||
| 89 | return new UploadManager($c->g(NameGeneratorInterface::class), $c->g(ConfigManager::class), |
||
| 90 | $c->g(Validator::class), $c->g(Translator::class)); |
||
| 91 | }); |
||
| 92 | // File upload plugin |
||
| 93 | $this->set(UploadHandler::class, function($c) { |
||
| 94 | return !$c->g(ConfigManager::class)->getOption('core.upload.enabled') ? null : |
||
| 95 | new UploadHandler($c->g(Container::class), $c->g(ResponseManager::class), $c->g(Translator::class)); |
||
| 96 | }); |
||
| 97 | // Request Factory |
||
| 98 | $this->set(Factory::class, function($c) { |
||
| 99 | return new Factory($c->g(CallableRegistry::class), $c->g(RequestFactory::class), |
||
| 100 | $c->g(ParameterFactory::class)); |
||
| 101 | }); |
||
| 102 | // Factory for requests to functions |
||
| 103 | $this->set(RequestFactory::class, function($c) { |
||
| 104 | $sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.function'); |
||
| 105 | return new RequestFactory($sPrefix, $c->g(DialogFacade::class), $c->g(Paginator::class)); |
||
| 106 | }); |
||
| 107 | // Parameter Factory |
||
| 108 | $this->set(ParameterFactory::class, function() { |
||
| 109 | return new ParameterFactory(); |
||
| 110 | }); |
||
| 173 |