Conditions | 9 |
Paths | 16 |
Total Lines | 68 |
Code Lines | 38 |
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 |
||
78 | protected function interact(InputInterface $input, OutputInterface $output) |
||
79 | { |
||
80 | $dialog = $this->getHelperSet()->get('dialog'); |
||
81 | |||
82 | if (!$input->getArgument('id')) { |
||
83 | $id = $dialog->askAndValidate( |
||
84 | $output, |
||
85 | 'Please give an id:', |
||
86 | function ($id) { |
||
87 | if (empty($id)) { |
||
88 | throw new \InvalidArgumentException('Id cannot be empty!'); |
||
89 | } |
||
90 | |||
91 | return $id; |
||
92 | } |
||
93 | ); |
||
94 | |||
95 | $input->setArgument('id', $id); |
||
96 | } |
||
97 | |||
98 | if (!$input->getArgument('headline')) { |
||
99 | $headline = $dialog->askAndValidate( |
||
100 | $output, |
||
101 | 'Please give an headline:', |
||
102 | function ($headline) { |
||
103 | if (empty($headline)) { |
||
104 | throw new \InvalidArgumentException('Headline cannot be empty!'); |
||
105 | } |
||
106 | |||
107 | return $headline; |
||
108 | } |
||
109 | ); |
||
110 | |||
111 | $input->setArgument('headline', $headline); |
||
112 | } |
||
113 | |||
114 | if (!$input->getArgument('about')) { |
||
115 | $about = $dialog->askAndValidate( |
||
116 | $output, |
||
117 | 'Please give an about:', |
||
118 | function ($about) { |
||
119 | if (empty($about)) { |
||
120 | throw new \InvalidArgumentException('About cannot be empty!'); |
||
121 | } |
||
122 | |||
123 | return $about; |
||
124 | } |
||
125 | ); |
||
126 | |||
127 | $input->setArgument('about', $about); |
||
128 | } |
||
129 | |||
130 | if (!$input->getArgument('text')) { |
||
131 | $text = $dialog->askAndValidate( |
||
132 | $output, |
||
133 | 'Please give an text:', |
||
134 | function ($text) { |
||
135 | if (empty($text)) { |
||
136 | throw new \InvalidArgumentException('Text cannot be empty!'); |
||
137 | } |
||
138 | |||
139 | return $text; |
||
140 | } |
||
141 | ); |
||
142 | |||
143 | $input->setArgument('text', $text); |
||
144 | } |
||
145 | } |
||
146 | |||
163 |