From 2012cc453c8efc95d4d27dc541d4c7341585bdb7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 27 Dec 2017 17:22:51 +0100 Subject: [PATCH] Fixed PHPStan errors due to API inconsistency in EntityManager and EntityManagerInterface --- module/Core/src/Service/Tag/TagService.php | 13 ++++++++----- module/Core/src/Service/VisitsTracker.php | 15 +++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 247112c8..65ae733a 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -4,8 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service\Tag; use Doctrine\Common\Collections\Collection; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Repository\TagRepository; @@ -16,11 +15,11 @@ class TagService implements TagServiceInterface use TagManagerTrait; /** - * @var EntityManager|EntityManagerInterface + * @var ORM\EntityManagerInterface */ private $em; - public function __construct(EntityManagerInterface $em) + public function __construct(ORM\EntityManagerInterface $em) { $this->em = $em; } @@ -64,6 +63,7 @@ class TagService implements TagServiceInterface * @param string $newName * @return Tag * @throws EntityDoesNotExistException + * @throws ORM\OptimisticLockException */ public function renameTag($oldName, $newName) { @@ -75,7 +75,10 @@ class TagService implements TagServiceInterface } $tag->setName($newName); - $this->em->flush($tag); + + /** @var ORM\EntityManager $em */ + $em = $this->em; + $em->flush($tag); return $tag; } diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index 6147046b..0a5cc73d 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; -use Doctrine\ORM\EntityManager; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM; use Psr\Http\Message\ServerRequestInterface; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Common\Util\DateRange; @@ -15,11 +14,11 @@ use Shlinkio\Shlink\Core\Repository\VisitRepository; class VisitsTracker implements VisitsTrackerInterface { /** - * @var EntityManager|EntityManagerInterface + * @var ORM\EntityManagerInterface */ private $em; - public function __construct(EntityManagerInterface $em) + public function __construct(ORM\EntityManagerInterface $em) { $this->em = $em; } @@ -29,6 +28,8 @@ class VisitsTracker implements VisitsTrackerInterface * * @param string $shortCode * @param ServerRequestInterface $request + * @throws ORM\ORMInvalidArgumentException + * @throws ORM\OptimisticLockException */ public function track($shortCode, ServerRequestInterface $request) { @@ -43,8 +44,10 @@ class VisitsTracker implements VisitsTrackerInterface ->setReferer($request->getHeaderLine('Referer')) ->setRemoteAddr($this->findOutRemoteAddr($request)); - $this->em->persist($visit); - $this->em->flush($visit); + /** @var ORM\EntityManager $em */ + $em = $this->em; + $em->persist($visit); + $em->flush($visit); } /**