JsonImporter::importFromJson()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MathieuTu\JsonSyncer\Traits;
4
5
use MathieuTu\JsonSyncer\Helpers\JsonImporter as ImporterHelper;
6
use MathieuTu\JsonSyncer\Helpers\RelationsInModelFinder;
7
8
trait JsonImporter
9
{
10
    protected $jsonImportableAttributes;
11
    protected $jsonImportableRelations;
12
13 15
    public static function importFromJson($objects)
14
    {
15 15
        ImporterHelper::importFromJson(new static, $objects);
0 ignored issues
show
Bug introduced by
new static() of type MathieuTu\JsonSyncer\Traits\JsonImporter is incompatible with the type MathieuTu\JsonSyncer\Contracts\JsonImportable expected by parameter $importable of MathieuTu\JsonSyncer\Hel...orter::importFromJson(). ( Ignorable by Annotation )

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

15
        ImporterHelper::importFromJson(/** @scrutinizer ignore-type */ new static, $objects);
Loading history...
16 14
    }
17
18 15
    public function getJsonImportableAttributes(): array
19
    {
20 15
        return $this->jsonImportableAttributes
21 14
            ?? $this->jsonExportableAttributes
0 ignored issues
show
Bug introduced by
The property jsonExportableAttributes does not exist on MathieuTu\JsonSyncer\Traits\JsonImporter. Did you mean jsonImportableAttributes?
Loading history...
22 15
            ?? $this->getFillable();
0 ignored issues
show
Bug introduced by
It seems like getFillable() 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

22
            ?? $this->/** @scrutinizer ignore-call */ getFillable();
Loading history...
23
    }
24
25 14
    public function getJsonImportableRelations(): array
26
    {
27 14
        return $this->jsonImportableRelations
28 14
            ?? $this->jsonExportableRelations
0 ignored issues
show
Bug introduced by
The property jsonExportableRelations does not exist on MathieuTu\JsonSyncer\Traits\JsonImporter. Did you mean jsonImportableRelations?
Loading history...
29 14
            ?? RelationsInModelFinder::hasOneOrMany($this);
0 ignored issues
show
Bug introduced by
$this of type MathieuTu\JsonSyncer\Traits\JsonImporter is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of MathieuTu\JsonSyncer\Hel...lFinder::hasOneOrMany(). ( Ignorable by Annotation )

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

29
            ?? RelationsInModelFinder::hasOneOrMany(/** @scrutinizer ignore-type */ $this);
Loading history...
30
    }
31
32 1
    public function isImporting(): bool
33
    {
34 1
        return collect(debug_backtrace())->contains('class', ImporterHelper::class);
35
    }
36
}
37