Conditions | 4 |
Paths | 5 |
Total Lines | 75 |
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 |
||
29 | */ |
||
30 | public function process(ContainerBuilder $container) |
||
31 | { |
||
32 | $analysis = $container->getParameter(Configuration::ONGR_ANALYSIS_CONFIG); |
||
33 | $additionalDirs = $container->getParameter(Configuration::ONGR_INCLUDE_DIR_CONFIG); |
||
34 | |||
35 | $collector = $container->get('es.metadata_collector'); |
||
36 | |||
37 | $kernelProjectDir = $container->getParameter('kernel.project_dir'); |
||
38 | |||
39 | $namespaces = array(); |
||
40 | |||
41 | $finder = new Finder(); |
||
42 | $projectFiles = $finder->files()->in( |
||
43 | array_merge([ |
||
44 | $kernelProjectDir . '/src' |
||
45 | ], $additionalDirs) |
||
46 | )->name('*.php'); |
||
47 | |||
48 | foreach ($projectFiles as $file) { |
||
49 | $namespaces[] = $this->getFullNamespace($file) . '\\' . $this->getClassname($file); |
||
50 | } |
||
51 | |||
52 | $indexDefinition = new Definition( |
||
53 | 'ONGR\ElasticsearchBundle\Service\IndexService', |
||
54 | [] |
||
55 | ); |
||
56 | |||
57 | $container->autowire() |
||
58 | |||
59 | } |
||
|
|||
60 | |||
61 | |||
62 | private function getFullNamespace($filename) { |
||
63 | $lines = file($filename); |
||
64 | $namespaceLine = array_shift(preg_grep('/^namespace /', $lines)); |
||
65 | $match = array(); |
||
66 | preg_match('/^namespace (.*);$/', $namespaceLine, $match); |
||
67 | $fullNamespace = array_pop($match); |
||
68 | |||
69 | return $fullNamespace; |
||
70 | } |
||
71 | |||
72 | private function getClassname($filename) { |
||
73 | $directoriesAndFilename = explode('/', $filename); |
||
74 | $filename = array_pop($directoriesAndFilename); |
||
75 | $nameAndExtension = explode('.', $filename); |
||
76 | $className = array_shift($nameAndExtension); |
||
77 | |||
78 | return $className; |
||
79 | } |
||
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||
86 | // |
||
87 | // |
||
88 | // foreach ($managers as $managerName => $manager) { |
||
89 | // $connection = $manager['index']; |
||
90 | // $managerName = strtolower($managerName); |
||
91 | // |
||
92 | // $managerDefinition = new Definition( |
||
93 | // 'ONGR\ElasticsearchBundle\Service\Manager', |
||
94 | // [ |
||
95 | // $managerName, |
||
96 | // $connection, |
||
97 | // $analysis, |
||
98 | // $manager, |
||
99 | // ] |
||
100 | // ); |
||
101 | // $managerDefinition->setFactory( |
||
102 | // [ |
||
103 | // new Reference('es.manager_factory'), |
||
104 | // 'createManager', |
||
137 |