Conditions | 8 |
Paths | 80 |
Total Lines | 55 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 14 | ||
Bugs | 0 | Features | 6 |
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 |
||
42 | protected function execute(InputInterface $input, OutputInterface $output) |
||
43 | { |
||
44 | $container = new Container(); |
||
45 | $verbose = (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()); |
||
46 | $strategy = $container->getChainStrategy(); |
||
47 | $executor = $container->getExecutor(!$input->getOption('no-cache'), $verbose, $input->getOption('timeout')); |
||
48 | $serviceManager = $container->getServiceManager($verbose); |
||
49 | $notifier = NotifierFactory::create(); |
||
50 | |||
51 | $output->writeln("<info>Creating builds...</info>"); |
||
52 | |||
53 | $jobs = $strategy->getJobs($input->getOption("project-path")); |
||
54 | |||
55 | $output->writeln(sprintf("<info>%s builds created</info>", count($jobs))); |
||
56 | |||
57 | $exitCode = 0; |
||
58 | |||
59 | try { |
||
60 | foreach ($jobs as $job) { |
||
61 | $output->writeln(sprintf("\n<info>Running job %s</info>\n", $job->getDescription())); |
||
62 | |||
63 | $serviceManager->start($job); |
||
64 | $strategy->prepareJob($job); |
||
65 | |||
66 | $success = $executor->test($job, $input->getArgument('cmd')); |
||
67 | $exitCode += $success == 0 ? 0 : 1; |
||
68 | |||
69 | if ($input->getOption('notify')) { |
||
70 | $notification = new Notification(); |
||
71 | $notification->setBody(sprintf('Test results for %s on %s', $container->getNaming()->getProjectName($input->getOption('project-path')), $job->getDescription())); |
||
72 | $notification->setTitle($success == 0 ? 'Tests passed' : 'Tests failed'); |
||
73 | |||
74 | $notifier->send($notification); |
||
75 | } |
||
76 | |||
77 | $serviceManager->stop($job); |
||
78 | } |
||
79 | } catch (\Exception $e) { |
||
80 | // Try stop last builds |
||
81 | if (isset($job)) { |
||
82 | $serviceManager->stop($job); |
||
83 | } |
||
84 | // We do not deal with exception (Console Component do it well), |
||
85 | // we just catch it to allow cleaner to be runned even if one of the build failed hard |
||
86 | // Simulation of a finally for php < 5.6 :-° |
||
87 | } |
||
88 | |||
89 | $container->getVacuum()->clean($input->getOption("project-path"), $input->getOption("keep")); |
||
90 | |||
91 | if (isset($e)) { |
||
92 | throw $e; |
||
93 | } |
||
94 | |||
95 | return $exitCode; |
||
96 | } |
||
97 | } |
||
98 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.