Conditions | 11 |
Paths | 33 |
Total Lines | 51 |
Code Lines | 25 |
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 |
||
61 | private function getLoggablePaths(ContainerBuilder $container, array $config): array |
||
62 | { |
||
63 | $loggableClasses = ['yml' => [], 'xml' => [], 'dir' => []]; |
||
64 | |||
65 | if (!array_key_exists('loggable_paths', $config)) { |
||
66 | return $loggableClasses; |
||
67 | } |
||
68 | |||
69 | $loggablePaths = $config['loggable_paths']; |
||
70 | |||
71 | // add default paths |
||
72 | $kernelRoot = $container->getParameter('kernel.project_dir'); |
||
73 | |||
74 | if(is_dir($dir = $kernelRoot.'/Resources/config/loggastic')) { |
||
75 | $loggablePaths[] = $dir; |
||
76 | } |
||
77 | |||
78 | if(is_dir($dir = $kernelRoot.'/src/Entity')) { |
||
79 | $loggablePaths[] = $dir; |
||
80 | } |
||
81 | |||
82 | $loggablePaths = array_unique($loggablePaths); |
||
83 | |||
84 | foreach ($loggablePaths as $path) { |
||
85 | if (is_dir($path)) { |
||
86 | foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) { |
||
87 | $loggableClasses['yaml' === ($extension = $file->getExtension()) ? 'yml' : $extension][] = $file->getRealPath(); |
||
88 | } |
||
89 | |||
90 | $loggableClasses['dir'][] = $path; |
||
91 | $container->addResource(new DirectoryResource($path, '/\.(xml|ya?ml|php)$/')); |
||
92 | |||
93 | continue; |
||
94 | } |
||
95 | |||
96 | if ($container->fileExists($path, false)) { |
||
97 | if (!preg_match('/\.(xml|ya?ml)$/', (string) $path, $matches)) { |
||
98 | throw new RuntimeException(sprintf('Unsupported mapping type in "%s", supported types are XML & YAML.', $path)); |
||
99 | } |
||
100 | |||
101 | $loggableClasses['yaml' === $matches[1] ? 'yml' : $matches[1]][] = $path; |
||
102 | |||
103 | continue; |
||
104 | } |
||
105 | |||
106 | throw new RuntimeException(sprintf('Could not open file or directory "%s".', $path)); |
||
107 | } |
||
108 | |||
109 | $container->setParameter('locastic_activity_logs.loggable_class_class_directories', $loggableClasses['dir']); |
||
110 | |||
111 | return $loggableClasses; |
||
112 | } |
||
114 |