Conditions | 7 |
Paths | 8 |
Total Lines | 70 |
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 |
||
41 | public function resolve($object, array $args, $context, ResolveInfo $info) |
||
42 | { |
||
43 | /** @var BaseElement $block */ |
||
44 | $block = BaseElement::get_by_id($args['ID']); |
||
45 | |||
46 | if (!$block) { |
||
47 | throw new \InvalidArgumentException(sprintf( |
||
48 | '%s#%s not found', |
||
49 | BaseElement::class, |
||
50 | $args['ID'] |
||
51 | )); |
||
52 | } |
||
53 | |||
54 | if (!$block->canEdit($context['currentUser'])) { |
||
55 | throw new \InvalidArgumentException( |
||
56 | 'Changing the sort order of blocks is not allowed' |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | $parentId = $block->ParentID; |
||
61 | $blockPosition = (int) $block->Sort; |
||
62 | |||
63 | $sortAfterPosition = 0; |
||
64 | $afterBlockID = $args['AfterBlockID']; |
||
65 | if ($afterBlockID) { |
||
66 | /** @var BaseElement $afterBlock */ |
||
67 | $afterBlock = BaseElement::get_by_id($afterBlockID); |
||
68 | |||
69 | if (!$afterBlock) { |
||
70 | throw new \InvalidArgumentException( |
||
71 | 'Trying to sort block after a block in a different elemental area' |
||
72 | ); |
||
73 | } |
||
74 | if ($afterBlock->ParentID !== $parentId) { |
||
75 | throw new \InvalidArgumentException(sprintf( |
||
76 | '%s#%s not found', |
||
77 | BaseElement::class, |
||
78 | $parentId |
||
79 | )); |
||
80 | } |
||
81 | |||
82 | $sortAfterPosition = (int) $afterBlock->Sort; |
||
83 | } |
||
84 | |||
85 | // We are updating records with SQL queries to avoid the ORM triggering the creation of new versions |
||
86 | // for each element that is affected by this reordering. |
||
87 | $tableName = Convert::raw2sql(DataObject::getSchema()->tableName(BaseElement::class)); |
||
88 | |||
89 | if ($sortAfterPosition < $blockPosition) { |
||
90 | $operator = '+'; |
||
91 | $filter = "\"$tableName\".\"Sort\" > $sortAfterPosition AND \"$tableName\".\"Sort\" < $blockPosition"; |
||
92 | $newBlockPosition = $sortAfterPosition + 1; |
||
93 | } else { |
||
94 | $operator = '-'; |
||
95 | $filter = "\"$tableName\".\"Sort\" <= $sortAfterPosition AND \"$tableName\".\"Sort\" > $blockPosition"; |
||
96 | $newBlockPosition = $sortAfterPosition; |
||
97 | } |
||
98 | |||
99 | $query = SQLUpdate::create() |
||
100 | ->setTable("\"$tableName\"") |
||
101 | ->assignSQL('"Sort"', "\"$tableName\".\"Sort\" $operator 1") |
||
102 | ->addWhere([$filter, "\"$tableName\".\"ParentID\"" => $parentId]); |
||
103 | |||
104 | $query->execute(); |
||
105 | |||
106 | // Now use the ORM to write a new version of the record that we are directly reordering |
||
107 | $block->Sort = $newBlockPosition; |
||
108 | $block->write(); |
||
109 | |||
110 | return $block; |
||
111 | } |
||
113 |
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