Passed
Push — main ( 030554...fba1e4 )
by Quentin
11:01 queued 04:37
created

HandleNesting   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 33
rs 10
c 3
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setNewOrder() 0 4 1
A forNestedSlug() 0 11 3
1
<?php
2
3
namespace A17\Twill\Repositories\Behaviors;
4
5
use A17\Twill\Jobs\ReorderNestedModuleItems;
6
7
trait HandleNesting
8
{
9
    /**
10
     * The Laravel queue name to be used for the reordering operation.
11
     *
12
     * @var string
13
     */
14
    protected $reorderNestedModuleItemsJobQueue = 'default';
15
16
    /**
17
     * @param string $nestedSlug
18
     * @param array $with
19
     * @param array $withCount
20
     * @param array $scopes
21
     * @return \A17\Twill\Models\Model|null
22
     */
23
    public function forNestedSlug($nestedSlug, $with = [], $withCount = [], $scopes = [])
24
    {
25
        $targetSlug = collect(explode('/', $nestedSlug))->last();
26
27
        $targetItem = $this->forSlug($targetSlug, $with, $withCount, $scopes);
0 ignored issues
show
Bug introduced by
It seems like forSlug() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        /** @scrutinizer ignore-call */ 
28
        $targetItem = $this->forSlug($targetSlug, $with, $withCount, $scopes);
Loading history...
28
29
        if (!$targetItem || $nestedSlug !== $targetItem->nestedSlug) {
30
            return null;
31
        }
32
33
        return $targetItem;
34
    }
35
36
    public function setNewOrder($ids)
37
    {
38
        ReorderNestedModuleItems::dispatch($this->model, $ids)
39
            ->onQueue($this->reorderNestedModuleItemsJobQueue);
40
    }
41
}
42