Conditions | 7 |
Paths | 11 |
Total Lines | 26 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | public function calculateSortValue(ComponentPosition $componentPosition): void |
||
24 | { |
||
25 | $sortCollection = $componentPosition->getSortCollection(); |
||
26 | $sortValueSet = null !== $componentPosition->sortValue; |
||
27 | if (!$sortCollection) { |
||
28 | if (!$sortValueSet) { |
||
29 | $componentPosition->setSortValue(0); |
||
30 | } |
||
31 | |||
32 | return; |
||
33 | } |
||
34 | |||
35 | if (!$sortValueSet) { |
||
36 | /** @var ComponentPosition|null $lastPosition */ |
||
37 | $lastPosition = $sortCollection->last(); |
||
38 | if ($lastPosition) { |
||
39 | $nextValue = $lastPosition->sortValue + 1; |
||
40 | $componentPosition->setSortValue($nextValue); |
||
41 | } else { |
||
42 | $componentPosition->setSortValue(0); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | foreach ($sortCollection as $existingComponentPosition) { |
||
47 | if ($existingComponentPosition->sortValue >= $componentPosition->sortValue) { |
||
48 | ++$existingComponentPosition->sortValue; |
||
49 | } |
||
53 |