Conditions | 9 |
Paths | 49 |
Total Lines | 74 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
59 | protected function execute(InputInterface $input, OutputInterface $output) |
||
60 | { |
||
61 | $this->detectMagento($output, true); |
||
62 | if ($this->initMagento()) { |
||
63 | $dialog = $this->getHelperSet()->get('dialog'); |
||
64 | |||
65 | |||
66 | $email = $this->getHelperSet()->get('parameter')->askEmail($input, $output); |
||
67 | |||
68 | // Password |
||
69 | $password = $this->getHelperSet()->get('parameter')->askPassword($input, $output, 'password', false); |
||
70 | |||
71 | // Firstname |
||
72 | if (($firstname = $input->getArgument('firstname')) == null) { |
||
73 | $firstname = $dialog->ask($output, '<question>Firstname:</question>'); |
||
74 | } |
||
75 | |||
76 | // Lastname |
||
77 | if (($lastname = $input->getArgument('lastname')) == null) { |
||
78 | $lastname = $dialog->ask($output, '<question>Lastname:</question>'); |
||
79 | } |
||
80 | |||
81 | $website = $this->getHelperSet()->get('parameter')->askWebsite($input, $output); |
||
82 | |||
83 | // create new customer |
||
84 | $customer = $this->getCustomer(); |
||
85 | $customer->setWebsiteId($website->getId()); |
||
86 | $customer->loadByEmail($email); |
||
87 | |||
88 | $outputPlain = $input->getOption('format') === null; |
||
89 | |||
90 | $table = array(); |
||
91 | if (!$customer->getId()) { |
||
92 | $customer->setWebsiteId($website->getId()); |
||
93 | $customer->setEmail($email); |
||
94 | $customer->setFirstname($firstname); |
||
95 | $customer->setLastname($lastname); |
||
96 | |||
97 | try { |
||
98 | $this->appState->emulateAreaCode('frontend', function () use ($customer, $password) { |
||
99 | $this->accountManagement->createAccount( |
||
100 | $customer->getDataModel(), |
||
101 | $password |
||
102 | ); |
||
103 | }); |
||
104 | } catch (\Exception $e) { |
||
105 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
106 | } |
||
107 | |||
108 | if ($outputPlain) { |
||
109 | $output->writeln( |
||
110 | sprintf( |
||
111 | '<info>Customer <comment>%s</comment> successfully created</info>', |
||
112 | |||
113 | ) |
||
114 | ); |
||
115 | } else { |
||
116 | $table[] = array( |
||
117 | $email, $password, $firstname, $lastname, |
||
118 | ); |
||
119 | } |
||
120 | } else { |
||
121 | if ($outputPlain) { |
||
122 | $output->writeln('<error>Customer ' . $email . ' already exists</error>'); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | if (!$outputPlain) { |
||
127 | $this->getHelper('table') |
||
128 | ->setHeaders(array('email', 'password', 'firstname', 'lastname')) |
||
129 | ->renderByFormat($output, $table, $input->getOption('format')); |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 |