User::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Dummies;
4
5
/**
6
 * User dummy class for StructureResolver tests
7
 */
8
class User implements \HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib\Dummies\UserInterface
9
{
10
11
    /**
12
     * 'full_name' property
13
     * @\Symfony\Component\Validator\Constraints\NotBlank()
14
     * @\JMS\Serializer\Annotation\Type("string")
15
     * @\JMS\Serializer\Annotation\SerializedName("full_name")
16
     * @var string
17
     */
18
    private $fullName;
19
20
    /**
21
     * 'email' property
22
     * @\Symfony\Component\Validator\Constraints\Email(message = "Invalid email!")
23
     * @\JMS\Serializer\Annotation\Type("string")
24
     * @\JMS\Serializer\Annotation\SerializedName("email")
25
     * @var string
26
     */
27
    private $email;
28
29
    /**
30
     * Wether user active
31
     * @\Symfony\Component\Validator\Constraints\Type(type='boolean')
32
     * @\Symfony\Component\Validator\Constraints\IsTrue()
33
     * @\JMS\Serializer\Annotation\Type("boolean")
34
     * @\JMS\Serializer\Annotation\SerializedName("active")
35
     * @var boolean
36
     */
37
    private $active;
38
39
    /**
40
     * User new posts
41
     * @\Symfony\Component\Validator\Constraints\NotNull()
42
     * @\Symfony\Component\Validator\Constraints\Valid()
43
     * @\JMS\Serializer\Annotation\Type("Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post>")
44
     * @\JMS\Serializer\Annotation\SerializedName("new_posts")
45
     * @var \Doctrine\Common\Collections\ArrayCollection
46
     */
47
    private $newPosts;
48
49
    /**
50
     * Constructor.
51
     */
52
    public function __construct()
53
    {
54
        $this->newPosts = new \Doctrine\Common\Collections\ArrayCollection();
55
    }
56
57
    /**
58
     * For property "fullName"
59
     * @param string $fullName
60
     * @return this
61
     */
62
    public function setFullName($fullName)
63
    {
64
        $this->fullName = $fullName;
65
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\User) is incompatible with the return type declared by the interface HelloWordPl\SimpleEntity...rInterface::setFullName of type HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\this.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
66
    }
67
68
    /**
69
     * For property "fullName"
70
     * @return string
71
     */
72
    public function getFullName()
73
    {
74
        return $this->fullName;
75
    }
76
77
    /**
78
     * For property "email"
79
     * @param string $email
80
     * @return this
81
     */
82
    public function setEmail($email)
83
    {
84
        $this->email = $email;
85
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\User) is incompatible with the return type declared by the interface HelloWordPl\SimpleEntity...UserInterface::setEmail of type HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\this.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
86
    }
87
88
    /**
89
     * For property "email"
90
     * @return string
91
     */
92
    public function getEmail()
93
    {
94
        return $this->email;
95
    }
96
97
    /**
98
     * For property "active"
99
     * @return boolean
100
     */
101
    public function isActive()
102
    {
103
        return (bool) $this->active;
104
    }
105
106
    /**
107
     * For property "active"
108
     * @param boolean $active
109
     * @return this
110
     */
111
    public function setActive($active)
112
    {
113
        $this->active = $active;
114
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\User) is incompatible with the return type declared by the interface HelloWordPl\SimpleEntity...serInterface::setActive of type HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\this.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
115
    }
116
117
    /**
118
     * For property "active"
119
     * @return boolean
120
     */
121
    public function getActive()
122
    {
123
        return $this->active;
124
    }
125
126
    /**
127
     * For property "newPosts"
128
     * @param \Doctrine\Common\Collections\ArrayCollection $newPosts
129
     * @return this
130
     */
131
    public function setNewPosts(\Doctrine\Common\Collections\ArrayCollection $newPosts)
132
    {
133
        $this->newPosts = $newPosts;
134
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\User) is incompatible with the return type declared by the interface HelloWordPl\SimpleEntity...rInterface::setNewPosts of type HelloWordPl\SimpleEntity...\Tests\Lib\Dummies\this.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
135
    }
136
137
    /**
138
     * For property "newPosts"
139
     * @return \Doctrine\Common\Collections\ArrayCollection
140
     */
141
    public function getNewPosts()
142
    {
143
        return $this->newPosts;
144
    }
145
146
}
147