From 89998a6418805f95f9dcf332be2ca87fbbb48b46 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Fri, 13 Jan 2017 01:58:52 +0300 Subject: [PATCH] New PHP 7.1 type hints for entities and repositories. --- .../PointToolsBundle/Entity/Blogs/Comment.php | 160 +++-------------- .../PointToolsBundle/Entity/Blogs/File.php | 33 +--- .../PointToolsBundle/Entity/Blogs/Post.php | 164 ++++-------------- .../PointToolsBundle/Entity/Blogs/PostTag.php | 69 ++------ .../PointToolsBundle/Entity/Blogs/Tag.php | 38 +--- .../Entity/SubscriptionEvent.php | 4 +- .../Entity/Telegram/Account.php | 15 +- .../Bundle/PointToolsBundle/Entity/User.php | 31 +--- .../Repository/Blogs/CommentRepository.php | 2 +- .../Repository/Blogs/FileRepository.php | 2 +- .../Repository/Blogs/PostRepository.php | 5 +- .../Repository/Blogs/PostTagRepository.php | 5 + .../Repository/Blogs/TagRepository.php | 9 +- .../SubscriptionEventRepository.php | 8 +- .../Repository/SubscriptionRepository.php | 10 +- .../Repository/Telegram/AccountRepository.php | 41 +---- .../Repository/UserRepository.php | 4 +- 17 files changed, 107 insertions(+), 493 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index 8aed834..c55b703 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -107,182 +107,101 @@ class Comment $this->children = new ArrayCollection(); } - /** - * Get id - * - * @return integer - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * Set createdAt - * - * @param \DateTime $createdAt - * @return Comment - */ - public function setCreatedAt($createdAt) + public function setCreatedAt(\DateTime $createdAt): self { $this->createdAt = $createdAt; return $this; } - /** - * Get createdAt - * - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): \DateTime { return $this->createdAt; } - /** - * Set text - * - * @param string $text - * @return Comment - */ - public function setText($text) + public function setText(string $text): self { $this->text = $text; return $this; } - /** - * Get text - * - * @return string - */ - public function getText() + public function getText(): string { return $this->text; } - /** - * Set isRec - * - * @param boolean $rec - * @return Comment - */ - public function setRec($rec) + public function setRec(bool $rec): self { $this->rec = $rec; return $this; } - /** - * Get isRec - * - * @return boolean - */ - public function isRec() + public function isRec(): bool { return $this->rec; } - /** - * Get isRec - * - * @return boolean - */ - public function getRec() + public function getRec(): bool { return $this->rec; } - /** - * @return Post - */ - public function getPost() + public function getPost(): Post { return $this->post; } - /** - * @param Post $post - * @return Comment - */ - public function setPost($post) + public function setPost(Post $post): self { $this->post = $post; return $this; } - /** - * Set number - * - * @param int $number - * @return Comment - */ - public function setNumber($number) + public function setNumber(int $number): self { $this->number = $number; return $this; } - /** - * Get number - * - * @return int - */ - public function getNumber() + public function getNumber(): int { return $this->number; } - /** - * @return User - */ - public function getAuthor() + public function getAuthor(): User { return $this->author; } - /** - * @param User $author - * @return Comment - */ - public function setAuthor($author) + public function setAuthor(User $author): self { $this->author = $author; return $this; } - /** - * Add files - * - * @param File $files - * @return Comment - */ - public function addFile(File $files) + public function addFile(File $files): self { $this->files[] = $files; return $this; } - /** - * Remove files - * - * @param File $files - */ - public function removeFile(File $files) + public function removeFile(File $files): void { $this->files->removeElement($files); } /** - * Get files - * * @return File[]|ArrayCollection */ public function getFiles() @@ -293,81 +212,48 @@ class Comment /** * @return Comment */ - public function getParent() + public function getParent(): ?Comment { return $this->parent; } - /** - * @param Comment $parent - * @return Comment - */ - public function setParent($parent) + public function setParent(Comment $parent): self { $this->parent = $parent; return $this; } - /** - * Set deleted - * - * @param boolean $deleted - * @return Comment - */ - public function setDeleted($deleted) + public function setDeleted(bool $deleted): self { $this->deleted = $deleted; return $this; } - /** - * Get deleted - * - * @return boolean - */ - public function getDeleted() + public function getDeleted(): bool { return $this->deleted; } - /** - * Get deleted - * - * @return boolean - */ - public function isDeleted() + public function isDeleted(): bool { return $this->deleted; } - /** - * Add children - * - * @param Comment $children - * @return Comment - */ - public function addChild(Comment $children) + public function addChild(Comment $children): self { $this->children[] = $children; return $this; } - /** - * Remove children - * - * @param Comment $children - */ - public function removeChild(Comment $children) + public function removeChild(Comment $children): void { $this->children->removeElement($children); } /** - * Get children - * * @return Comment[]|ArrayCollection */ public function getChildren() diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/File.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/File.php index ebf37de..6c1c938 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/File.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/File.php @@ -5,10 +5,8 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; use Doctrine\ORM\Mapping as ORM; /** - * File - * * @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 { @@ -29,40 +27,17 @@ class File private $remoteUrl; - public function __construct($remoteUrl = null) + public function __construct($remoteUrl) { $this->remoteUrl = $remoteUrl; } - /** - * Get id - * - * @return integer - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * Set remoteUrl - * - * @param string $remoteUrl - * @return File - */ - public function setRemoteUrl($remoteUrl) - { - $this->remoteUrl = $remoteUrl; - - return $this; - } - - /** - * Get remoteUrl - * - * @return string - */ - public function getRemoteUrl() + public function getRemoteUrl(): string { return $this->remoteUrl; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index 435d9c5..59b7821 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -7,8 +7,6 @@ use Doctrine\ORM\Mapping as ORM; use Skobkin\Bundle\PointToolsBundle\Entity\User; /** - * Post - * * @ORM\Table(name="posts", schema="posts", indexes={ * @ORM\Index(name="idx_post_created_at", columns={"created_at"}), * @ORM\Index(name="idx_post_private", columns={"private"}), @@ -18,8 +16,8 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; */ class Post { - const TYPE_POST = 'post'; - const TYPE_FEED = 'feed'; + public const TYPE_POST = 'post'; + public const TYPE_FEED = 'feed'; /** * @var string @@ -121,135 +119,77 @@ class Post /** * @ORM\PreUpdate */ - public function preUpdate() + public function preUpdate(): void { $this->updatedAt = new \DateTime(); } - /** - * Get id - * - * @return string - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * Set text - * - * @param string $text - * @return Post - */ - public function setText($text) + public function setText(string $text): self { $this->text = $text; return $this; } - /** - * Get text - * - * @return string - */ - public function getText() + public function getText(): string { return $this->text; } - /** - * Set createdAt - * - * @param \DateTime $createdAt - * @return Post - */ - public function setCreatedAt($createdAt) + public function setCreatedAt(\DateTime $createdAt): self { $this->createdAt = $createdAt; return $this; } - /** - * Get createdAt - * - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): \DateTime { return $this->createdAt; } - /** - * @return \DateTime - */ - public function getUpdatedAt() + public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; } - /** - * Set type - * - * @param string $type - * @return Post - */ - public function setType($type) + public function setType(string $type): self { $this->type = $type; return $this; } - /** - * Get type - * - * @return string - */ - public function getType() + public function getType(): string { return $this->type; } - /** - * @return User - */ - public function getAuthor() + public function getAuthor(): User { return $this->author; } - /** - * @param User $author - * @return Post - */ - public function setAuthor($author) + public function setAuthor(User $author): self { $this->author = $author; + return $this; } - /** - * Add files - * - * @param File $files - * @return Post - */ - public function addFile(File $files) + public function addFile(File $files): self { $this->files[] = $files; return $this; } - /** - * Remove files - * - * @param File $files - */ - public function removeFile(File $files) + public function removeFile(File $files): void { $this->files->removeElement($files); } @@ -264,13 +204,7 @@ class Post return $this->files; } - /** - * Add post tags - * - * @param PostTag $tag - * @return Post - */ - public function addPostTag(PostTag $tag) + public function addPostTag(PostTag $tag): self { $tag->setPost($this); $this->postTags[] = $tag; @@ -278,12 +212,7 @@ class Post return $this; } - /** - * Remove tags - * - * @param PostTag $tag - */ - public function removePostTag(PostTag $tag) + public function removePostTag(PostTag $tag): void { $this->postTags->removeElement($tag); } @@ -298,69 +227,41 @@ class Post return $this->postTags; } - /** - * Set deleted - * - * @param boolean $deleted - * @return Post - */ - public function setDeleted($deleted) + public function setDeleted(bool $deleted): self { $this->deleted = $deleted; return $this; } - /** - * Get deleted - * - * @return boolean - */ - public function getDeleted() + public function getDeleted(): bool { return $this->deleted; } - /** - * Get deleted - * - * @return boolean - */ - public function isDeleted() + public function isDeleted(): bool { return $this->deleted; } - /** - * Set private - * - * @param boolean $private - * @return Post - */ - public function setPrivate($private) + public function setPrivate(bool $private): self { $this->private = $private; return $this; } - /** - * Get private - * - * @return boolean - */ - public function getPrivate() + public function isPrivate(): bool { return $this->private; } - /** - * Add comments - * - * @param Comment $comment - * @return Post - */ - public function addComment(Comment $comment) + public function getPrivate(): bool + { + return $this->private; + } + + public function addComment(Comment $comment): self { $this->comments[] = $comment; $comment->setPost($this); @@ -368,12 +269,7 @@ class Post return $this; } - /** - * Remove comments - * - * @param Comment $comment - */ - public function removeComment(Comment $comment) + public function removeComment(Comment $comment): void { $this->comments->removeElement($comment); } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostTag.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostTag.php index 0fe61c8..1b4a76e 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostTag.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostTag.php @@ -5,15 +5,13 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; use Doctrine\ORM\Mapping as ORM; /** - * PostTag - * * @ORM\Table(name="posts_tags", schema="posts") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostTagRepository") */ class PostTag { /** - * @var integer + * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id @@ -32,6 +30,8 @@ class PostTag /** * @var Tag * + * @todo fix SET NULL + * * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EAGER") * @ORM\JoinColumn(name="tag_id", onDelete="SET NULL") */ @@ -45,53 +45,29 @@ class PostTag private $text; - /** - * PostTag constructor. - * - * @param Tag $tag - */ public function __construct(Tag $tag) { $this->tag = $tag; } - /** - * Get id - * - * @return integer - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * Set text - * - * @param string $text - * @return PostTag - */ - public function setText($text) + public function setText(string $text): self { $this->text = $text; return $this; } - /** - * Get text - * - * @return string - */ - public function getText() + public function getText(): string { return $this->text; } - /** - * @return string - */ - public function getOriginalTagText() + public function getOriginalTagText(): string { return $this->tag ? $this->tag->getText() : ''; } @@ -99,45 +75,24 @@ class PostTag /** * Set post * + * @todo move to constructor + * * @param Post $post * @return PostTag */ - public function setPost(Post $post = null) + public function setPost(Post $post = null): self { $this->post = $post; return $this; } - /** - * Get post - * - * @return Post - */ - public function getPost() + public function getPost(): Post { return $this->post; } - /** - * 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() + public function getTag(): Tag { return $this->tag; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php index e510cb6..90db241 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Tag.php @@ -5,17 +5,15 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; use Doctrine\ORM\Mapping as ORM; /** - * Tag - * * @ORM\Table(name="tags", schema="posts", indexes={ * @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 { /** - * @var integer + * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id @@ -31,43 +29,17 @@ class Tag private $text; - /** - * @param string $text - */ - public function __construct($text) + public function __construct(string $text) { $this->text = $text; } - /** - * Get id - * - * @return integer - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * Set text - * - * @param string $text - * @return Tag - */ - public function setText($text) - { - $this->text = $text; - - return $this; - } - - /** - * Get text - * - * @return string - */ - public function getText() + public function getText(): string { return $this->text; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/SubscriptionEvent.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/SubscriptionEvent.php index 82e47c8..89e2abe 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/SubscriptionEvent.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/SubscriptionEvent.php @@ -14,8 +14,8 @@ use Doctrine\ORM\Mapping as ORM; */ class SubscriptionEvent { - const ACTION_SUBSCRIBE = 'subscribe'; - const ACTION_UNSUBSCRIBE = 'unsubscribe'; + public const ACTION_SUBSCRIBE = 'subscribe'; + public const ACTION_UNSUBSCRIBE = 'unsubscribe'; /** * @var int diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Telegram/Account.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Telegram/Account.php index 247c23b..4a99ca0 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Telegram/Account.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Telegram/Account.php @@ -6,8 +6,6 @@ use Doctrine\ORM\Mapping as ORM; use Skobkin\Bundle\PointToolsBundle\Entity\User; /** - * Account - * * @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="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}), @@ -113,7 +111,7 @@ class Account /** * @ORM\PrePersist() */ - public function prePersist() + public function prePersist(): void { $this->createdAt = new \DateTime(); } @@ -121,7 +119,7 @@ class Account /** * @ORM\PreUpdate() */ - public function preUpdate() + public function preUpdate(): void { $this->updatedAt = new \DateTime(); } @@ -167,12 +165,12 @@ class Account return $this; } - public function getLastName(): string + public function getLastName(): ?string { return $this->lastName; } - public function setLastName(string $lastName = null): Account + public function setLastName(?string $lastName = null): Account { $this->lastName = $lastName; @@ -203,10 +201,7 @@ class Account return $this->chatId; } - /** - * @return User|null - */ - public function getUser() + public function getUser(): ?User { return $this->user; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php index cad66c7..c87b0a2 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php @@ -73,36 +73,22 @@ class User private $newSubscriberEvents; - /** - * @param int $id - * @param string $login - * @param string $name - */ public function __construct(int $id, string $login = null, string $name = null) { $this->id = $id; $this->login = $login; $this->name = $name; + $this->createdAt = new \DateTime(); $this->subscribers = new ArrayCollection(); $this->subscriptions = new ArrayCollection(); $this->newSubscriberEvents = new ArrayCollection(); } - /** - * @ORM\PrePersist - */ - public function onCreate() - { - if (!$this->createdAt) { - $this->createdAt = new \DateTime(); - } - } - /** * @ORM\PreUpdate */ - public function preUpdate() + public function preUpdate(): void { $this->updatedAt = new \DateTime(); } @@ -112,10 +98,6 @@ class User return $this->id; } - /** - * @param string $login - * @return User - */ public function setLogin(string $login): self { $this->login = $login; @@ -128,17 +110,14 @@ class User return $this->login; } - public function setName(string $name = null): self + public function setName(?string $name): self { $this->name = $name; return $this; } - /** - * @return string|null - */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -198,7 +177,7 @@ class User return $this; } - public function getUpdatedAt(): \DateTime + public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php index bd8318f..0b5f608 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php @@ -7,7 +7,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment; class CommentRepository extends EntityRepository { - public function add(Comment $entity) + public function add(Comment $entity): void { $this->getEntityManager()->persist($entity); } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php index 5e3ead2..cdd58b4 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php @@ -7,7 +7,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File; class FileRepository extends EntityRepository { - public function add(File $entity) + public function add(File $entity): void { $this->getEntityManager()->persist($entity); } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostRepository.php index eeae971..9921913 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostRepository.php @@ -8,18 +8,19 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post; class PostRepository extends EntityRepository { - public function add(Post $entity) + public function add(Post $entity): void { $this->getEntityManager()->persist($entity); } - public function getPostWithComments($postId) + public function getPostWithComments(string $postId): ?Post { /** @var QueryBuilder $qb */ $qb = $this->createQueryBuilder('p'); return $qb ->select(['p', 'c', 'a']) ->leftJoin('p.comments', 'c') + // @todo Optimize https://ocramius.github.io/blog/doctrine-orm-optimization-hydration/ ->leftJoin('c.author', 'a') ->where($qb->expr()->eq('p.id', ':post_id')) ->orderBy('c.number', 'asc') diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostTagRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostTagRepository.php index e134c99..59975ee 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostTagRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/PostTagRepository.php @@ -3,7 +3,12 @@ namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs; use Doctrine\ORM\EntityRepository; +use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag; class PostTagRepository extends EntityRepository { + public function add(PostTag $entity): void + { + $this->getEntityManager()->persist($entity); + } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/TagRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/TagRepository.php index 79dcc1a..18a72b9 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/TagRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/TagRepository.php @@ -7,17 +7,12 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag; class TagRepository extends EntityRepository { - public function add(Tag $entity) + public function add(Tag $entity): void { $this->getEntityManager()->persist($entity); } - /** - * @param $text - * @return Tag|null - * @throws \Doctrine\ORM\NonUniqueResultException - */ - public function findOneByLowerText($text) + public function findOneByLowerText(string $text): ?Tag { $qb = $this->createQueryBuilder('t'); return $qb diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php index c5d18d3..8c54672 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionEventRepository.php @@ -9,7 +9,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; class SubscriptionEventRepository extends EntityRepository { - public function add(SubscriptionEvent $entity) + public function add(SubscriptionEvent $entity): void { $this->getEntityManager()->persist($entity); } @@ -21,12 +21,12 @@ class SubscriptionEventRepository extends EntityRepository { $qb = $this->createQueryBuilder('se'); - $now = new \DateTime(); + $from = (new \DateTime())->sub(new \DateInterval('PT24H')); return $qb ->select('COUNT(se)') - ->where('se.date > :time') - ->setParameter('time', $now->sub(new \DateInterval('PT24H'))) + ->where('se.date > :from_time') + ->setParameter('from_time', $from) ->getQuery()->getSingleScalarResult() ; } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionRepository.php index 41d47fd..a92ced2 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/SubscriptionRepository.php @@ -8,7 +8,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; class SubscriptionRepository extends EntityRepository { - public function add(Subscription $entity) + public function add(Subscription $entity): void { $this->getEntityManager()->persist($entity); } @@ -18,12 +18,8 @@ class SubscriptionRepository extends EntityRepository * * @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'); return $qb ->select('COUNT(s.subscriber)') @@ -38,7 +34,7 @@ class SubscriptionRepository extends EntityRepository * @param User $user * @param User[] $subscribers */ - public function removeSubscribers(User $user, array $subscribers) + public function removeSubscribers(User $user, array $subscribers): void { $qb = $this->createQueryBuilder('s'); $qb diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php index cfeb05b..f470962 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php @@ -7,50 +7,11 @@ use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account; class AccountRepository extends EntityRepository { - public function add(Account $entity) + public function add(Account $entity): void { $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 * diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/UserRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/UserRepository.php index 58a2d84..8c1890a 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/UserRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/UserRepository.php @@ -15,10 +15,8 @@ class UserRepository extends EntityRepository /** * Case-insensitive user search - * - * @throws \Doctrine\ORM\NonUniqueResultException */ - public function findUserByLogin(string $login): User + public function findUserByLogin(string $login): ?User { $qb = $this->createQueryBuilder('u');