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

MediaProperties   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
c 1
b 0
f 1
dl 0
loc 47
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A for() 0 15 2
A createFor() 0 7 1
A generateTable() 0 3 1
1
<?php
2
3
namespace ByTIC\MediaLibrary\Models\MediaProperties;
4
5
use Nip\Records\AbstractModels\Record;
6
use Nip\Records\RecordManager;
7
8
/**
9
 * Class MediaProperties
10
 * @package ByTIC\MediaLibrary\Models\MediaRecords
11
 *
12
 * @method MediaProperty getNew()
13
 */
14
class MediaProperties extends RecordManager
15
{
16
    /**
17
     * @param Record $model
18
     * @param $collection
19
     * @return MediaProperty|Record
20
     */
21
    public function for(Record $model, $collection)
22
    {
23
        if ($model->hasRelation('MediaProperties')) {
24
            return $model->getRelation('MediaProperties')->getResults()->filter(
0 ignored issues
show
Bug introduced by
The method getResults() does not exist on Nip\Helpers\AbstractHelper. It seems like you code against a sub-type of Nip\Helpers\AbstractHelper such as Nip_Helper_Url or Nip\Helpers\View\Stylesheets or Nip\Helpers\View\Strings or Nip\Helpers\View\Paginator or Nip\Helpers\View\Arrays or Nip\Helpers\View\Icontext or Nip\Helpers\View\Color or Nip\Helpers\View\Scripts or Nip\Helpers\View\Url. ( Ignorable by Annotation )

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

24
            return $model->getRelation('MediaProperties')->/** @scrutinizer ignore-call */ getResults()->filter(
Loading history...
25
                function ($item) use ($collection) {
26
                    return $item->collection_name == $collection;
27
                }
28
            )->current();
29
        }
30
31
        return $this->findOneByParams([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->findOneByParams(a...ame=?', $collection)))) targeting Nip\Records\AbstractMode...ager::findOneByParams() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
            'where' => [
33
                ['model =?', $model->getManager()->getController()],
34
                ['model_id =?', $model->getPrimaryKey()],
35
                ['collection_name=?', $collection]
36
            ]
37
        ]);
38
    }
39
40
    /**
41
     * @param Record $model
42
     * @param $collection
43
     * @return MediaProperty
44
     */
45
    public function createFor(Record $model, $collection)
46
    {
47
        $record = $this->getNew();
48
        $record->populateFromModel($model);
49
        $record->populateFromCollection($collection);
50
        $record->insert();
51
        return $record;
52
    }
53
54
    /**
55
     * @inheritDoc
56
     * @noinspection PhpMissingParentCallCommonInspection
57
     */
58
    protected function generateTable()
59
    {
60
        return 'media-properties';
61
    }
62
}
63