Conditions | 12 |
Paths | 168 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
39 | protected function execute(InputInterface $input, OutputInterface $output) |
||
40 | { |
||
41 | /** @var EntityManager $em */ |
||
42 | $em = $this->getContainer()->get('doctrine')->getManager(); |
||
43 | |||
44 | $userFields = explode(',', $input->getArgument('fields')); |
||
|
|||
45 | $fields = []; |
||
46 | |||
47 | foreach ($userFields as $fieldName) { |
||
48 | $fields[$fieldName] = 'p.' . trim($fieldName); |
||
49 | } |
||
50 | |||
51 | if ('' !== $input->getOption('concat')) { |
||
52 | $fields['custom'] = $input->getOption('concat') . ' as custom'; |
||
53 | } |
||
54 | |||
55 | $dql = sprintf('SELECT p.id, %s FROM %s p', implode(', ', $fields), $input->getArgument('entity')); |
||
56 | |||
57 | $qb = $em->createQuery($dql); |
||
58 | |||
59 | if (array_key_exists('custom', $fields)) { |
||
60 | unset($fields['custom']); |
||
61 | } |
||
62 | |||
63 | $list = []; |
||
64 | |||
65 | foreach ($qb->getResult() as $record) { |
||
66 | foreach (array_keys($fields) as $field) { |
||
67 | if (preg_match_all('/\<img.*src=\"\/media(.*?)\".*\>/', $record[$field], $matches)) { |
||
68 | foreach ($matches[1] as $image) { |
||
69 | $imagePath = './web/media' . $image; |
||
70 | if (file_exists($imagePath)) { |
||
71 | $fileSize = filesize($imagePath); |
||
72 | $arr = [ |
||
73 | 'id' => $record['id'], |
||
74 | 'image' => $image, |
||
75 | 'size' => $this->humanFilesize($fileSize), |
||
76 | ]; |
||
77 | |||
78 | if ('' !== $input->getOption('concat')) { |
||
79 | $arr['custom'] = $record['custom']; |
||
80 | } |
||
81 | |||
82 | $list[$fileSize][] = $arr; |
||
83 | } else { |
||
84 | $output->writeln('File not found ' . $image); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | krsort($list); |
||
92 | |||
93 | foreach ($list as $fileSize => $sizes) { |
||
94 | foreach ($sizes as $size => $info) { |
||
95 | $output->writeln(implode(', ', $info)); |
||
96 | } |
||
116 |