AbstractManager::refreshMedias()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: tetsu0o
5
 * Date: 28/12/14
6
 * Time: 15:02
7
 */
8
9
namespace Mykees\MediaBundle\Manager;
10
11
12
use Mykees\MediaBundle\Interfaces\Mediable;
13
use Mykees\MediaBundle\Util\Reflection;
14
15
abstract class AbstractManager {
16
17
    public function getModelInfos(array $datas)
18
    {
19
        $ids= [];
20
        $models = [];
21
        $model_exist = false;
22
23
        foreach( $datas as $k=>$data )
24
        {
25
            if($data instanceof Mediable)
26
            {
27
                array_push($ids,$data->getMediableId());
0 ignored issues
show
Bug introduced by
The method getMediableId() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
                if( $model_exist != $data->getMediableModel() )
0 ignored issues
show
Bug introduced by
The method getMediableModel() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
                {
30
                    array_push($models,$data->getMediableModel());
0 ignored issues
show
Bug introduced by
The method getMediableModel() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
                    $model_exist = $data->getMediableModel();
0 ignored issues
show
Bug introduced by
The method getMediableModel() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
                }
33
            }
34
        }
35
36
        return [ 'ids'=>$ids, 'models'=>$models ];
37
    }
38
39
    public function refreshMediasArray(array $medias, array $models)
40
    {
41
        $this->clean($models);
42
        foreach($models as $model)
43
        {
44
            foreach($medias as $media){
45
                if($model instanceof Mediable)
46
                {
47
                    if($model->getId() == $media->getMediableId() && $model->getMediableModel() == $media->getMediableModel())
0 ignored issues
show
Bug introduced by
The method getMediableModel() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
                    {
49
                        $model->getMedias()->add($media);
0 ignored issues
show
Bug introduced by
The method getMedias() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
                    }
51
                }
52
            }
53
        }
54
    }
55
56
    public function addMedia($media, Mediable $model)
57
    {
58
        $model->getMedias()->add($media);
0 ignored issues
show
Bug introduced by
The method getMedias() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
    }
60
61
    public function addMedias(array $medias, Mediable $model)
62
    {
63
        foreach($medias as $media){
64
            if(!empty($media) && Reflection::getClassShortName($media) == 'Media'){
65
                $this->addMedia($media,$model);
66
            }
67
        }
68
    }
69
70
    public function refreshMedias(array $medias, Mediable $model)
71
    {
72
        $model->getMedias()->clear();
0 ignored issues
show
Bug introduced by
The method getMedias() does not seem to exist on object<Mykees\MediaBundle\Interfaces\Mediable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
        $this->addMedias($medias,$model);
74
    }
75
76
    public function clean(array $models)
77
    {
78
        foreach($models as $model)
79
        {
80
            $model->getMedias()->clear();
81
        }
82
    }
83
}
84