Fixed all possible PHPStan errors

This commit is contained in:
Alejandro Celaya
2017-12-27 16:23:54 +01:00
parent 4f3995ea80
commit db956a1f40
21 changed files with 67 additions and 68 deletions

View File

@@ -49,9 +49,9 @@ class ShortUrlService implements ShortUrlServiceInterface
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function setTagsByShortCode($shortCode, array $tags = [])
public function setTagsByShortCode($shortCode, array $tags = []): ShortUrl
{
/** @var ShortUrl $shortUrl */
/** @var ShortUrl|null $shortUrl */
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([
'shortCode' => $shortCode,
]);

View File

@@ -24,5 +24,5 @@ interface ShortUrlServiceInterface
* @return ShortUrl
* @throws InvalidShortCodeException
*/
public function setTagsByShortCode($shortCode, array $tags = []);
public function setTagsByShortCode($shortCode, array $tags = []): ShortUrl;
}

View File

@@ -4,6 +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 Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
@@ -15,7 +16,7 @@ class TagService implements TagServiceInterface
use TagManagerTrait;
/**
* @var EntityManagerInterface
* @var EntityManager|EntityManagerInterface
*/
private $em;

View File

@@ -90,6 +90,7 @@ class UrlShortener implements UrlShortenerInterface
int $maxVisits = null
): string {
// If the url already exists in the database, just return its short code
/** @var ShortUrl|null $shortUrl */
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([
'originalUrl' => $url,
]);
@@ -148,6 +149,7 @@ class UrlShortener implements UrlShortenerInterface
'max' => 15,
]]);
} catch (GuzzleException $e) {
/** @var \Throwable $e */
throw InvalidUrlException::fromUrl($url, $e);
}
}
@@ -155,13 +157,13 @@ class UrlShortener implements UrlShortenerInterface
/**
* Generates the unique shortcode for an autoincrement ID
*
* @param int $id
* @param float $id
* @return string
*/
private function convertAutoincrementIdToShortCode($id): string
private function convertAutoincrementIdToShortCode(float $id): string
{
$id = ((int) $id) + 200000; // Increment the Id so that the generated shortcode is not too short
$length = strlen($this->chars);
$id += 200000; // Increment the Id so that the generated shortcode is not too short
$length = \strlen($this->chars);
$code = '';
while ($id > 0) {

View File

@@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Repository\VisitRepository;
class VisitsTracker implements VisitsTrackerInterface
{
/**
* @var EntityManagerInterface|EntityManager
* @var EntityManager|EntityManagerInterface
*/
private $em;
@@ -66,14 +66,14 @@ class VisitsTracker implements VisitsTrackerInterface
/**
* Returns the visits on certain short code
*
* @param $shortCode
* @param string $shortCode
* @param DateRange $dateRange
* @return Visit[]
* @throws InvalidArgumentException
*/
public function info($shortCode, DateRange $dateRange = null): array
public function info(string $shortCode, DateRange $dateRange = null): array
{
/** @var ShortUrl $shortUrl */
/** @var ShortUrl|null $shortUrl */
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([
'shortCode' => $shortCode,
]);

View File

@@ -21,10 +21,10 @@ interface VisitsTrackerInterface
/**
* Returns the visits on certain short code
*
* @param $shortCode
* @param string $shortCode
* @param DateRange $dateRange
* @return Visit[]
* @throws InvalidArgumentException
*/
public function info($shortCode, DateRange $dateRange = null): array;
public function info(string $shortCode, DateRange $dateRange = null): array;
}