Conditions | 6 |
Paths | 6 |
Total Lines | 56 |
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 |
||
78 | private function createSenders(array $config, ContainerBuilder $container) |
||
79 | { |
||
80 | $configuration = []; |
||
81 | $mainSender = $this->getSender($config['main_sender'], $config); |
||
82 | |||
83 | if (isset($mainSender['chain'])) { |
||
84 | foreach ($mainSender['chain']['senders'] as $sender) { |
||
85 | $configuration[$sender] = $this->getSender($sender, $config); |
||
86 | } |
||
87 | } else { |
||
88 | $configuration[$config['main_sender']] = $mainSender; |
||
89 | } |
||
90 | |||
91 | $senders = []; |
||
92 | $repositories = []; |
||
93 | foreach ($configuration as $senderName => $senderConfig) { |
||
94 | if (false === isset($senderConfig['sender'], $senderConfig['repository']) || |
||
95 | false === isset($senderConfig['sender']['class'], $senderConfig['repository']['class'])) { |
||
96 | throw new InvalidConfigurationException(sprintf('"sender" and "repository" must be defined in "%s" sender.', $senderName)); |
||
97 | } |
||
98 | |||
99 | $sender = new Definition($senderConfig['sender']['class']); |
||
100 | $sender |
||
101 | ->setPublic(true) |
||
102 | ->setAutoconfigured(true) |
||
103 | ->setAutowired(true); |
||
104 | |||
105 | $repository = new Definition($senderConfig['repository']['class']); |
||
106 | $repository |
||
107 | ->setPublic(true) |
||
108 | ->setAutoconfigured(true) |
||
109 | ->setAutowired(true); |
||
110 | |||
111 | $container->addDefinitions([ |
||
112 | $senderConfig['repository']['class'] => $repository, |
||
113 | $senderConfig['sender']['class'] => $sender, |
||
114 | ]); |
||
115 | |||
116 | // Prepare senders and repositories for injecting into mailer |
||
117 | $senders[$senderConfig['sender']['class']] = $sender; |
||
118 | $repositories[$senderConfig['repository']['class']] = $repository; |
||
119 | } |
||
120 | |||
121 | $mailer = new Definition(Mailer::class); |
||
122 | $mailer |
||
123 | ->setPublic(true) |
||
124 | ->setArguments([ |
||
125 | new Reference(ParameterResolverInterface::class), |
||
126 | new Reference(LoggerInterface::class), |
||
127 | ]) |
||
128 | ->addMethodCall('setConfiguration', [$configuration]) |
||
129 | ->addMethodCall('setSenders', [$senders]) |
||
130 | ->addMethodCall('setRepositories', [$repositories]); |
||
131 | |||
132 | $container->setDefinition(Mailer::class, $mailer); |
||
133 | } |
||
134 | |||
184 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.