Issues (28)

src/Document/Application.php (2 issues)

1
<?php
2
3
namespace App\Document;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
7
use Symfony\Component\Serializer\Annotation\Groups;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
/**
11
 * @MongoDB\Document(repositoryClass="App\Repositories\ApplicationRepository")
12
 */
13
class Application
14
{
15
    /**
16
     * @MongoDB\Id
17
     * @Groups({"application_default", "application_full"})
18
     */
19
    protected $id;
20
21
    /**
22
     * @MongoDB\Field(type="string")
23
     * @MongoDB\Index()
24
     *
25
     * @Groups({"application_default", "application_write", "application_full"})
26
     * @Assert\NotBlank
27
     */
28
    protected $name;
29
30
    /**
31
     * @MongoDB\Field(type="string")
32
     *
33
     * @Groups({"application_default", "application_write", "application_full"})
34
     * @Assert\NotBlank
35
     */
36
    protected $description;
37
38
    /**
39
     * @MongoDB\ReferenceMany(targetDocument="Environment", mappedBy="application", orphanRemoval=true)
40
     *
41
     * @var Environment[]
42
     */
43
    protected $environments;
44
45
    /**
46
     * @MongoDB\EmbedMany(targetDocument="Access")
47
     *
48
     * @var Access[]
49
     */
50
    protected $accesses;
51
52
    public function __construct()
53
    {
54
        $this->accesses = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type App\Document\Access[] of property $accesses.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        $this->environments = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type App\Document\Environment[] of property $environments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
    }
57
58
    public function getId(): ?string
59
    {
60
        return $this->id;
61
    }
62
63
    public function getName(): ?string
64
    {
65
        return $this->name;
66
    }
67
68
    public function setName(string $name): self
69
    {
70
        $this->name = $name;
71
72
        return $this;
73
    }
74
75
    public function getDescription(): ?string
76
    {
77
        return $this->description;
78
    }
79
80
    public function setDescription(string $description): self
81
    {
82
        $this->description = $description;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @return Environment[]
89
     */
90
    public function getEnvironments()
91
    {
92
        return $this->environments;
93
    }
94
95
    /**
96
     * @return Access[]
97
     */
98
    public function getAccesses()
99
    {
100
        return $this->accesses;
101
    }
102
103
    public function addAccess(Access $access)
104
    {
105
        $this->removeAccess($access->getUser()->getId());
106
        $this->accesses->add($access);
107
    }
108
109
    public function getAccess(string $userId)
110
    {
111
        foreach ($this->accesses as $item) {
112
            if ($item->getUser()->getId() === $userId) {
113
                return $item;
114
            }
115
        }
116
    }
117
118
    public function removeAccess(string $userId)
119
    {
120
        if ($access = $this->getAccess($userId)) {
121
            $this->accesses->removeElement($access);
122
        }
123
    }
124
}
125