Completed
Pull Request — master (#268)
by greg
07:26 queued 04:08
created

Mission::addMissionGame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace PlaygroundGame\Entity;
3
4
use PlaygroundGame\Entity\Game;
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
8
use Doctrine\ORM\Mapping\PrePersist;
9
use Doctrine\ORM\Mapping\PreUpdate;
10
use Zend\InputFilter\InputFilter;
11
use Zend\InputFilter\Factory as InputFactory;
12
use Zend\InputFilter\InputFilterAwareInterface;
13
use Zend\InputFilter\InputFilterInterface;
14
15
/**
16
 * @ORM\Entity @HasLifecycleCallbacks
17
 * @ORM\Table(name="game_mission")
18
 */
19
class Mission extends Game implements InputFilterAwareInterface
20
{
21
    const CLASSTYPE = 'mission';
22
    
23
    /**
24
     * @ORM\OneToMany(targetEntity="MissionGame", mappedBy="mission", cascade={"persist","remove"}, orphanRemoval=true)
25
     */
26
    protected $missionGames;
27
28
    public function __construct()
29
    {
30
        parent::__construct();
31
        $this->setClassType(self::CLASSTYPE);
32
        $this->missionGames = new ArrayCollection();
33
    }
34
35
     /**
36
     * @return the $missionGames
37
     */
38
    public function getMissionGames()
39
    {
40
        return $this->missionGames;
41
    }
42
43
    /**
44
     * @param \PlaygroundGame\Entity\ArrayCollection $missionGames
45
     */
46
    public function setMissionGames($missionGames)
47
    {
48
        $this->missionGames = $missionGames;
49
        
50
        return $this;
51
    }
52
    
53
    public function addMissionGames(ArrayCollection $missionGames)
54
    {
55
        //echo 'addMissionGames<br/>';
56
        foreach ($missionGames as $missionGame) {
57
            //echo 'uu ' . $missionGame->getId();
58
59
            $missionGame->setMission($this);
60
            $this->missionGames->add($missionGame);
61
        }
62
        //die('----fin----');
63
    }
64
    
65
    public function removeMissionGames(ArrayCollection $missionGames)
66
    {
67
        foreach ($missionGames as $missionGame) {
68
            $missionGame->setMission(null);
69
            $this->missionGames->removeElement($missionGame);
70
        }
71
    }
72
    
73
    /**
74
     * Add a game to the mission.
75
     *
76
     * @param MissionGame $missionGame
77
     *
78
     * @return void
79
     */
80
    public function addMissionGame($missionGame)
81
    {
82
        $this->missionGames[] = $missionGame;
83
    }
84
85
    /**
86
     * Convert the object to an array.
87
     *
88
     * @return array
89
     */
90
    public function getArrayCopy()
91
    {
92
        return get_object_vars($this);
93
    }
94
95
    /**
96
     * Populate from an array.
97
     *
98
     * @param array $data
99
     */
100
    public function populate($data = array())
101
    {
102
103
    }
104
105 View Code Duplication
    public function getInputFilter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        if (! $this->inputFilter) {
108
            $inputFilter = new InputFilter();
0 ignored issues
show
Unused Code introduced by
$inputFilter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
109
            $factory = new InputFactory();
110
111
            $inputFilter = parent::getInputFilter();
112
            
113
            // This definition is mandatory for the hydration to work in a form !!!!
114
            $inputFilter->add($factory->createInput(array(
115
                'name' => 'missionGames',
116
                'required' => false,
117
            )));
118
            
119
120
            $this->inputFilter = $inputFilter;
121
        }
122
    
123
        return $this->inputFilter;
124
    }
125
}
126