Conditions | 11 |
Paths | 257 |
Total Lines | 85 |
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 |
||
62 | protected function execute(InputInterface $input, OutputInterface $output) |
||
63 | { |
||
64 | $this->detectMagento($output, true); |
||
65 | if (!$this->initMagento()) { |
||
66 | return 1; |
||
67 | } |
||
68 | |||
69 | $dialog = $this->getHelperSet()->get('dialog'); |
||
70 | |||
71 | |||
72 | $email = $this->getHelperSet()->get('parameter')->askEmail($input, $output); |
||
73 | |||
74 | // Password |
||
75 | if (($password = $input->getArgument('password')) == null) { |
||
|
|||
76 | $password = $dialog->askHiddenResponse($output, '<question>Password:</question>'); |
||
77 | } |
||
78 | |||
79 | // Firstname |
||
80 | if (($firstname = $input->getArgument('firstname')) == null) { |
||
81 | $firstname = $dialog->ask($output, '<question>Firstname:</question>'); |
||
82 | } |
||
83 | |||
84 | // Lastname |
||
85 | if (($lastname = $input->getArgument('lastname')) == null) { |
||
86 | $lastname = $dialog->ask($output, '<question>Lastname:</question>'); |
||
87 | } |
||
88 | |||
89 | $website = $this->getHelperSet()->get('parameter')->askWebsite($input, $output); |
||
90 | |||
91 | // create new customer |
||
92 | $customer = $this->getCustomer(); |
||
93 | $customer->setWebsiteId($website->getId()); |
||
94 | $customer->loadByEmail($email); |
||
95 | |||
96 | $outputPlain = $input->getOption('format') === null; |
||
97 | |||
98 | $table = array(); |
||
99 | $isError = false; |
||
100 | |||
101 | if (!$customer->getId()) { |
||
102 | $customer->setWebsiteId($website->getId()); |
||
103 | $customer->setEmail($email); |
||
104 | $customer->setFirstname($firstname); |
||
105 | $customer->setLastname($lastname); |
||
106 | $customer->setStoreId($website->getDefaultGroup()->getDefaultStore()->getId()); |
||
107 | |||
108 | try { |
||
109 | $this->appState->setAreaCode('frontend'); |
||
110 | $this->appState->emulateAreaCode( |
||
111 | 'frontend', |
||
112 | [$this, 'createCustomer'], |
||
113 | [$customer, $password] |
||
114 | ); |
||
115 | |||
116 | if ($outputPlain) { |
||
117 | $output->writeln( |
||
118 | sprintf( |
||
119 | '<info>Customer <comment>%s</comment> successfully created</info>', |
||
120 | |||
121 | ) |
||
122 | ); |
||
123 | } else { |
||
124 | $table[] = array( |
||
125 | $email, |
||
126 | $password, |
||
127 | $firstname, |
||
128 | $lastname, |
||
129 | ); |
||
130 | } |
||
131 | } catch (\Exception $e) { |
||
132 | $isError = true; |
||
133 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
134 | } |
||
135 | } elseif ($outputPlain) { |
||
136 | $output->writeln('<warning>Customer ' . $email . ' already exists</warning>'); |
||
137 | } |
||
138 | |||
139 | if (!$outputPlain) { |
||
140 | $this->getHelper('table') |
||
141 | ->setHeaders(array('email', 'password', 'firstname', 'lastname')) |
||
142 | ->renderByFormat($output, $table, $input->getOption('format')); |
||
143 | } |
||
144 | |||
145 | return $isError ? 1 : 0; |
||
146 | } |
||
147 | |||
175 |