Test Failed
Push — master ( c9f7be...859573 )
by Gabriel
06:41
created

MediaRecord::populateFromCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace ByTIC\MediaLibrary\Models\MediaRecords;
4
5
use Nip\Filesystem\File;
6
use Nip\Records\Record;
7
8
/**
9
 * Class MediaRecord
10
 * @package ByTIC\MediaLibrary\Models\MediaRecords
11
 *
12
 * @property string $model
13
 * @property int $model_id
14
 * @property int $collection_name
15
 * @property int $file_name
16
 * @property int $path
17
 * @property int $disk
18
 */
19
class MediaRecord extends Record
20
{
21
    /**
22
     * @param \Nip\Records\AbstractModels\Record $model
23
     */
24
    public function populateFromFile(File $file)
25
    {
26
        $this->file_name = $file->getName();
27
        $this->path = $file->getPath();
0 ignored issues
show
Documentation Bug introduced by
The property $path was declared of type integer, but $file->getPath() is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
28
    }
29
30
    /**
31
     * @param \Nip\Records\AbstractModels\Record $model
32
     */
33
    public function populateFromModel(Record $model)
34
    {
35
        $this->model = $model->getManager()->getMorphName();
0 ignored issues
show
Bug introduced by
It seems like getMorphName() 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

35
        $this->model = $model->getManager()->/** @scrutinizer ignore-call */ getMorphName();
Loading history...
Documentation Bug introduced by
It seems like $model->getManager()->getMorphName() of type Nip\Records\AbstractModels\RecordManager or Nip\Records\Collections\Collection or Nip\Records\Traits\Relat...asRelationsRecordsTrait or true is incompatible with the declared type string of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        $this->model_id = $model->getPrimaryKey();
37
    }
38
39
    /**
40
     * @param $collection
41
     */
42
    public function populateFromCollection($collection)
43
    {
44
        $name = is_object($collection) ? $collection->getName() : $collection;
45
        $this->collection_name = $name;
46
    }
47
}
48