Replaced more ussages of AnnotatedFactory by ConfigAbstractFactory

This commit is contained in:
Alejandro Celaya
2017-07-22 13:48:30 +02:00
parent 9ef9da0870
commit b93d65ddc1
10 changed files with 34 additions and 91 deletions

View File

@@ -1,7 +1,6 @@
<?php
namespace Shlinkio\Shlink\Core\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Common\Paginator\Adapter\PaginableRepositoryAdapter;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
@@ -19,12 +18,6 @@ class ShortUrlService implements ShortUrlServiceInterface
*/
private $em;
/**
* ShortUrlService constructor.
* @param EntityManagerInterface $em
*
* @Inject({"em"})
*/
public function __construct(EntityManagerInterface $em)
{
$this->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);
}

View File

@@ -1,7 +1,6 @@
<?php
namespace Shlinkio\Shlink\Core\Service\Tag;
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Core\Entity\Tag;
@@ -18,12 +17,6 @@ class TagService implements TagServiceInterface
*/
private $em;
/**
* VisitService constructor.
* @param EntityManagerInterface $em
*
* @DI\Inject({"em"})
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;

View File

@@ -1,7 +1,6 @@
<?php
namespace Shlinkio\Shlink\Core\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\Common\Cache\Cache;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
@@ -37,15 +36,6 @@ class UrlShortener implements UrlShortenerInterface
*/
private $cache;
/**
* UrlShortener constructor.
* @param ClientInterface $httpClient
* @param EntityManagerInterface $em
* @param Cache $cache
* @param string $chars
*
* @Inject({"httpClient", "em", Cache::class, "config.url_shortener.shortcode_chars"})
*/
public function __construct(
ClientInterface $httpClient,
EntityManagerInterface $em,
@@ -112,7 +102,7 @@ class UrlShortener implements UrlShortenerInterface
* Tries to perform a GET request to provided url, returning true on success and false on failure
*
* @param UriInterface $url
* @return bool
* @return void
*/
protected function checkUrlExists(UriInterface $url)
{
@@ -133,17 +123,17 @@ class UrlShortener implements UrlShortenerInterface
*/
protected function convertAutoincrementIdToShortCode($id)
{
$id = intval($id) + 200000; // Increment the Id so that the generated shortcode is not too short
$id = ((int) $id) + 200000; // Increment the Id so that the generated shortcode is not too short
$length = strlen($this->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;
}
/**

View File

@@ -1,7 +1,6 @@
<?php
namespace Shlinkio\Shlink\Core\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Repository\VisitRepository;
@@ -13,12 +12,6 @@ class VisitService implements VisitServiceInterface
*/
private $em;
/**
* VisitService constructor.
* @param EntityManagerInterface $em
*
* @Inject({"em"})
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;

View File

@@ -1,7 +1,6 @@
<?php
namespace Shlinkio\Shlink\Core\Service;
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
@@ -17,12 +16,6 @@ class VisitsTracker implements VisitsTrackerInterface
*/
private $em;
/**
* VisitsTracker constructor.
* @param EntityManagerInterface $em
*
* @Inject({"em"})
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;