Conditions | 5 |
Paths | 16 |
Total Lines | 51 |
Code Lines | 34 |
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 |
||
51 | public function handle() |
||
52 | { |
||
53 | $hasErrors = false; |
||
54 | /** @var PublisherInterface $entity */ |
||
55 | foreach ($this->container->getPublishers() as $publisherName => $entity) { |
||
56 | try { |
||
57 | $entity->delete(); |
||
58 | $this->output->writeln( |
||
59 | sprintf( |
||
60 | "Deleted entity <info>%s</info> for publisher [<fg=yellow>%s</>]", |
||
61 | (string)$entity->getAliasName(), |
||
62 | (string)$publisherName |
||
63 | ) |
||
64 | ); |
||
65 | } catch (\Exception $e) { |
||
66 | $hasErrors = true; |
||
67 | $this->output->error( |
||
68 | sprintf( |
||
69 | "Could not delete entity %s for publisher [%s], got:\n%s", |
||
70 | (string)$entity->getAliasName(), |
||
71 | (string)$publisherName, |
||
72 | (string)$e->getMessage() |
||
73 | ) |
||
74 | ); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | foreach ($this->container->getConsumers() as $consumerAliasName => $entity) { |
||
79 | try { |
||
80 | /** @var QueueEntity $entity */ |
||
81 | $entity->delete(); |
||
82 | $this->output->writeln( |
||
83 | sprintf( |
||
84 | "Deleted entity <info>%s</info> for consumer [<fg=yellow>%s</>]", |
||
85 | (string)$entity->getAliasName(), |
||
86 | (string)$consumerAliasName |
||
87 | ) |
||
88 | ); |
||
89 | } catch (\Exception $e) { |
||
90 | $hasErrors = true; |
||
91 | $this->output->error( |
||
92 | sprintf( |
||
93 | "Could not delete entity %s for consumer [%s], got:\n%s", |
||
94 | (string)$entity->getAliasName(), |
||
95 | (string)$consumerAliasName, |
||
96 | (string)$e->getMessage() |
||
97 | ) |
||
98 | ); |
||
99 | } |
||
100 | } |
||
101 | return (int)$hasErrors; |
||
102 | } |
||
104 |