| Conditions | 12 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 57 |
| 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 |
||
| 120 | protected function getAttributes(NodeInterface $node, array $attributes): array |
||
| 121 | { |
||
| 122 | $acl = $this->acl; |
||
| 123 | $server = $this->server; |
||
| 124 | $fs = $this->server->getFilesystem(); |
||
| 125 | $decorator = $this->role_decorator; |
||
| 126 | |||
| 127 | return [ |
||
| 128 | 'id' => (string) $attributes['_id'], |
||
| 129 | 'name' => (string) $attributes['name'], |
||
| 130 | 'mime' => (string) $attributes['mime'], |
||
| 131 | 'readonly' => (bool) $attributes['readonly'], |
||
| 132 | 'directory' => $node instanceof Collection, |
||
| 133 | 'meta' => function ($node) { |
||
| 134 | return (object) $node->getMetaAttributes(); |
||
| 135 | }, |
||
| 136 | 'size' => function ($node) { |
||
| 137 | return $node->getSize(); |
||
| 138 | }, |
||
| 139 | 'path' => function ($node) { |
||
| 140 | try { |
||
| 141 | return $node->getPath(); |
||
| 142 | } catch (\Exception $e) { |
||
| 143 | return null; |
||
| 144 | } |
||
| 145 | }, |
||
| 146 | 'parent' => function ($node) { |
||
| 147 | $parent = $node->getParent(); |
||
| 148 | |||
| 149 | if (null === $parent || $parent->isRoot()) { |
||
| 150 | return null; |
||
| 151 | } |
||
| 152 | |||
| 153 | return $this->decorate($node->getParent(), ['id', 'name', '_links']); |
||
| 154 | }, |
||
| 155 | 'access' => function ($node) use ($acl) { |
||
| 156 | return $acl->getAclPrivilege($node); |
||
| 157 | }, |
||
| 158 | 'share' => function ($node) { |
||
| 159 | if ($node->isShared() || !$node->isSpecial()) { |
||
| 160 | return null; |
||
| 161 | } |
||
| 162 | |||
| 163 | try { |
||
| 164 | return $this->decorate($node->getShareNode(), ['id', 'name', '_links']); |
||
| 165 | } catch (\Exception $e) { |
||
| 166 | return null; |
||
| 167 | } |
||
| 168 | }, |
||
| 169 | 'sharename' => function ($node) { |
||
| 170 | if (!$node->isShared()) { |
||
| 171 | return null; |
||
| 172 | } |
||
| 173 | |||
| 174 | try { |
||
| 175 | return $node->getShareName(); |
||
| 176 | } catch (\Exception $e) { |
||
| 177 | return null; |
||
| 178 | } |
||
| 179 | }, |
||
| 180 | 'shareowner' => function ($node) use ($server, $fs, $decorator) { |
||
| 181 | if (!$node->isSpecial()) { |
||
| 182 | return null; |
||
| 183 | } |
||
| 184 | |||
| 185 | try { |
||
| 186 | return $decorator->decorate( |
||
| 187 | $server->getUserById($fs->findRawNode($node->getShareId())['owner']), |
||
| 188 | ['id', 'name', '_links'] |
||
| 189 | ); |
||
| 190 | } catch (\Exception $e) { |
||
| 191 | return null; |
||
| 192 | } |
||
| 193 | }, |
||
| 194 | 'owner' => function ($node) use ($server, $decorator) { |
||
| 195 | try { |
||
| 196 | return $decorator->decorate( |
||
| 197 | $server->getUserById($node->getOwner()), |
||
| 198 | ['id', 'name', '_links'] |
||
| 199 | ); |
||
| 200 | } catch (\Exception $e) { |
||
| 201 | return null; |
||
| 202 | } |
||
| 203 | }, |
||
| 204 | ]; |
||
| 205 | } |
||
| 206 | |||
| 301 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.