Conditions | 9 |
Paths | 64 |
Total Lines | 59 |
Code Lines | 27 |
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 |
||
34 | public function compileProject(SettingsInterface $settings, RouteCollectionInterface &$routes = null): string |
||
35 | { |
||
36 | $settings = new ManagedSettings($settings, new ArraySettings(self::DEFAULT_SETTINGS)); |
||
37 | |||
38 | $container = new NaiveContainer; |
||
39 | |||
40 | if ($settings->hasSetting('container')) { |
||
41 | /** @var ContainerInterface */ |
||
42 | $container = $this->build('container', ContainerInterface::CLASS, $container, $settings); |
||
|
|||
43 | } |
||
44 | |||
45 | if ($container->has($settings->getSetting('bootstrap'))) { |
||
46 | /** @var BootstrapInterface */ |
||
47 | $bootstrap = $this->build('bootstrap', BootstrapInterface::CLASS, $container, $settings); |
||
48 | $bootstrap->bootstrap($settings); |
||
49 | } |
||
50 | |||
51 | /** @var RouteFactoryInterface */ |
||
52 | $routeFactory = $this->build('route-factory', RouteFactoryInterface::CLASS, $container, $settings); |
||
53 | |||
54 | /** @var RouteCollectionInterface[] */ |
||
55 | $collections = []; |
||
56 | |||
57 | foreach ((array)$settings->getSetting('source-classes') as $classname) { |
||
58 | $collections[] = $routeFactory->createRoutesFrom($classname); |
||
59 | } |
||
60 | |||
61 | if ($settings->getSetting('source-dir')) { |
||
62 | $classFinder = new Psr4ClassFinder( |
||
63 | $settings->getSetting('source-dir'), |
||
64 | $settings->getSetting('source-prefix') |
||
65 | ); |
||
66 | |||
67 | foreach ($classFinder as $classname) { |
||
68 | $collections[] = $routeFactory->createRoutesFrom((string)$classname); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** @var CompilerInterface */ |
||
73 | $compiler = $this->build('compiler', CompilerInterface::CLASS, $container, $settings); |
||
74 | |||
75 | foreach (['core-compiler-passes', 'compiler-passes'] as $settingName) { |
||
76 | foreach ((array)$settings->getSetting($settingName) as $serviceName) { |
||
77 | $compilerPass = $container->get($serviceName); |
||
78 | |||
79 | if (!$compilerPass instanceof CompilerPassInterface) { |
||
80 | throw new CompilerException("Service '$serviceName' must implement CompilerPassInterface"); |
||
81 | } |
||
82 | |||
83 | $compiler->addCompilerPass($compilerPass); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | $routes = $compiler->compile(...$collections); |
||
88 | |||
89 | /** @var CodeGeneratorInterface */ |
||
90 | $generator = $this->build('code-generator', CodeGeneratorInterface::CLASS, $container, $settings); |
||
91 | |||
92 | return $generator->generateRouterCode($settings, $routes); |
||
93 | } |
||
112 |