LTreeResource::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
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\Resources;
6
7
use Illuminate\Http\Resources\Json\JsonResource;
8
use Umbrellio\LTree\Helpers\LTreeNode;
9
use Umbrellio\LTree\Interfaces\LTreeInterface;
10
11
/**
12
 * @property LTreeNode $resource
13
 */
14
abstract class LTreeResource extends JsonResource
15
{
16 1
    final public function toArray($request)
17
    {
18 1
        return array_merge($this->toTreeArray($request, $this->resource->model), [
0 ignored issues
show
Bug introduced by
It seems like $this->resource->model can also be of type Illuminate\Database\Eloquent\Model; however, parameter $model of Umbrellio\LTree\Resource...Resource::toTreeArray() does only seem to accept Umbrellio\LTree\Interfaces\LTreeInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

18
        return array_merge($this->toTreeArray($request, /** @scrutinizer ignore-type */ $this->resource->model), [
Loading history...
19 1
            'children' => static::collection($this->resource->getChildren())->toArray($request),
20 1
        ]);
21
    }
22
23
    /**
24
     * @param LTreeInterface $model
25
     */
26
    abstract protected function toTreeArray($request, $model);
27
}
28