| Conditions | 9 | 
| Paths | 40 | 
| Total Lines | 51 | 
| Code Lines | 31 | 
| 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 | ||
| 54 | public function resolve($object, array $args, $context, ResolveInfo $info) | ||
| 55 |     { | ||
| 56 | $folderId = (isset($args['folderId'])) ? $args['folderId'] : 0; | ||
| 57 | |||
| 58 |         if ($folderId) { | ||
| 59 | /** @var Folder $folder */ | ||
| 60 | $folder = Versioned::get_by_stage(Folder::class, Versioned::DRAFT) | ||
| 61 | ->byID($folderId); | ||
| 62 |             if (!$folder) { | ||
| 63 | throw new \InvalidArgumentException(sprintf( | ||
| 64 | '%s#%s not found', | ||
| 65 | Folder::class, | ||
| 66 | $folderId | ||
| 67 | )); | ||
| 68 | } | ||
| 69 | |||
| 70 | // Check permission | ||
| 71 |             if (!$folder->canEdit($context['currentUser'])) { | ||
| 72 | throw new \InvalidArgumentException(sprintf( | ||
| 73 | '%s edit not allowed', | ||
| 74 | Folder::class | ||
| 75 | )); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | $files = Versioned::get_by_stage(File::class, Versioned::DRAFT) | ||
| 79 | ->byIDs($args['fileIds']); | ||
| 80 | $errorFiles = []; | ||
| 81 | |||
| 82 | /** @var File $file */ | ||
| 83 |         foreach ($files as $file) { | ||
| 84 |             if ($file->canEdit($context['currentUser'])) { | ||
| 85 | $this->accessor->setValue($file, 'ParentID', $folderId); | ||
| 86 | $file->writeToStage(Versioned::DRAFT); | ||
| 87 |             } else { | ||
| 88 | $errorFiles[] = $file->ID; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 |         if ($errorFiles) { | ||
|  | |||
| 93 | throw new \InvalidArgumentException(sprintf( | ||
| 94 | '%s (%s) edit not allowed', | ||
| 95 | File::class, | ||
| 96 |                 implode(', ', $errorFiles) | ||
| 97 | )); | ||
| 98 | } | ||
| 99 | |||
| 100 |         if (!isset($folder)) { | ||
| 101 | return Folder::singleton(); | ||
| 102 | } | ||
| 103 | return $folder; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.