Conditions | 7 |
Paths | 11 |
Total Lines | 53 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
44 | public function execute(InputInterface $input, OutputInterface $output) |
||
45 | { |
||
46 | $bundleName = $input->getArgument('bundle'); |
||
47 | $name = $input->getArgument('name'); |
||
48 | $fileType = $input->getOption('format'); |
||
49 | |||
50 | if ($bundleName == $this->thisBundle) { |
||
51 | throw new \InvalidArgumentException("It is not allowed to create workflows in bundle '$bundleName'"); |
||
52 | } |
||
53 | |||
54 | if (!in_array($fileType, $this->availableWorkflowFormats)) { |
||
55 | throw new \InvalidArgumentException('Unsupported workflow file format ' . $fileType); |
||
56 | } |
||
57 | |||
58 | $workflowDirectory = $this->getWorkflowDirectory($bundleName); |
||
|
|||
59 | |||
60 | if (!is_dir($workflowDirectory)) { |
||
61 | $output->writeln(sprintf( |
||
62 | "Workflows directory <info>%s</info> does not exist. I will create it now....", |
||
63 | $workflowDirectory |
||
64 | )); |
||
65 | |||
66 | if (mkdir($workflowDirectory, self::DIR_CREATE_PERMISSIONS, true)) { |
||
67 | $output->writeln(sprintf( |
||
68 | "Workflows directory <info>%s</info> has been created", |
||
69 | $workflowDirectory |
||
70 | )); |
||
71 | } else { |
||
72 | throw new FileException(sprintf( |
||
73 | "Failed to create workflows directory %s.", |
||
74 | $workflowDirectory |
||
75 | )); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | $date = date('YmdHis'); |
||
80 | |||
81 | if ($name == '') { |
||
82 | $name = 'placeholder'; |
||
83 | } |
||
84 | $fileName = $date . '_' . $name . '.' . $fileType; |
||
85 | |||
86 | $path = $workflowDirectory . '/' . $fileName; |
||
87 | |||
88 | $warning = $this->generateWorkflowFile($path, $fileType); |
||
89 | |||
90 | $output->writeln(sprintf("Generated new workflow file: <info>%s</info>", $path)); |
||
91 | |||
92 | if ($warning != '') { |
||
93 | $output->writeln("<comment>$warning</comment>"); |
||
94 | } |
||
95 | |||
96 | return 0; |
||
97 | } |
||
152 |