LTreeService::dropDescendants()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\LTree\Services;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Umbrellio\LTree\Helpers\LTreeHelper;
9
use Umbrellio\LTree\Interfaces\LTreeModelInterface;
10
use Umbrellio\LTree\Interfaces\LTreeServiceInterface;
11
12
final class LTreeService implements LTreeServiceInterface
13
{
14
    private $helper;
15
16 43
    public function __construct(LTreeHelper $helper)
17
    {
18 43
        $this->helper = $helper;
19
    }
20
21 1
    public function createPath(LTreeModelInterface $model): void
22
    {
23 1
        $this->helper->buildPath($model);
24
    }
25
26
    /**
27
     * @param LTreeModelInterface|Model $model
28
     */
29 2
    public function updatePath(LTreeModelInterface $model): void
30
    {
31 2
        $columns = array_intersect_key($model->getAttributes(), array_flip($model->getLtreeProxyUpdateColumns()));
0 ignored issues
show
Bug introduced by
The method getAttributes() does not exist on Umbrellio\LTree\Interfaces\LTreeModelInterface. ( Ignorable by Annotation )

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

31
        $columns = array_intersect_key($model->/** @scrutinizer ignore-call */ getAttributes(), array_flip($model->getLtreeProxyUpdateColumns()));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33 2
        $this->helper->moveNode($model, $model->ltreeParent, $columns);
0 ignored issues
show
Bug introduced by
Accessing ltreeParent on the interface Umbrellio\LTree\Interfaces\LTreeModelInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
34 2
        $this->helper->buildPath($model);
35
    }
36
37
    /**
38
     * @param LTreeModelInterface|Model $model
39
     */
40 1
    public function dropDescendants(LTreeModelInterface $model): void
41
    {
42 1
        $columns = array_intersect_key($model->getAttributes(), array_flip($model->getLtreeProxyDeleteColumns()));
43
44 1
        $this->helper->dropDescendants($model, $columns);
45
    }
46
}
47