diff --git a/composer.json b/composer.json index 34787bd9..1c3ea632 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,10 @@ "akrabat/ip-address-middleware": "^1.0", "cakephp/chronos": "^1.2", "cocur/slugify": "^3.0", - "doctrine/cache": "^1.6", - "doctrine/dbal": "^2.9", - "doctrine/migrations": "^2.0", - "doctrine/orm": "^2.5", + "doctrine/cache": "^1.9", + "doctrine/dbal": "^2.10", + "doctrine/migrations": "^2.2", + "doctrine/orm": "^2.7", "endroid/qr-code": "^3.6", "firebase/php-jwt": "^4.0", "geoip2/geoip2": "^2.9", diff --git a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php index 65026af0..1facba39 100644 --- a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php +++ b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php @@ -82,6 +82,6 @@ class LocateShortUrlVisit } $visit->locate(new VisitLocation($location)); - $this->em->flush($visit); + $this->em->flush(); } } diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index 1f3ea73a..02977186 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -64,9 +64,7 @@ class ShortUrlService implements ShortUrlServiceInterface $shortUrl = $this->findByShortCode($this->em, $shortCode); $shortUrl->updateMeta($shortUrlMeta); - /** @var ORM\EntityManager $em */ - $em = $this->em; - $em->flush($shortUrl); + $this->em->flush(); return $shortUrl; } diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index fd32efe5..d5ac562e 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -77,9 +77,7 @@ class TagService implements TagServiceInterface $tag->rename($newName); - /** @var ORM\EntityManager $em */ - $em = $this->em; - $em->flush($tag); + $this->em->flush(); return $tag; } diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index ebfdf778..12af69ce 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -43,10 +43,8 @@ class VisitsTracker implements VisitsTrackerInterface $visit = new Visit($shortUrl, $visitor); - /** @var ORM\EntityManager $em */ - $em = $this->em; - $em->persist($visit); - $em->flush($visit); + $this->em->persist($visit); + $this->em->flush(); $this->eventDispatcher->dispatch(new ShortUrlVisited($visit->getId())); } diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index 14318749..0b557dd8 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -61,7 +61,7 @@ class LocateShortUrlVisitTest extends TestCase ($this->locateVisit)($event); $findVisit->shouldHaveBeenCalledOnce(); - $this->em->flush(Argument::cetera())->shouldNotHaveBeenCalled(); + $this->em->flush()->shouldNotHaveBeenCalled(); $this->ipLocationResolver->resolveIpLocation(Argument::cetera())->shouldNotHaveBeenCalled(); $logWarning->shouldHaveBeenCalled(); } @@ -86,7 +86,7 @@ class LocateShortUrlVisitTest extends TestCase $findVisit->shouldHaveBeenCalledOnce(); $resolveLocation->shouldHaveBeenCalledOnce(); $logWarning->shouldHaveBeenCalled(); - $this->em->flush(Argument::cetera())->shouldNotHaveBeenCalled(); + $this->em->flush()->shouldNotHaveBeenCalled(); } /** @@ -97,7 +97,7 @@ class LocateShortUrlVisitTest extends TestCase { $event = new ShortUrlVisited('123'); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); - $flush = $this->em->flush($visit)->will(function () { + $flush = $this->em->flush()->will(function () { }); $resolveIp = $this->ipLocationResolver->resolveIpLocation(Argument::any()); @@ -128,7 +128,7 @@ class LocateShortUrlVisitTest extends TestCase $event = new ShortUrlVisited('123'); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); - $flush = $this->em->flush($visit)->will(function () { + $flush = $this->em->flush()->will(function () { }); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); @@ -151,7 +151,7 @@ class LocateShortUrlVisitTest extends TestCase $event = new ShortUrlVisited('123'); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); - $flush = $this->em->flush($visit)->will(function () { + $flush = $this->em->flush()->will(function () { }); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e); @@ -179,7 +179,7 @@ class LocateShortUrlVisitTest extends TestCase $event = new ShortUrlVisited('123'); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); - $flush = $this->em->flush($visit)->will(function () { + $flush = $this->em->flush()->will(function () { }); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e); diff --git a/module/Core/test/Service/ShortUrlServiceTest.php b/module/Core/test/Service/ShortUrlServiceTest.php index 9fd19394..07628f7c 100644 --- a/module/Core/test/Service/ShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrlServiceTest.php @@ -35,7 +35,7 @@ class ShortUrlServiceTest extends TestCase } /** @test */ - public function listedUrlsAreReturnedFromEntityManager() + public function listedUrlsAreReturnedFromEntityManager(): void { $list = [ new ShortUrl(''), @@ -54,7 +54,7 @@ class ShortUrlServiceTest extends TestCase } /** @test */ - public function exceptionIsThrownWhenSettingTagsOnInvalidShortcode() + public function exceptionIsThrownWhenSettingTagsOnInvalidShortcode(): void { $shortCode = 'abc123'; $repo = $this->prophesize(ShortUrlRepository::class); @@ -67,7 +67,7 @@ class ShortUrlServiceTest extends TestCase } /** @test */ - public function providedTagsAreGetFromRepoAndSetToTheShortUrl() + public function providedTagsAreGetFromRepoAndSetToTheShortUrl(): void { $shortUrl = $this->prophesize(ShortUrl::class); $shortUrl->setTags(Argument::any())->shouldBeCalledOnce(); @@ -86,14 +86,14 @@ class ShortUrlServiceTest extends TestCase } /** @test */ - public function updateMetadataByShortCodeUpdatesProvidedData() + public function updateMetadataByShortCodeUpdatesProvidedData(): void { $shortUrl = new ShortUrl(''); $repo = $this->prophesize(ShortUrlRepository::class); $findShortUrl = $repo->findOneBy(['shortCode' => 'abc123'])->willReturn($shortUrl); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); - $flush = $this->em->flush($shortUrl)->willReturn(null); + $flush = $this->em->flush()->willReturn(null); $result = $this->service->updateMetadataByShortCode('abc123', ShortUrlMeta::createFromParams( Chronos::parse('2017-01-01 00:00:00')->toAtomString(), diff --git a/module/Core/test/Service/Tag/TagServiceTest.php b/module/Core/test/Service/Tag/TagServiceTest.php index 7670eafd..0dd63ff5 100644 --- a/module/Core/test/Service/Tag/TagServiceTest.php +++ b/module/Core/test/Service/Tag/TagServiceTest.php @@ -28,7 +28,7 @@ class TagServiceTest extends TestCase } /** @test */ - public function listTagsDelegatesOnRepository() + public function listTagsDelegatesOnRepository(): void { $expected = [new Tag('foo'), new Tag('bar')]; @@ -44,7 +44,7 @@ class TagServiceTest extends TestCase } /** @test */ - public function deleteTagsDelegatesOnRepository() + public function deleteTagsDelegatesOnRepository(): void { $repo = $this->prophesize(TagRepository::class); $delete = $repo->deleteByName(['foo', 'bar'])->willReturn(4); @@ -57,7 +57,7 @@ class TagServiceTest extends TestCase } /** @test */ - public function createTagsPersistsEntities() + public function createTagsPersistsEntities(): void { $repo = $this->prophesize(TagRepository::class); $find = $repo->findOneBy(Argument::cetera())->willReturn(new Tag('foo')); @@ -75,7 +75,7 @@ class TagServiceTest extends TestCase } /** @test */ - public function renameInvalidTagThrowsException() + public function renameInvalidTagThrowsException(): void { $repo = $this->prophesize(TagRepository::class); $find = $repo->findOneBy(Argument::cetera())->willReturn(null); @@ -89,14 +89,14 @@ class TagServiceTest extends TestCase } /** @test */ - public function renameValidTagChangesItsName() + public function renameValidTagChangesItsName(): void { $expected = new Tag('foo'); $repo = $this->prophesize(TagRepository::class); $find = $repo->findOneBy(Argument::cetera())->willReturn($expected); $getRepo = $this->em->getRepository(Tag::class)->willReturn($repo->reveal()); - $flush = $this->em->flush($expected)->willReturn(null); + $flush = $this->em->flush()->willReturn(null); $tag = $this->service->renameTag('foo', 'bar'); diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index f137fd54..a59429fb 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -46,11 +46,11 @@ class VisitsTrackerTest extends TestCase $repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl('')); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce(); - $this->em->persist(Argument::any())->shouldBeCalledOnce(); - $this->em->flush(Argument::that(function (Visit $visit) { + $this->em->persist(Argument::that(function (Visit $visit) { $visit->setId('1'); return $visit; }))->shouldBeCalledOnce(); + $this->em->flush()->shouldBeCalledOnce(); $this->visitsTracker->track($shortCode, Visitor::emptyInstance()); @@ -69,11 +69,10 @@ class VisitsTrackerTest extends TestCase /** @var Visit $visit */ $visit = $args[0]; Assert::assertEquals('4.3.2.0', $visit->getRemoteAddr()); - })->shouldBeCalledOnce(); - $this->em->flush(Argument::that(function (Visit $visit) { $visit->setId('1'); return $visit; - }))->shouldBeCalledOnce(); + })->shouldBeCalledOnce(); + $this->em->flush()->shouldBeCalledOnce(); $this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1')); diff --git a/phpstan.neon b/phpstan.neon index 8b5db673..7df6d88f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,6 @@ parameters: ignoreErrors: - '#is not subtype of Throwable#' - - '#ObjectManager::flush()#' - '#Undefined variable: \$metadata#' - '#AbstractQuery::setParameters()#' - '#mustRun()#'