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