Completed
Push — master ( 43b306...d002ef )
by Jordi Sala
14s queued 11s
created

Post::getPostCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
19
class Post
20
{
21
    private $tags;
22
23
    private $postCategories;
24
25
    public function __construct()
26
    {
27
        $this->tags = new ArrayCollection();
28
        $this->postCategories = new ArrayCollection();
29
    }
30
31
    public function setTags(Collection $tags): void
32
    {
33
        $this->tags = $tags;
34
    }
35
36
    public function getTags(): Collection
37
    {
38
        return $this->tags;
39
    }
40
41
    public function addTag(Tag $tag): void
42
    {
43
        $tag->setPost($this);
44
        $this->tags->add($tag);
45
    }
46
47
    public function removeTag(Tag $tag): void
48
    {
49
        $tag->setPost(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Sonata\AdminBundl...res\Bundle\Entity\Post>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        $this->tags->removeElement($tag);
51
    }
52
53
    public function setPostCategories(Collection $postCategories): void
54
    {
55
        $this->postCategories = $postCategories;
56
    }
57
58
    public function getPostCategories(): Collection
59
    {
60
        return $this->postCategories;
61
    }
62
63
    public function addPostCategory(PostCategory $postCategory): void
64
    {
65
        $postCategory->addPost($this);
66
        $this->postCategories->add($postCategory);
67
    }
68
69
    public function removePostCategory(PostCategory $postCategory): void
70
    {
71
        $postCategory->removePost($this);
72
        $this->postCategories->removeElement($postCategory);
73
    }
74
}
75