Issues (112)

src/Models/MediaRecords/MediaRecord.php (6 issues)

1
<?php
2
3
namespace ByTIC\MediaLibrary\Models\MediaRecords;
4
5
use ByTIC\MediaLibrary\Collections\Collection;
6
use Nip\Filesystem\File;
7
use Nip\Records\Record;
8
9
/**
10
 * Class MediaRecord
11
 * @package ByTIC\MediaLibrary\Models\MediaRecords
12
 *
13
 * @property string $model
14
 * @property int $model_id
15
 * @property int $collection_name
16
 * @property int $file_name
17
 * @property int $path
18
 * @property int $disk
19
 */
20
class MediaRecord extends Record
21
{
22
    /**
23
     * @param \Nip\Records\AbstractModels\Record $model
24
     */
25
    public function populateFromFile(File $file)
26
    {
27
        $this->file_name = $file->getName();
0 ignored issues
show
Documentation Bug introduced by
The property $file_name was declared of type integer, but $file->getName() 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
        $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...
29
    }
30
31
    /**
32
     * @param \Nip\Records\AbstractModels\Record $model
33
     */
34
    public function populateFromModel(Record $model)
35
    {
36
        $this->model = $model->getManager()->getMorphName();
0 ignored issues
show
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...
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

36
        $this->model = $model->getManager()->/** @scrutinizer ignore-call */ getMorphName();
Loading history...
37
        $this->model_id = $model->getPrimaryKey();
38
    }
39
40
    /**
41
     * @param Collection $collection
42
     */
43
    public function populateFromCollection($collection)
44
    {
45
        if (is_object($collection)) {
46
            $this->collection_name = $collection->getName();
0 ignored issues
show
Documentation Bug introduced by
The property $collection_name was declared of type integer, but $collection->getName() 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...
47
            $this->disk = $collection->getMediaFilesystemDiskName();
0 ignored issues
show
Documentation Bug introduced by
The property $disk was declared of type integer, but $collection->getMediaFilesystemDiskName() 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...
48
            return;
49
        }
50
        $this->collection_name = $collection;
51
    }
52
}
53