Conditions | 14 |
Paths | 2 |
Total Lines | 65 |
Code Lines | 58 |
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 |
||
89 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
90 | $userNameSubString = $input->getArgument('search-pattern'); |
||
91 | $attributes = \array_map('mb_strtolower', $input->getOption('attributes')); |
||
92 | $useKey = \count($attributes) > 1 |
||
93 | || $input->getOption('output') !== self::OUTPUT_FORMAT_PLAIN; |
||
94 | $users = $this->userManager->search($userNameSubString); |
||
95 | $users = \array_map(function(IUser $user) use ($output, $attributes, $useKey) { |
||
96 | if ($output->isVerbose()) { |
||
97 | // include all attributes |
||
98 | $row = [ |
||
99 | 'uid' => $user->getUID(), |
||
100 | 'displayName' => $user->getDisplayName(), |
||
101 | 'email' => $user->getEMailAddress(), |
||
102 | 'quota' => $user->getQuota(), |
||
103 | 'enabled' => $user->isEnabled(), |
||
104 | 'lastLogin' => $user->getLastLogin(), |
||
105 | 'home' => $user->getHome(), |
||
106 | 'backend' => $user->getBackendClassName(), |
||
107 | 'cloudId' => $user->getCloudId(), |
||
108 | 'searchTerms' => $user->getSearchTerms(), |
||
109 | ]; |
||
110 | } else { |
||
111 | // include only specified attributes |
||
112 | $row = []; |
||
113 | foreach ($attributes as $attribute) { |
||
114 | switch ($attribute) { |
||
115 | case 'uid': |
||
116 | $this->add($row, 'uid', $user->getUID(), $useKey); |
||
117 | break; |
||
118 | case 'displayname': |
||
119 | $this->add($row, 'displayName', $user->getDisplayName(), $useKey); |
||
120 | break; |
||
121 | case 'email': |
||
122 | $this->add($row, 'email', $user->getEMailAddress(), $useKey); |
||
123 | break; |
||
124 | case 'quota': |
||
125 | $this->add($row, 'quota', $user->getQuota(), $useKey); |
||
126 | break; |
||
127 | case 'enabled': |
||
128 | $this->add($row, 'enabled', $user->isEnabled(), $useKey); |
||
129 | break; |
||
130 | case 'lastlogin': |
||
131 | $this->add($row, 'lastLogin', $user->getLastLogin(), $useKey); |
||
132 | break; |
||
133 | case 'home': |
||
134 | $this->add($row, 'home', $user->getHome(), $useKey); |
||
135 | break; |
||
136 | case 'backend': |
||
137 | $this->add($row, 'backend', $user->getBackendClassName(), $useKey); |
||
138 | break; |
||
139 | case 'cloudid': |
||
140 | $this->add($row, 'cloudId', $user->getCloudId(), $useKey); |
||
141 | break; |
||
142 | case 'searchterms': |
||
143 | $this->add($row, 'searchTerms', $user->getSearchTerms(), $useKey); |
||
144 | break; |
||
145 | default: |
||
146 | throw new \UnexpectedValueException("Unknown attribute $attribute"); |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | return $row; |
||
151 | }, $users); |
||
152 | parent::writeArrayInOutputFormat($input, $output, $users, self::DEFAULT_OUTPUT_PREFIX, true); |
||
|
|||
153 | } |
||
154 | } |
||
155 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.