Conditions | 5 |
Paths | 12 |
Total Lines | 111 |
Code Lines | 70 |
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 |
||
82 | public function execute(InputInterface $input, OutputInterface $output): void |
||
83 | { |
||
84 | $commandQueue = []; |
||
85 | |||
86 | $donor = $this->readDonor($input); |
||
87 | |||
88 | $inputReader = new Helper\InputReader($input, $output, new QuestionHelper()); |
||
89 | |||
90 | $commandQueue[] = new CommandBus\UpdateName( |
||
91 | $donor, |
||
92 | $inputReader->readOptionalInput( |
||
93 | self::OPTION_NAME, |
||
94 | $donor->getName(), |
||
95 | new Validator\ValidatorCollection( |
||
96 | new Validator\StringValidator(), |
||
97 | new Validator\NotEmptyValidator() |
||
98 | ) |
||
99 | ) |
||
100 | ); |
||
101 | |||
102 | $commandQueue[] = new CommandBus\UpdatePostalAddress( |
||
103 | $donor, |
||
104 | new PostalAddress( |
||
105 | $inputReader->readOptionalInput( |
||
106 | self::OPTION_ADDRESS1, |
||
107 | $donor->getPostalAddress()->getLine1(), |
||
108 | new Validator\StringValidator() |
||
109 | ), |
||
110 | $inputReader->readOptionalInput( |
||
111 | self::OPTION_ADDRESS2, |
||
112 | $donor->getPostalAddress()->getLine2(), |
||
113 | new Validator\StringValidator() |
||
114 | ), |
||
115 | $inputReader->readOptionalInput( |
||
116 | self::OPTION_ADDRESS3, |
||
117 | $donor->getPostalAddress()->getLine3(), |
||
118 | new Validator\StringValidator() |
||
119 | ), |
||
120 | $inputReader->readOptionalInput( |
||
121 | self::OPTION_POSTAL_CODE, |
||
122 | $donor->getPostalAddress()->getPostalCode(), |
||
123 | new Validator\PostalCodeValidator() |
||
124 | ), |
||
125 | $inputReader->readOptionalInput( |
||
126 | self::OPTION_POSTAL_CITY, |
||
127 | $donor->getPostalAddress()->getPostalCity(), |
||
128 | new Validator\StringValidator() |
||
129 | ) |
||
130 | ) |
||
131 | ); |
||
132 | |||
133 | $commandQueue[] = new CommandBus\UpdateEmail( |
||
134 | $donor, |
||
135 | $inputReader->readOptionalInput(self::OPTION_EMAIL, $donor->getEmail(), new Validator\EmailValidator()) |
||
136 | ); |
||
137 | |||
138 | $commandQueue[] = new CommandBus\UpdatePhone( |
||
139 | $donor, |
||
140 | $inputReader->readOptionalInput(self::OPTION_PHONE, $donor->getPhone(), new Validator\PhoneValidator()) |
||
141 | ); |
||
142 | |||
143 | $commandQueue[] = new CommandBus\UpdateComment( |
||
144 | $donor, |
||
145 | $inputReader->readOptionalInput( |
||
146 | self::OPTION_COMMENT, |
||
147 | $donor->getComment(), |
||
148 | new Validator\StringValidator() |
||
149 | ) |
||
150 | ); |
||
151 | |||
152 | foreach ($donor->getAttributes() as $attrKey => $attrValue) { |
||
153 | $commandQueue[] = new CommandBus\UpdateAttribute( |
||
154 | $donor, |
||
155 | $attrKey, |
||
156 | $inputReader->readOptionalInput("attribute.$attrKey", $attrValue, new Validator\StringValidator()) |
||
157 | ); |
||
158 | } |
||
159 | |||
160 | /** @var array<string> */ |
||
161 | $attrKeys = $input->getOption(self::OPTION_ATTR_KEY); |
||
162 | |||
163 | /** @var array<string> */ |
||
164 | $attrValues = $input->getOption(self::OPTION_ATTR_VALUE); |
||
165 | |||
166 | for ($count = 0;; $count++) { |
||
167 | $attrKey = $inputReader->readInput( |
||
168 | '', |
||
169 | Helper\QuestionFactory::createQuestion('Add an attribute (empty to skip)', $attrKeys[$count] ?? ''), |
||
170 | new Validator\StringValidator() |
||
171 | ); |
||
172 | |||
173 | if (!$attrKey) { |
||
174 | break; |
||
175 | } |
||
176 | |||
177 | $commandQueue[] = new CommandBus\UpdateAttribute( |
||
178 | $donor, |
||
179 | $attrKey, |
||
180 | $inputReader->readInput( |
||
181 | '', |
||
182 | Helper\QuestionFactory::createQuestion('Value', $attrValues[$count] ?? ''), |
||
183 | new Validator\StringValidator() |
||
184 | ) |
||
185 | ); |
||
186 | } |
||
187 | |||
188 | foreach ($commandQueue as $command) { |
||
189 | $this->commandBus->handle($command); |
||
190 | } |
||
191 | |||
192 | $this->evaluateDryRun($input); |
||
193 | } |
||
195 |