From b93d65ddc18bfbc4bf99773215cd8047b86583ec Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Jul 2017 13:48:30 +0200 Subject: [PATCH] Replaced more ussages of AnnotatedFactory by ConfigAbstractFactory --- module/Core/config/dependencies.config.php | 39 ++++++++++++++----- module/Core/src/Action/PreviewAction.php | 10 ----- module/Core/src/Action/QrCodeAction.php | 10 ----- module/Core/src/Action/RedirectAction.php | 11 ------ .../src/Middleware/QrCodeCacheMiddleware.php | 7 ---- module/Core/src/Service/ShortUrlService.php | 9 +---- module/Core/src/Service/Tag/TagService.php | 7 ---- module/Core/src/Service/UrlShortener.php | 18 ++------- module/Core/src/Service/VisitService.php | 7 ---- module/Core/src/Service/VisitsTracker.php | 7 ---- 10 files changed, 34 insertions(+), 91 deletions(-) diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 1ef7257c..a25c82fb 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -1,9 +1,13 @@ Options\AppOptionsFactory::class, // Services - Service\UrlShortener::class => AnnotatedFactory::class, - Service\VisitsTracker::class => AnnotatedFactory::class, - Service\ShortUrlService::class => AnnotatedFactory::class, - Service\VisitService::class => AnnotatedFactory::class, - Service\Tag\TagService::class => AnnotatedFactory::class, + Service\UrlShortener::class => ConfigAbstractFactory::class, + Service\VisitsTracker::class => ConfigAbstractFactory::class, + Service\ShortUrlService::class => ConfigAbstractFactory::class, + Service\VisitService::class => ConfigAbstractFactory::class, + Service\Tag\TagService::class => ConfigAbstractFactory::class, // Middleware - Action\RedirectAction::class => AnnotatedFactory::class, - Action\QrCodeAction::class => AnnotatedFactory::class, - Action\PreviewAction::class => AnnotatedFactory::class, - Middleware\QrCodeCacheMiddleware::class => AnnotatedFactory::class, + Action\RedirectAction::class => ConfigAbstractFactory::class, + Action\QrCodeAction::class => ConfigAbstractFactory::class, + Action\PreviewAction::class => ConfigAbstractFactory::class, + Middleware\QrCodeCacheMiddleware::class => ConfigAbstractFactory::class, ], ], + ConfigAbstractFactory::class => [ + // Services + Service\UrlShortener::class => ['httpClient', 'em', Cache::class, 'config.url_shortener.shortcode_chars'], + Service\VisitsTracker::class => ['em'], + Service\ShortUrlService::class => ['em'], + Service\VisitService::class => ['em'], + Service\Tag\TagService::class => ['em'], + + // Middleware + Action\RedirectAction::class => [Service\UrlShortener::class, Service\VisitsTracker::class, 'Logger_Shlink'], + Action\QrCodeAction::class => [RouterInterface::class, Service\UrlShortener::class, 'Logger_Shlink'], + Action\PreviewAction::class => [PreviewGenerator::class, Service\UrlShortener::class], + Middleware\QrCodeCacheMiddleware::class => [Cache::class], + ], + ]; diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php index 291225be..12c57435 100644 --- a/module/Core/src/Action/PreviewAction.php +++ b/module/Core/src/Action/PreviewAction.php @@ -1,16 +1,13 @@ previewGenerator = $previewGenerator; diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 3970d740..efef3400 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -1,7 +1,6 @@ cache = $cache; diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index 59c76565..c7ae94c9 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -1,7 +1,6 @@ em = $em; @@ -60,7 +53,7 @@ class ShortUrlService implements ShortUrlServiceInterface $shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([ 'shortCode' => $shortCode, ]); - if (! isset($shortUrl)) { + if ($shortUrl === null) { throw InvalidShortCodeException::fromNotFoundShortCode($shortCode); } diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 52708a39..97fdca2d 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -1,7 +1,6 @@ em = $em; diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index 9d6927bf..67e32626 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -1,7 +1,6 @@ chars); $code = ''; while ($id > 0) { // Determine the value of the next higher character in the short code and prepend it - $code = $this->chars[intval(fmod($id, $length))] . $code; + $code = $this->chars[(int) fmod($id, $length)] . $code; $id = floor($id / $length); } - return $this->chars[intval($id)] . $code; + return $this->chars[(int) $id] . $code; } /** diff --git a/module/Core/src/Service/VisitService.php b/module/Core/src/Service/VisitService.php index d8e46c31..375cc57e 100644 --- a/module/Core/src/Service/VisitService.php +++ b/module/Core/src/Service/VisitService.php @@ -1,7 +1,6 @@ em = $em; diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index 94647086..92bafa71 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -1,7 +1,6 @@ em = $em;