Skip to content

Add annotation with proper types for entity properties #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/AppBundle/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@
class Comment
{
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var Post
*
* @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $post;

/**
* @var string
*
* @ORM\Column(type="text")
* @Assert\NotBlank(message="comment.blank")
* @Assert\Length(
Expand All @@ -55,12 +61,16 @@ class Comment
private $content;

/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\Email()
*/
private $authorEmail;

/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
* @Assert\DateTime()
*/
Expand Down Expand Up @@ -90,6 +100,10 @@ public function getContent()
{
return $this->content;
}

/**
* @param string $content
*/
public function setContent($content)
{
$this->content = $content;
Expand All @@ -99,6 +113,10 @@ public function getAuthorEmail()
{
return $this->authorEmail;
}

/**
* @param string $authorEmail
*/
public function setAuthorEmail($authorEmail)
{
$this->authorEmail = $authorEmail;
Expand All @@ -108,6 +126,7 @@ public function getPublishedAt()
{
return $this->publishedAt;
}

public function setPublishedAt(\DateTime $publishedAt)
{
$this->publishedAt = $publishedAt;
Expand All @@ -117,6 +136,7 @@ public function getPost()
{
return $this->post;
}

public function setPost(Post $post)
{
$this->post = $post;
Expand Down
35 changes: 31 additions & 4 deletions src/AppBundle/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,65 @@ class Post
const NUM_ITEMS = 10;

/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank()
*/
private $title;

/**
* @var string
*
* @ORM\Column(type="string")
*/
private $slug;

/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank(message="post.blank_summary")
*/
private $summary;

/**
* @var string
*
* @ORM\Column(type="text")
* @Assert\NotBlank(message="post.blank_content")
* @Assert\Length(min = "10", minMessage = "post.too_short_content")
*/
private $content;

/**
* @var string
*
* @ORM\Column(type="string")
* @Assert\Email()
*/
private $authorEmail;

/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
* @Assert\DateTime()
*/
private $publishedAt;

/**
* @var Comment[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="Comment",
* mappedBy="post",
Expand All @@ -97,6 +113,9 @@ public function getTitle()
return $this->title;
}

/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
Expand All @@ -107,6 +126,9 @@ public function getSlug()
return $this->slug;
}

/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
Expand All @@ -117,6 +139,9 @@ public function getContent()
return $this->content;
}

/**
* @param string $content
*/
public function setContent($content)
{
$this->content = $content;
Expand All @@ -127,17 +152,16 @@ public function getAuthorEmail()
return $this->authorEmail;
}

/**
* @param string $authorEmail
*/
public function setAuthorEmail($authorEmail)
{
$this->authorEmail = $authorEmail;
}

/**
* Is the given User the author of this Post?
*
* @param User $user
*
* @return bool
*/
public function isAuthor(User $user)
{
Expand Down Expand Up @@ -175,6 +199,9 @@ public function getSummary()
return $this->summary;
}

/**
* @param string $summary
*/
public function setSummary($summary)
{
$this->summary = $summary;
Expand Down
34 changes: 27 additions & 7 deletions src/AppBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,38 @@
class User implements UserInterface
{
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="string", unique=true)
*/
private $username;

/**
* @var string
*
* @ORM\Column(type="string", unique=true)
*/
private $email;

/**
* @var string
*
* @ORM\Column(type="string")
*/
private $password;

/**
* @var array
*
* @ORM\Column(type="json_array")
*/
private $roles = [];
Expand All @@ -52,13 +62,14 @@ public function getId()
return $this->id;
}

/**
* {@inheritdoc}
*/
public function getUsername()
{
return $this->username;
}

/**
* @param string $username
*/
public function setUsername($username)
{
$this->username = $username;
Expand All @@ -68,18 +79,23 @@ public function getEmail()
{
return $this->email;
}

/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}

/**
* {@inheritdoc}
*/
public function getPassword()
{
return $this->password;
}

/**
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
Expand Down Expand Up @@ -107,18 +123,22 @@ public function setRoles(array $roles)

/**
* Returns the salt that was originally used to encode the password.
*
* {@inheritdoc}
*/
public function getSalt()
{
// See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
// we're using bcrypt in security.yml to encode the password, so
// the salt value is built-in and you don't have to generate one

return;
return null;
}

/**
* Removes sensitive data from the user.
*
* {@inheritdoc}
*/
public function eraseCredentials()
{
Expand Down