Conditions | 8 |
Paths | 20 |
Total Lines | 54 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
100 | public function interact(Reader $reader, Writer $writer): void |
||
101 | { |
||
102 | parent::interact($reader, $writer); |
||
103 | |||
104 | $io = $this->io(); |
||
105 | $this->name = $io->prompt('Enter the task name', ''); |
||
106 | |||
107 | $expression = $io->prompt('Enter the cron expression', '* * * * *'); |
||
108 | while (true) { |
||
109 | try { |
||
110 | $time = Cron::parse($expression); |
||
111 | if ($time === 0) { |
||
112 | $expression = $io->prompt( |
||
113 | 'Invalid expression timestamp, please enter the cron expression', |
||
114 | '* * * * *' |
||
115 | ); |
||
116 | } else { |
||
117 | break; |
||
118 | } |
||
119 | } catch (Exception $ex) { |
||
120 | $expression = $io->prompt( |
||
121 | 'Invalid expression format, please enter the cron expression', |
||
122 | '* * * * *' |
||
123 | ); |
||
124 | } |
||
125 | } |
||
126 | $this->expression = $expression; |
||
127 | |||
128 | $properties = []; |
||
129 | |||
130 | $writer->boldYellow('Enter the properties list (empty value to finish):', true); |
||
131 | $value = ''; |
||
132 | while ($value !== null) { |
||
133 | $value = $io->prompt('Property full class name', null, null, false); |
||
134 | |||
135 | if (!empty($value)) { |
||
136 | $value = trim($value); |
||
137 | if (!class_exists($value) && !interface_exists($value)) { |
||
138 | $writer->boldWhiteBgRed(sprintf('The class [%s] does not exists', $value), true); |
||
139 | } else { |
||
140 | $shortClass = $this->getClassBaseName($value); |
||
141 | $name = Str::camel($shortClass, true); |
||
142 | //replace "interface", "abstract" |
||
143 | $nameClean = str_ireplace(['interface', 'abstract'], '', $name); |
||
144 | |||
145 | $properties[$value] = [ |
||
146 | 'name' => $nameClean, |
||
147 | 'short' => $shortClass, |
||
148 | ]; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | $this->properties = $properties; |
||
154 | } |
||
232 |