| Conditions | 2 |
| Paths | 1 |
| Total Lines | 133 |
| Code Lines | 101 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| 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 |
||
| 56 | public function __invoke(): ServiceManager |
||
| 57 | { |
||
| 58 | return new ServiceManager([ |
||
| 59 | 'abstract_factories' => [ |
||
| 60 | ReflectionBasedAbstractFactory::class, |
||
| 61 | ], |
||
| 62 | 'lazy_services' => [ |
||
| 63 | 'classmap' => [ |
||
| 64 | \Faker\Generator::class => \Faker\Generator::class, |
||
| 65 | ], |
||
| 66 | ], |
||
| 67 | 'aliases' => [ |
||
| 68 | Renderer::class => TwigRenderer::class, |
||
| 69 | ContainerInterface::class => ServiceManager::class, |
||
| 70 | Handler::class => LogHandler::class, |
||
| 71 | Sitemap::class => XmlStringSitemap::class, |
||
| 72 | TransportInterface::class => InMemory::class, |
||
| 73 | FormFactory::class => LaminasFormFactory::class, |
||
| 74 | CacheFactory::class => StashCacheFactory::class, |
||
| 75 | CacheItemPoolInterface::class => Pool::class, |
||
| 76 | ResponseInterface::class => Response::class, |
||
| 77 | RunInterface::class => Run::class, |
||
| 78 | 'response' => Response::class, |
||
| 79 | ], |
||
| 80 | 'factories' => [ |
||
| 81 | SessionMiddleware::class => function ( |
||
| 82 | ContainerInterface $container |
||
| 83 | ): SessionMiddleware { |
||
| 84 | $config = $container->get(Config::class); |
||
| 85 | $key = $config->get('key'); |
||
| 86 | assert(is_string($key)); |
||
| 87 | $time = (int)$config->get('session_time'); |
||
| 88 | return SessionMiddleware::fromSymmetricKeyDefaults( |
||
| 89 | $key, |
||
| 90 | $time |
||
| 91 | ); |
||
| 92 | }, |
||
| 93 | \Faker\Generator::class => function ( |
||
| 94 | ContainerInterface $container |
||
| 95 | ): \Faker\Generator { |
||
| 96 | $config = $container->get(Config::class); |
||
| 97 | return \Faker\Factory::create($config->get('locale')); |
||
| 98 | }, |
||
| 99 | Clockwork::class => function (): Clockwork { |
||
| 100 | return Clockwork::init(); |
||
| 101 | }, |
||
| 102 | Config::class => function (): Config { |
||
| 103 | return Config::fromFiles(glob(ROOT_DIR . 'config/*.*')); |
||
| 104 | }, |
||
| 105 | FilesystemInterface::class => function ( |
||
| 106 | ContainerInterface $container |
||
| 107 | ): MountManager { |
||
| 108 | $factory = $container->get(FlysystemFactory::class); |
||
| 109 | $config = $container->get(Config::class); |
||
| 110 | |||
| 111 | // Decorate the adapter |
||
| 112 | $contentFilesystem = $factory->make($config->filesystem->content); |
||
| 113 | $assetFilesystem = $factory->make($config->filesystem->assets); |
||
| 114 | $mediaFilesystem = $factory->make($config->filesystem->media); |
||
| 115 | $cacheFilesystem = $factory->make($config->filesystem->cache); |
||
| 116 | |||
| 117 | return new MountManager([ |
||
| 118 | 'content' => $contentFilesystem, |
||
| 119 | 'assets' => $assetFilesystem, |
||
| 120 | 'media' => $mediaFilesystem, |
||
| 121 | 'cache' => $cacheFilesystem, |
||
| 122 | ]); |
||
| 123 | }, |
||
| 124 | Source::class => function (ContainerInterface $container): Source { |
||
| 125 | $config = $container->get(Config::class)->get('source'); |
||
| 126 | /** @var class-string<Source> $config **/ |
||
| 127 | return $container->get($config); |
||
| 128 | }, |
||
| 129 | LoggerInterface::class => function ( |
||
| 130 | ContainerInterface $container |
||
| 131 | ): LoggerInterface { |
||
| 132 | /** @var Config **/ |
||
| 133 | $config = $container->get('PublishingKit\Config\Config'); |
||
| 134 | $factory = new MonologFactory(); |
||
| 135 | return $factory->make($config->get('loggers')); |
||
| 136 | }, |
||
| 137 | FilesystemLoader::class => function ( |
||
| 138 | ContainerInterface $container |
||
| 139 | ): FilesystemLoader { |
||
| 140 | return new FilesystemLoader(ROOT_DIR . 'resources' . DIRECTORY_SEPARATOR . 'views'); |
||
| 141 | }, |
||
| 142 | Environment::class => function (ContainerInterface $container): Environment { |
||
| 143 | $config = []; |
||
| 144 | if ($_ENV['APP_ENV'] !== 'development') { |
||
| 145 | $config['cache'] = ROOT_DIR . '/cache/views'; |
||
| 146 | } |
||
| 147 | return new Environment($container->get('Twig\Loader\FilesystemLoader'), $config); |
||
| 148 | }, |
||
| 149 | Router::class => function (ContainerInterface $container): Router { |
||
| 150 | $strategy = (new ApplicationStrategy())->setContainer($container); |
||
| 151 | $router = new Router(); |
||
| 152 | $router->setStrategy($strategy); |
||
| 153 | return $router; |
||
| 154 | }, |
||
| 155 | EventManagerInterface::class => function ( |
||
| 156 | ContainerInterface $container |
||
| 157 | ): EventManagerInterface { |
||
| 158 | /** @var EventManagerInterface **/ |
||
| 159 | $manager = $container->get(EventManager::class); |
||
| 160 | $manager->attach( |
||
| 161 | RegisterDynamicRoutes::class, |
||
| 162 | $container->get(RegisterSystemDynamicRoutes::class) |
||
| 163 | ); |
||
| 164 | $manager->attach( |
||
| 165 | RegisterViewHelpers::class, |
||
| 166 | $container->get(RegisterViews::class) |
||
| 167 | ); |
||
| 168 | return $manager; |
||
| 169 | }, |
||
| 170 | Server::class => function (ContainerInterface $container) { |
||
| 171 | $fs = $container->get('League\Flysystem\FilesystemInterface'); |
||
| 172 | $source = $fs->getFilesystem('media'); |
||
| 173 | $cache = $fs->getFilesystem('cache'); |
||
| 174 | return ServerFactory::create([ |
||
| 175 | 'source' => $source, |
||
| 176 | 'cache' => $cache, |
||
| 177 | 'response' => new PsrResponseFactory(new Response(), function ($stream) { |
||
| 178 | return new Stream($stream); |
||
| 179 | }), |
||
| 180 | ]); |
||
| 181 | }, |
||
| 182 | CacheContract::class => function (ContainerInterface $container): CacheContract { |
||
| 183 | return new Psr6Cache($container->get(CacheItemPoolInterface::class)); |
||
| 184 | }, |
||
| 185 | Pool::class => function (ContainerInterface $container): Pool { |
||
| 186 | $factory = $container->get(CacheFactory::class); |
||
| 187 | $config = $container->get(Config::class); |
||
| 188 | return $factory->make($config->cache->toArray()); |
||
| 189 | } |
||
| 194 |