New PHP 7.1 type hints for entities and repositories.

This commit is contained in:
Alexey Skobkin 2017-01-13 01:58:52 +03:00
parent 069aa27bb4
commit 89998a6418
17 changed files with 107 additions and 493 deletions

View file

@ -107,182 +107,101 @@ class Comment
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
} }
/** public function getId(): int
* Get id
*
* @return integer
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function setCreatedAt(\DateTime $createdAt): self
* Set createdAt
*
* @param \DateTime $createdAt
* @return Comment
*/
public function setCreatedAt($createdAt)
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
/** public function getCreatedAt(): \DateTime
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{ {
return $this->createdAt; return $this->createdAt;
} }
/** public function setText(string $text): self
* Set text
*
* @param string $text
* @return Comment
*/
public function setText($text)
{ {
$this->text = $text; $this->text = $text;
return $this; return $this;
} }
/** public function getText(): string
* Get text
*
* @return string
*/
public function getText()
{ {
return $this->text; return $this->text;
} }
/** public function setRec(bool $rec): self
* Set isRec
*
* @param boolean $rec
* @return Comment
*/
public function setRec($rec)
{ {
$this->rec = $rec; $this->rec = $rec;
return $this; return $this;
} }
/** public function isRec(): bool
* Get isRec
*
* @return boolean
*/
public function isRec()
{ {
return $this->rec; return $this->rec;
} }
/** public function getRec(): bool
* Get isRec
*
* @return boolean
*/
public function getRec()
{ {
return $this->rec; return $this->rec;
} }
/** public function getPost(): Post
* @return Post
*/
public function getPost()
{ {
return $this->post; return $this->post;
} }
/** public function setPost(Post $post): self
* @param Post $post
* @return Comment
*/
public function setPost($post)
{ {
$this->post = $post; $this->post = $post;
return $this; return $this;
} }
/** public function setNumber(int $number): self
* Set number
*
* @param int $number
* @return Comment
*/
public function setNumber($number)
{ {
$this->number = $number; $this->number = $number;
return $this; return $this;
} }
/** public function getNumber(): int
* Get number
*
* @return int
*/
public function getNumber()
{ {
return $this->number; return $this->number;
} }
/** public function getAuthor(): User
* @return User
*/
public function getAuthor()
{ {
return $this->author; return $this->author;
} }
/** public function setAuthor(User $author): self
* @param User $author
* @return Comment
*/
public function setAuthor($author)
{ {
$this->author = $author; $this->author = $author;
return $this; return $this;
} }
/** public function addFile(File $files): self
* Add files
*
* @param File $files
* @return Comment
*/
public function addFile(File $files)
{ {
$this->files[] = $files; $this->files[] = $files;
return $this; return $this;
} }
/** public function removeFile(File $files): void
* Remove files
*
* @param File $files
*/
public function removeFile(File $files)
{ {
$this->files->removeElement($files); $this->files->removeElement($files);
} }
/** /**
* Get files
*
* @return File[]|ArrayCollection * @return File[]|ArrayCollection
*/ */
public function getFiles() public function getFiles()
@ -293,81 +212,48 @@ class Comment
/** /**
* @return Comment * @return Comment
*/ */
public function getParent() public function getParent(): ?Comment
{ {
return $this->parent; return $this->parent;
} }
/** public function setParent(Comment $parent): self
* @param Comment $parent
* @return Comment
*/
public function setParent($parent)
{ {
$this->parent = $parent; $this->parent = $parent;
return $this; return $this;
} }
/** public function setDeleted(bool $deleted): self
* Set deleted
*
* @param boolean $deleted
* @return Comment
*/
public function setDeleted($deleted)
{ {
$this->deleted = $deleted; $this->deleted = $deleted;
return $this; return $this;
} }
/** public function getDeleted(): bool
* Get deleted
*
* @return boolean
*/
public function getDeleted()
{ {
return $this->deleted; return $this->deleted;
} }
/** public function isDeleted(): bool
* Get deleted
*
* @return boolean
*/
public function isDeleted()
{ {
return $this->deleted; return $this->deleted;
} }
/** public function addChild(Comment $children): self
* Add children
*
* @param Comment $children
* @return Comment
*/
public function addChild(Comment $children)
{ {
$this->children[] = $children; $this->children[] = $children;
return $this; return $this;
} }
/** public function removeChild(Comment $children): void
* Remove children
*
* @param Comment $children
*/
public function removeChild(Comment $children)
{ {
$this->children->removeElement($children); $this->children->removeElement($children);
} }
/** /**
* Get children
*
* @return Comment[]|ArrayCollection * @return Comment[]|ArrayCollection
*/ */
public function getChildren() public function getChildren()

View file

@ -5,10 +5,8 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* File
*
* @ORM\Table(name="files", schema="posts") * @ORM\Table(name="files", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository", readOnly=true)
*/ */
class File class File
{ {
@ -29,40 +27,17 @@ class File
private $remoteUrl; private $remoteUrl;
public function __construct($remoteUrl = null) public function __construct($remoteUrl)
{ {
$this->remoteUrl = $remoteUrl; $this->remoteUrl = $remoteUrl;
} }
/** public function getId(): int
* Get id
*
* @return integer
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function getRemoteUrl(): string
* Set remoteUrl
*
* @param string $remoteUrl
* @return File
*/
public function setRemoteUrl($remoteUrl)
{
$this->remoteUrl = $remoteUrl;
return $this;
}
/**
* Get remoteUrl
*
* @return string
*/
public function getRemoteUrl()
{ {
return $this->remoteUrl; return $this->remoteUrl;
} }

View file

@ -7,8 +7,6 @@ use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
/** /**
* Post
*
* @ORM\Table(name="posts", schema="posts", indexes={ * @ORM\Table(name="posts", schema="posts", indexes={
* @ORM\Index(name="idx_post_created_at", columns={"created_at"}), * @ORM\Index(name="idx_post_created_at", columns={"created_at"}),
* @ORM\Index(name="idx_post_private", columns={"private"}), * @ORM\Index(name="idx_post_private", columns={"private"}),
@ -18,8 +16,8 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
*/ */
class Post class Post
{ {
const TYPE_POST = 'post'; public const TYPE_POST = 'post';
const TYPE_FEED = 'feed'; public const TYPE_FEED = 'feed';
/** /**
* @var string * @var string
@ -121,135 +119,77 @@ class Post
/** /**
* @ORM\PreUpdate * @ORM\PreUpdate
*/ */
public function preUpdate() public function preUpdate(): void
{ {
$this->updatedAt = new \DateTime(); $this->updatedAt = new \DateTime();
} }
/** public function getId(): string
* Get id
*
* @return string
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function setText(string $text): self
* Set text
*
* @param string $text
* @return Post
*/
public function setText($text)
{ {
$this->text = $text; $this->text = $text;
return $this; return $this;
} }
/** public function getText(): string
* Get text
*
* @return string
*/
public function getText()
{ {
return $this->text; return $this->text;
} }
/** public function setCreatedAt(\DateTime $createdAt): self
* Set createdAt
*
* @param \DateTime $createdAt
* @return Post
*/
public function setCreatedAt($createdAt)
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
/** public function getCreatedAt(): \DateTime
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{ {
return $this->createdAt; return $this->createdAt;
} }
/** public function getUpdatedAt(): ?\DateTime
* @return \DateTime
*/
public function getUpdatedAt()
{ {
return $this->updatedAt; return $this->updatedAt;
} }
/** public function setType(string $type): self
* Set type
*
* @param string $type
* @return Post
*/
public function setType($type)
{ {
$this->type = $type; $this->type = $type;
return $this; return $this;
} }
/** public function getType(): string
* Get type
*
* @return string
*/
public function getType()
{ {
return $this->type; return $this->type;
} }
/** public function getAuthor(): User
* @return User
*/
public function getAuthor()
{ {
return $this->author; return $this->author;
} }
/** public function setAuthor(User $author): self
* @param User $author
* @return Post
*/
public function setAuthor($author)
{ {
$this->author = $author; $this->author = $author;
return $this; return $this;
} }
/** public function addFile(File $files): self
* Add files
*
* @param File $files
* @return Post
*/
public function addFile(File $files)
{ {
$this->files[] = $files; $this->files[] = $files;
return $this; return $this;
} }
/** public function removeFile(File $files): void
* Remove files
*
* @param File $files
*/
public function removeFile(File $files)
{ {
$this->files->removeElement($files); $this->files->removeElement($files);
} }
@ -264,13 +204,7 @@ class Post
return $this->files; return $this->files;
} }
/** public function addPostTag(PostTag $tag): self
* Add post tags
*
* @param PostTag $tag
* @return Post
*/
public function addPostTag(PostTag $tag)
{ {
$tag->setPost($this); $tag->setPost($this);
$this->postTags[] = $tag; $this->postTags[] = $tag;
@ -278,12 +212,7 @@ class Post
return $this; return $this;
} }
/** public function removePostTag(PostTag $tag): void
* Remove tags
*
* @param PostTag $tag
*/
public function removePostTag(PostTag $tag)
{ {
$this->postTags->removeElement($tag); $this->postTags->removeElement($tag);
} }
@ -298,69 +227,41 @@ class Post
return $this->postTags; return $this->postTags;
} }
/** public function setDeleted(bool $deleted): self
* Set deleted
*
* @param boolean $deleted
* @return Post
*/
public function setDeleted($deleted)
{ {
$this->deleted = $deleted; $this->deleted = $deleted;
return $this; return $this;
} }
/** public function getDeleted(): bool
* Get deleted
*
* @return boolean
*/
public function getDeleted()
{ {
return $this->deleted; return $this->deleted;
} }
/** public function isDeleted(): bool
* Get deleted
*
* @return boolean
*/
public function isDeleted()
{ {
return $this->deleted; return $this->deleted;
} }
/** public function setPrivate(bool $private): self
* Set private
*
* @param boolean $private
* @return Post
*/
public function setPrivate($private)
{ {
$this->private = $private; $this->private = $private;
return $this; return $this;
} }
/** public function isPrivate(): bool
* Get private
*
* @return boolean
*/
public function getPrivate()
{ {
return $this->private; return $this->private;
} }
/** public function getPrivate(): bool
* Add comments {
* return $this->private;
* @param Comment $comment }
* @return Post
*/ public function addComment(Comment $comment): self
public function addComment(Comment $comment)
{ {
$this->comments[] = $comment; $this->comments[] = $comment;
$comment->setPost($this); $comment->setPost($this);
@ -368,12 +269,7 @@ class Post
return $this; return $this;
} }
/** public function removeComment(Comment $comment): void
* Remove comments
*
* @param Comment $comment
*/
public function removeComment(Comment $comment)
{ {
$this->comments->removeElement($comment); $this->comments->removeElement($comment);
} }

View file

@ -5,15 +5,13 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* PostTag
*
* @ORM\Table(name="posts_tags", schema="posts") * @ORM\Table(name="posts_tags", schema="posts")
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostTagRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostTagRepository")
*/ */
class PostTag class PostTag
{ {
/** /**
* @var integer * @var int
* *
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
@ -32,6 +30,8 @@ class PostTag
/** /**
* @var Tag * @var Tag
* *
* @todo fix SET NULL
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EAGER") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EAGER")
* @ORM\JoinColumn(name="tag_id", onDelete="SET NULL") * @ORM\JoinColumn(name="tag_id", onDelete="SET NULL")
*/ */
@ -45,53 +45,29 @@ class PostTag
private $text; private $text;
/**
* PostTag constructor.
*
* @param Tag $tag
*/
public function __construct(Tag $tag) public function __construct(Tag $tag)
{ {
$this->tag = $tag; $this->tag = $tag;
} }
/** public function getId(): int
* Get id
*
* @return integer
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function setText(string $text): self
* Set text
*
* @param string $text
* @return PostTag
*/
public function setText($text)
{ {
$this->text = $text; $this->text = $text;
return $this; return $this;
} }
/** public function getText(): string
* Get text
*
* @return string
*/
public function getText()
{ {
return $this->text; return $this->text;
} }
/** public function getOriginalTagText(): string
* @return string
*/
public function getOriginalTagText()
{ {
return $this->tag ? $this->tag->getText() : ''; return $this->tag ? $this->tag->getText() : '';
} }
@ -99,45 +75,24 @@ class PostTag
/** /**
* Set post * Set post
* *
* @todo move to constructor
*
* @param Post $post * @param Post $post
* @return PostTag * @return PostTag
*/ */
public function setPost(Post $post = null) public function setPost(Post $post = null): self
{ {
$this->post = $post; $this->post = $post;
return $this; return $this;
} }
/** public function getPost(): Post
* Get post
*
* @return Post
*/
public function getPost()
{ {
return $this->post; return $this->post;
} }
/** public function getTag(): Tag
* Set tag
*
* @param Tag $tag
* @return PostTag
*/
public function setTag(Tag $tag = null)
{
$this->tag = $tag;
return $this;
}
/**
* Get tag
*
* @return Tag
*/
public function getTag()
{ {
return $this->tag; return $this->tag;
} }

View file

@ -5,17 +5,15 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Tag
*
* @ORM\Table(name="tags", schema="posts", indexes={ * @ORM\Table(name="tags", schema="posts", indexes={
* @ORM\Index(name="idx_tag_text", columns={"text"}) * @ORM\Index(name="idx_tag_text", columns={"text"})
* }) * })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository", readOnly=true)
*/ */
class Tag class Tag
{ {
/** /**
* @var integer * @var int
* *
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
@ -31,43 +29,17 @@ class Tag
private $text; private $text;
/** public function __construct(string $text)
* @param string $text
*/
public function __construct($text)
{ {
$this->text = $text; $this->text = $text;
} }
/** public function getId(): int
* Get id
*
* @return integer
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function getText(): string
* Set text
*
* @param string $text
* @return Tag
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text
*
* @return string
*/
public function getText()
{ {
return $this->text; return $this->text;
} }

View file

@ -14,8 +14,8 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class SubscriptionEvent class SubscriptionEvent
{ {
const ACTION_SUBSCRIBE = 'subscribe'; public const ACTION_SUBSCRIBE = 'subscribe';
const ACTION_UNSUBSCRIBE = 'unsubscribe'; public const ACTION_UNSUBSCRIBE = 'unsubscribe';
/** /**
* @var int * @var int

View file

@ -6,8 +6,6 @@ use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
/** /**
* Account
*
* @ORM\Table(name="telegram_accounts", schema="users", indexes={ * @ORM\Table(name="telegram_accounts", schema="users", indexes={
* @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}), * @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}),
* @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}), * @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}),
@ -113,7 +111,7 @@ class Account
/** /**
* @ORM\PrePersist() * @ORM\PrePersist()
*/ */
public function prePersist() public function prePersist(): void
{ {
$this->createdAt = new \DateTime(); $this->createdAt = new \DateTime();
} }
@ -121,7 +119,7 @@ class Account
/** /**
* @ORM\PreUpdate() * @ORM\PreUpdate()
*/ */
public function preUpdate() public function preUpdate(): void
{ {
$this->updatedAt = new \DateTime(); $this->updatedAt = new \DateTime();
} }
@ -167,12 +165,12 @@ class Account
return $this; return $this;
} }
public function getLastName(): string public function getLastName(): ?string
{ {
return $this->lastName; return $this->lastName;
} }
public function setLastName(string $lastName = null): Account public function setLastName(?string $lastName = null): Account
{ {
$this->lastName = $lastName; $this->lastName = $lastName;
@ -203,10 +201,7 @@ class Account
return $this->chatId; return $this->chatId;
} }
/** public function getUser(): ?User
* @return User|null
*/
public function getUser()
{ {
return $this->user; return $this->user;
} }

View file

@ -73,36 +73,22 @@ class User
private $newSubscriberEvents; private $newSubscriberEvents;
/**
* @param int $id
* @param string $login
* @param string $name
*/
public function __construct(int $id, string $login = null, string $name = null) public function __construct(int $id, string $login = null, string $name = null)
{ {
$this->id = $id; $this->id = $id;
$this->login = $login; $this->login = $login;
$this->name = $name; $this->name = $name;
$this->createdAt = new \DateTime();
$this->subscribers = new ArrayCollection(); $this->subscribers = new ArrayCollection();
$this->subscriptions = new ArrayCollection(); $this->subscriptions = new ArrayCollection();
$this->newSubscriberEvents = new ArrayCollection(); $this->newSubscriberEvents = new ArrayCollection();
} }
/**
* @ORM\PrePersist
*/
public function onCreate()
{
if (!$this->createdAt) {
$this->createdAt = new \DateTime();
}
}
/** /**
* @ORM\PreUpdate * @ORM\PreUpdate
*/ */
public function preUpdate() public function preUpdate(): void
{ {
$this->updatedAt = new \DateTime(); $this->updatedAt = new \DateTime();
} }
@ -112,10 +98,6 @@ class User
return $this->id; return $this->id;
} }
/**
* @param string $login
* @return User
*/
public function setLogin(string $login): self public function setLogin(string $login): self
{ {
$this->login = $login; $this->login = $login;
@ -128,17 +110,14 @@ class User
return $this->login; return $this->login;
} }
public function setName(string $name = null): self public function setName(?string $name): self
{ {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }
/** public function getName(): ?string
* @return string|null
*/
public function getName()
{ {
return $this->name; return $this->name;
} }
@ -198,7 +177,7 @@ class User
return $this; return $this;
} }
public function getUpdatedAt(): \DateTime public function getUpdatedAt(): ?\DateTime
{ {
return $this->updatedAt; return $this->updatedAt;
} }

View file

@ -7,7 +7,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
class CommentRepository extends EntityRepository class CommentRepository extends EntityRepository
{ {
public function add(Comment $entity) public function add(Comment $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }

View file

@ -7,7 +7,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File;
class FileRepository extends EntityRepository class FileRepository extends EntityRepository
{ {
public function add(File $entity) public function add(File $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }

View file

@ -8,18 +8,19 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
class PostRepository extends EntityRepository class PostRepository extends EntityRepository
{ {
public function add(Post $entity) public function add(Post $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }
public function getPostWithComments($postId) public function getPostWithComments(string $postId): ?Post
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilder $qb */
$qb = $this->createQueryBuilder('p'); $qb = $this->createQueryBuilder('p');
return $qb return $qb
->select(['p', 'c', 'a']) ->select(['p', 'c', 'a'])
->leftJoin('p.comments', 'c') ->leftJoin('p.comments', 'c')
// @todo Optimize https://ocramius.github.io/blog/doctrine-orm-optimization-hydration/
->leftJoin('c.author', 'a') ->leftJoin('c.author', 'a')
->where($qb->expr()->eq('p.id', ':post_id')) ->where($qb->expr()->eq('p.id', ':post_id'))
->orderBy('c.number', 'asc') ->orderBy('c.number', 'asc')

View file

@ -3,7 +3,12 @@
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag;
class PostTagRepository extends EntityRepository class PostTagRepository extends EntityRepository
{ {
public function add(PostTag $entity): void
{
$this->getEntityManager()->persist($entity);
}
} }

View file

@ -7,17 +7,12 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag;
class TagRepository extends EntityRepository class TagRepository extends EntityRepository
{ {
public function add(Tag $entity) public function add(Tag $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }
/** public function findOneByLowerText(string $text): ?Tag
* @param $text
* @return Tag|null
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByLowerText($text)
{ {
$qb = $this->createQueryBuilder('t'); $qb = $this->createQueryBuilder('t');
return $qb return $qb

View file

@ -9,7 +9,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
class SubscriptionEventRepository extends EntityRepository class SubscriptionEventRepository extends EntityRepository
{ {
public function add(SubscriptionEvent $entity) public function add(SubscriptionEvent $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }
@ -21,12 +21,12 @@ class SubscriptionEventRepository extends EntityRepository
{ {
$qb = $this->createQueryBuilder('se'); $qb = $this->createQueryBuilder('se');
$now = new \DateTime(); $from = (new \DateTime())->sub(new \DateInterval('PT24H'));
return $qb return $qb
->select('COUNT(se)') ->select('COUNT(se)')
->where('se.date > :time') ->where('se.date > :from_time')
->setParameter('time', $now->sub(new \DateInterval('PT24H'))) ->setParameter('from_time', $from)
->getQuery()->getSingleScalarResult() ->getQuery()->getSingleScalarResult()
; ;
} }

View file

@ -8,7 +8,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
class SubscriptionRepository extends EntityRepository class SubscriptionRepository extends EntityRepository
{ {
public function add(Subscription $entity) public function add(Subscription $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }
@ -18,12 +18,8 @@ class SubscriptionRepository extends EntityRepository
* *
* @return int * @return int
*/ */
public function getUserSubscribersCountById($id): int public function getUserSubscribersCountById(int $id): int
{ {
if (!is_int($id)) {
throw new \InvalidArgumentException('$id must be an integer');
}
$qb = $this->createQueryBuilder('s'); $qb = $this->createQueryBuilder('s');
return $qb return $qb
->select('COUNT(s.subscriber)') ->select('COUNT(s.subscriber)')
@ -38,7 +34,7 @@ class SubscriptionRepository extends EntityRepository
* @param User $user * @param User $user
* @param User[] $subscribers * @param User[] $subscribers
*/ */
public function removeSubscribers(User $user, array $subscribers) public function removeSubscribers(User $user, array $subscribers): void
{ {
$qb = $this->createQueryBuilder('s'); $qb = $this->createQueryBuilder('s');
$qb $qb

View file

@ -7,50 +7,11 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account;
class AccountRepository extends EntityRepository class AccountRepository extends EntityRepository
{ {
public function add(Account $entity) public function add(Account $entity): void
{ {
$this->getEntityManager()->persist($entity); $this->getEntityManager()->persist($entity);
} }
/**
* @todo remove if not used
*
* @param array $criteria
* @param array|null $orderBy
* @param int|null $limit
* @param int|null $offset
*
* @return Account[]
*/
public function findLinkedAccountsBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
$qb = $this->createQueryBuilder('a');
$i = 0;
foreach ($criteria as $property => $value) {
$qb
->andWhere('a.'.$property.' = :criteria_'.$i)
->setParameter('criteria_'.$i, $value)
;
}
if (null !== $orderBy) {
foreach ($orderBy as $property => $order) {
$qb->addOrderBy($property, $order);
}
}
if (null !== $limit) {
$qb->setMaxResults($limit);
}
if (null !== $offset) {
$qb->setFirstResult($offset);
}
return $qb->getQuery()->getResult();
}
/** /**
* Returns total number of accounts * Returns total number of accounts
* *

View file

@ -15,10 +15,8 @@ class UserRepository extends EntityRepository
/** /**
* Case-insensitive user search * Case-insensitive user search
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/ */
public function findUserByLogin(string $login): User public function findUserByLogin(string $login): ?User
{ {
$qb = $this->createQueryBuilder('u'); $qb = $this->createQueryBuilder('u');