Passed
Push — master ( 859573...a81ea2 )
by Gabriel
03:21
created

HasMediaPropertiesTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 28
ccs 0
cts 10
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateMediaProperties() 0 8 2
A mediaProperties() 0 8 2
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
Bug introduced by
$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
Bug introduced by
$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
Bug introduced by
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
Bug introduced by
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
}