Issues (112)

src/HasMedia/Traits/HasMediaPropertiesTrait.php (4 issues)

1
<?php
2
3
namespace ByTIC\MediaLibrary\HasMedia\Traits;
4
5
use ByTIC\MediaLibrary\Support\MediaModels;
6
7
/**
8
 * Trait HasMediaPropertiesTrait
9
 * @package ByTIC\MediaLibrary\HasMedia\Traits
10
 */
11
trait HasMediaPropertiesTrait
12
{
13
    /**
14
     * @param $collection
15
     * @return \ByTIC\MediaLibrary\Models\MediaProperties\MediaProperty|\Nip\Records\AbstractModels\Record
16
     */
17
    public function mediaProperties($collection)
18
    {
19
        $propertiesRecord = MediaModels::properties()->for($this, $collection);
0 ignored issues
show
$this of type ByTIC\MediaLibrary\HasMe...HasMediaPropertiesTrait is incompatible with the type Nip\Records\AbstractModels\Record expected by parameter $model of ByTIC\MediaLibrary\Model...\MediaProperties::for(). ( Ignorable by Annotation )

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

19
        $propertiesRecord = MediaModels::properties()->for(/** @scrutinizer ignore-type */ $this, $collection);
Loading history...
20
        if (!is_object($propertiesRecord)) {
21
            $propertiesRecord = $this->generateMediaProperties($collection);
22
        }
23
24
        return $propertiesRecord;
25
    }
26
27
    /**
28
     * @param $collection
29
     * @return \ByTIC\MediaLibrary\Models\MediaProperties\MediaProperty
30
     */
31
    protected function generateMediaProperties($collection)
32
    {
33
        $propertiesRecord = MediaModels::properties()->createFor($this, $collection);
0 ignored issues
show
$this of type ByTIC\MediaLibrary\HasMe...HasMediaPropertiesTrait is incompatible with the type Nip\Records\AbstractModels\Record expected by parameter $model of ByTIC\MediaLibrary\Model...Properties::createFor(). ( Ignorable by Annotation )

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

33
        $propertiesRecord = MediaModels::properties()->createFor(/** @scrutinizer ignore-type */ $this, $collection);
Loading history...
34
35
        if ($this->hasRelation('MediaProperties')) {
0 ignored issues
show
It seems like hasRelation() 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
        if ($this->/** @scrutinizer ignore-call */ hasRelation('MediaProperties')) {
Loading history...
36
            $this->getRelation('MediaProperties')->getResults()->add($propertiesRecord);
0 ignored issues
show
It seems like getRelation() 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->/** @scrutinizer ignore-call */ 
37
                   getRelation('MediaProperties')->getResults()->add($propertiesRecord);
Loading history...
37
        }
38
        return $propertiesRecord;
39
    }
40
}
41