| Conditions | 7 |
| Paths | 8 |
| Total Lines | 65 |
| Code Lines | 41 |
| 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 |
||
| 36 | public function resolve($object, array $args, $context, ResolveInfo $info) |
||
| 37 | { |
||
| 38 | $block = BaseElement::get_by_id($args['ID']); |
||
| 39 | |||
| 40 | if (!$block) { |
||
| 41 | throw new \InvalidArgumentException(sprintf( |
||
| 42 | '%s#%s not found', |
||
| 43 | BaseElement::class, |
||
| 44 | $args['ID'] |
||
| 45 | )); |
||
| 46 | } |
||
| 47 | |||
| 48 | if (!$block->canEdit($context['currentUser'])) { |
||
| 49 | throw new \InvalidArgumentException( |
||
| 50 | 'Changing the sort order of blocks is not allowed' |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | |||
| 54 | $parentId = $block->ParentID; |
||
| 55 | $blockPosition = $block->Sort; |
||
| 56 | |||
| 57 | $sortAfterPosition = 0; |
||
| 58 | $afterBlockID = $args['AfterBlockID']; |
||
| 59 | if ($afterBlockID) { |
||
| 60 | $afterBlock = BaseElement::get_by_id($afterBlockID); |
||
| 61 | |||
| 62 | if (!$afterBlock) { |
||
| 63 | throw new \InvalidArgumentException( |
||
| 64 | 'Trying to sort block after a block in a different elemental area' |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | if ($afterBlock->ParentID !== $parentId) { |
||
| 68 | throw new \InvalidArgumentException(sprintf( |
||
| 69 | '%s#%s not found', |
||
| 70 | BaseElement::class, |
||
| 71 | $parentId |
||
| 72 | )); |
||
| 73 | } |
||
| 74 | |||
| 75 | $sortAfterPosition = $afterBlock->Sort; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($sortAfterPosition < $blockPosition) { |
||
| 79 | $operator = '+'; |
||
| 80 | $filter = "Sort > $sortAfterPosition && Sort < $blockPosition"; |
||
| 81 | $newBlockPosition = $sortAfterPosition + 1; |
||
| 82 | } else { |
||
| 83 | $operator = '-'; |
||
| 84 | $filter = "Sort <= $sortAfterPosition && Sort > $blockPosition"; |
||
| 85 | $newBlockPosition = $sortAfterPosition; |
||
| 86 | } |
||
| 87 | |||
| 88 | $table = DataObject::getSchema()->tableName(BaseElement::class); |
||
| 89 | |||
| 90 | $query = SQLUpdate::create() |
||
| 91 | ->setTable($table) |
||
| 92 | ->assignSQL('"' . $table . '"."Sort"', "\"$table\".\"Sort\" $operator 1") |
||
| 93 | ->addWhere([$filter, '"ParentId"' => $parentId]); |
||
| 94 | |||
| 95 | $query->execute(); |
||
| 96 | |||
| 97 | $block->Sort = $newBlockPosition; |
||
| 98 | $block->write(); |
||
| 99 | |||
| 100 | return $block; |
||
| 101 | } |
||
| 103 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths