Conditions | 15 |
Paths | 42 |
Total Lines | 113 |
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 |
||
71 | protected function execute(InputInterface $input, OutputInterface $output) |
||
72 | { |
||
73 | $this->detectMagento($output, true); |
||
74 | if (!$this->initMagento()) { |
||
75 | return; |
||
76 | } |
||
77 | |||
78 | $this->input = $input; |
||
79 | $this->output = $output; |
||
80 | /** @var DialogHelper dialog */ |
||
81 | $this->dialog = $this->getHelper('dialog'); |
||
82 | |||
83 | // Defaults |
||
84 | $range = $all = false; |
||
85 | |||
86 | $id = $this->input->getArgument('id'); |
||
87 | $range = $this->input->getOption('range'); |
||
88 | $all = $this->input->getOption('all'); |
||
89 | // Get args required |
||
90 | if (!($id) && !($range) && !($all)) { |
||
91 | |||
92 | // Delete more than one customer ? |
||
93 | $batchDelete = $this->dialog->askConfirmation( |
||
94 | $this->output, |
||
95 | $this->getQuestion('Delete more than 1 customer?', 'n'), |
||
96 | false |
||
97 | ); |
||
98 | |||
99 | if ($batchDelete) { |
||
100 | // Batch deletion |
||
101 | $all = $this->dialog->askConfirmation( |
||
102 | $this->output, |
||
103 | $this->getQuestion('Delete all customers?', 'n'), |
||
104 | false |
||
105 | ); |
||
106 | |||
107 | if (!$all) { |
||
108 | $range = $this->dialog->askConfirmation( |
||
109 | $this->output, |
||
110 | $this->getQuestion('Delete a range of customers?', 'n'), |
||
111 | false |
||
112 | ); |
||
113 | |||
114 | if (!$range) { |
||
115 | // Nothing to do |
||
116 | $this->output->writeln('<error>Finished nothing to do</error>'); |
||
117 | return false; |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | |||
123 | if (!$range && !$all) { |
||
124 | // Single customer deletion |
||
125 | if (!$id) { |
||
126 | $id = $this->dialog->ask($this->output, $this->getQuestion('Customer Id'), null); |
||
127 | } |
||
128 | |||
129 | try { |
||
130 | $customer = $this->getCustomer($id); |
||
131 | } catch (Exception $e) { |
||
132 | $this->output->writeln('<error>No customer found!</error>'); |
||
133 | return false; |
||
134 | } |
||
135 | |||
136 | if ($this->shouldRemove()) { |
||
137 | $this->deleteCustomer($customer); |
||
138 | } else { |
||
139 | $this->output->writeln('<error>Aborting delete</error>'); |
||
140 | } |
||
141 | } else { |
||
142 | $customers = $this->getCustomerCollection(); |
||
143 | $customers |
||
144 | ->addAttributeToSelect('firstname') |
||
145 | ->addAttributeToSelect('lastname') |
||
146 | ->addAttributeToSelect('email'); |
||
147 | |||
148 | if ($range) { |
||
149 | // Get Range |
||
150 | $ranges = array(); |
||
151 | $ranges[0] = $this->dialog->askAndValidate( |
||
152 | $this->output, |
||
153 | $this->getQuestion('Range start Id', '1'), |
||
154 | array($this, 'validateInt'), |
||
155 | false, |
||
156 | '1' |
||
157 | ); |
||
158 | $ranges[1] = $this->dialog->askAndValidate( |
||
159 | $this->output, |
||
160 | $this->getQuestion('Range end Id', '1'), |
||
161 | array($this, 'validateInt'), |
||
162 | false, |
||
163 | '1' |
||
164 | ); |
||
165 | |||
166 | // Ensure ascending order |
||
167 | sort($ranges); |
||
168 | |||
169 | // Range delete, takes precedence over --all |
||
170 | $customers->addAttributeToFilter('entity_id', array( |
||
171 | 'from' => $ranges[0], |
||
172 | 'to' => $ranges[1], |
||
173 | )); |
||
174 | } |
||
175 | |||
176 | if ($this->shouldRemove()) { |
||
177 | $count = $this->batchDelete($customers); |
||
178 | $this->output->writeln('<info>Successfully deleted ' . $count . ' customer/s</info>'); |
||
179 | } else { |
||
180 | $this->output->writeln('<error>Aborting delete</error>'); |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
298 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.