Replaced all FQ global function and constants by explicit imports

This commit is contained in:
Alejandro Celaya
2018-10-28 08:24:06 +01:00
parent e1222de05b
commit 77d810b735
70 changed files with 235 additions and 123 deletions

View File

@@ -16,6 +16,7 @@ use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Options\AppOptions;
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
use function array_key_exists;
abstract class AbstractTrackingAction implements MiddlewareInterface
{
@@ -69,7 +70,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface
$url = $this->urlShortener->shortCodeToUrl($shortCode);
// Track visit to this short code
if ($disableTrackParam === null || ! \array_key_exists($disableTrackParam, $query)) {
if ($disableTrackParam === null || ! array_key_exists($disableTrackParam, $query)) {
$this->visitTracker->track($shortCode, Visitor::fromRequest($request));
}

View File

@@ -9,6 +9,7 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
use function count;
/**
* Class ShortUrl
@@ -176,7 +177,7 @@ class ShortUrl extends AbstractEntity
public function getVisitsCount(): int
{
return \count($this->visits);
return count($this->visits);
}
/**

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Core\Repository\TagRepository;
@@ -15,7 +16,7 @@ use Shlinkio\Shlink\Core\Repository\TagRepository;
* @ORM\Entity(repositoryClass=TagRepository::class)
* @ORM\Table(name="tags")
*/
class Tag extends AbstractEntity implements \JsonSerializable
class Tag extends AbstractEntity implements JsonSerializable
{
/**
* @var string

View File

@@ -5,6 +5,7 @@ namespace Shlinkio\Shlink\Core\Entity;
use Cake\Chronos\Chronos;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Common\Exception\WrongIpException;
use Shlinkio\Shlink\Common\Util\IpAddress;
@@ -18,7 +19,7 @@ use Shlinkio\Shlink\Core\Repository\VisitRepository;
* @ORM\Entity(repositoryClass=VisitRepository::class)
* @ORM\Table(name="visits")
*/
class Visit extends AbstractEntity implements \JsonSerializable
class Visit extends AbstractEntity implements JsonSerializable
{
/**
* @var string

View File

@@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Zend\Stdlib\ArraySerializableInterface;
use function array_key_exists;
/**
* Class VisitLocation
@@ -15,7 +17,7 @@ use Zend\Stdlib\ArraySerializableInterface;
* @ORM\Entity()
* @ORM\Table(name="visit_locations")
*/
class VisitLocation extends AbstractEntity implements ArraySerializableInterface, \JsonSerializable
class VisitLocation extends AbstractEntity implements ArraySerializableInterface, JsonSerializable
{
/**
* @var string
@@ -135,25 +137,25 @@ class VisitLocation extends AbstractEntity implements ArraySerializableInterface
*/
public function exchangeArray(array $array): void
{
if (\array_key_exists('country_code', $array)) {
if (array_key_exists('country_code', $array)) {
$this->setCountryCode((string) $array['country_code']);
}
if (\array_key_exists('country_name', $array)) {
if (array_key_exists('country_name', $array)) {
$this->setCountryName((string) $array['country_name']);
}
if (\array_key_exists('region_name', $array)) {
if (array_key_exists('region_name', $array)) {
$this->setRegionName((string) $array['region_name']);
}
if (\array_key_exists('city', $array)) {
if (array_key_exists('city', $array)) {
$this->setCityName((string) $array['city']);
}
if (\array_key_exists('latitude', $array)) {
if (array_key_exists('latitude', $array)) {
$this->setLatitude((string) $array['latitude']);
}
if (\array_key_exists('longitude', $array)) {
if (array_key_exists('longitude', $array)) {
$this->setLongitude((string) $array['longitude']);
}
if (\array_key_exists('time_zone', $array)) {
if (array_key_exists('time_zone', $array)) {
$this->setTimezone((string) $array['time_zone']);
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
use Throwable;
use function sprintf;
class DeleteShortUrlException extends RuntimeException
{
@@ -20,7 +21,7 @@ class DeleteShortUrlException extends RuntimeException
public static function fromVisitsThreshold(int $threshold, string $shortCode): self
{
return new self($threshold, \sprintf(
return new self($threshold, sprintf(
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
$shortCode,
$threshold

View File

@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
interface ExceptionInterface extends \Throwable
use Throwable;
interface ExceptionInterface extends Throwable
{
}

View File

@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
use InvalidArgumentException as SplInvalidArgumentException;
class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface
{
}

View File

@@ -3,13 +3,16 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
use Exception;
use function sprintf;
class InvalidShortCodeException extends RuntimeException
{
public static function fromCharset($shortCode, $charSet, \Exception $previous = null)
public static function fromCharset($shortCode, $charSet, Exception $previous = null)
{
$code = $previous !== null ? $previous->getCode() : -1;
return new static(
\sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet),
sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet),
$code,
$previous
);
@@ -17,6 +20,6 @@ class InvalidShortCodeException extends RuntimeException
public static function fromNotFoundShortCode($shortCode)
{
return new static(\sprintf('Provided short code "%s" does not belong to a short URL', $shortCode));
return new static(sprintf('Provided short code "%s" does not belong to a short URL', $shortCode));
}
}

View File

@@ -3,9 +3,11 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
use Throwable;
class InvalidUrlException extends RuntimeException
{
public static function fromUrl($url, \Throwable $previous = null)
public static function fromUrl($url, Throwable $previous = null)
{
$code = isset($previous) ? $previous->getCode() : -1;
return new static(sprintf('Provided URL "%s" is not an existing and valid URL', $url), $code, $previous);

View File

@@ -3,6 +3,8 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
class RuntimeException extends \RuntimeException implements ExceptionInterface
use RuntimeException as SplRuntimeException;
class RuntimeException extends SplRuntimeException implements ExceptionInterface
{
}

View File

@@ -3,7 +3,11 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
use Throwable;
use Zend\InputFilter\InputFilterInterface;
use function is_array;
use function print_r;
use function sprintf;
class ValidationException extends RuntimeException
{
@@ -16,7 +20,7 @@ class ValidationException extends RuntimeException
string $message = '',
array $invalidElements = [],
int $code = 0,
\Throwable $previous = null
Throwable $previous = null
) {
$this->invalidElements = $invalidElements;
parent::__construct($message, $code, $previous);
@@ -27,7 +31,7 @@ class ValidationException extends RuntimeException
* @param \Throwable|null $prev
* @return ValidationException
*/
public static function fromInputFilter(InputFilterInterface $inputFilter, \Throwable $prev = null): self
public static function fromInputFilter(InputFilterInterface $inputFilter, Throwable $prev = null): self
{
return static::fromArray($inputFilter->getMessages(), $prev);
}
@@ -37,10 +41,10 @@ class ValidationException extends RuntimeException
* @param \Throwable|null $prev
* @return ValidationException
*/
public static function fromArray(array $invalidData, \Throwable $prev = null): self
public static function fromArray(array $invalidData, Throwable $prev = null): self
{
return new self(
\sprintf(
sprintf(
'Provided data is not valid. These are the messages:%s%s%s',
PHP_EOL,
self::formMessagesToString($invalidData),
@@ -56,10 +60,10 @@ class ValidationException extends RuntimeException
{
$text = '';
foreach ($messages as $name => $messageSet) {
$text .= \sprintf(
$text .= sprintf(
"\n\t'%s' => %s",
$name,
\is_array($messageSet) ? \print_r($messageSet, true) : $messageSet
is_array($messageSet) ? print_r($messageSet, true) : $messageSet
);
}

View File

@@ -7,6 +7,7 @@ use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Util\ShortUrlBuilderTrait;
use function array_map;
class ShortUrlDataTransformer implements DataTransformerInterface
{
@@ -37,7 +38,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface
'longUrl' => $longUrl,
'dateCreated' => $dateCreated !== null ? $dateCreated->toAtomString() : null,
'visitsCount' => $value->getVisitsCount(),
'tags' => \array_map([$this, 'serializeTag'], $value->getTags()->toArray()),
'tags' => array_map([$this, 'serializeTag'], $value->getTags()->toArray()),
// Deprecated
'originalUrl' => $longUrl,

View File

@@ -6,6 +6,9 @@ namespace Shlinkio\Shlink\Core\Util;
use Doctrine\Common\Collections;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Core\Entity\Tag;
use function str_replace;
use function strtolower;
use function trim;
trait TagManagerTrait
{
@@ -35,6 +38,6 @@ trait TagManagerTrait
*/
private function normalizeTagName($tagName): string
{
return \str_replace(' ', '-', \strtolower(\trim($tagName)));
return str_replace(' ', '-', strtolower(trim($tagName)));
}
}

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Validation;
use DateTime;
use Zend\I18n\Validator\IsInt;
use Zend\InputFilter\InputFilter;
use Zend\Validator\Date;
@@ -28,11 +29,11 @@ class ShortUrlMetaInputFilter extends InputFilter
private function initialize(): void
{
$validSince = $this->createInput(self::VALID_SINCE, false);
$validSince->getValidatorChain()->attach(new Date(['format' => \DateTime::ATOM]));
$validSince->getValidatorChain()->attach(new Date(['format' => DateTime::ATOM]));
$this->add($validSince);
$validUntil = $this->createInput(self::VALID_UNTIL, false);
$validUntil->getValidatorChain()->attach(new Date(['format' => \DateTime::ATOM]));
$validUntil->getValidatorChain()->attach(new Date(['format' => DateTime::ATOM]));
$this->add($validUntil);
$this->add($this->createInput(self::CUSTOM_SLUG, false));

View File

@@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepository;
use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase;
use function count;
class ShortUrlRepositoryTest extends DatabaseTestCase
{
@@ -131,7 +132,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$result = $this->repo->findList(null, null, null, [], ['longUrl' => 'ASC']);
$this->assertCount(\count($urls), $result);
$this->assertCount(count($urls), $result);
$this->assertEquals('a', $result[0]->getLongUrl());
$this->assertEquals('b', $result[1]->getLongUrl());
$this->assertEquals('c', $result[2]->getLongUrl());

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Action;
use finfo;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy;
@@ -76,7 +77,7 @@ class PreviewActionTest extends TestCase
);
$this->assertEquals(filesize($path), $resp->getHeaderLine('Content-length'));
$this->assertEquals((new \finfo(FILEINFO_MIME))->file($path), $resp->getHeaderLine('Content-type'));
$this->assertEquals((new finfo(FILEINFO_MIME))->file($path), $resp->getHeaderLine('Content-type'));
}
/**

View File

@@ -5,6 +5,8 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use function array_map;
use function range;
class DeleteShortUrlExceptionTest extends TestCase
{
@@ -54,8 +56,8 @@ class DeleteShortUrlExceptionTest extends TestCase
public function provideThresholds(): array
{
return \array_map(function (int $number) {
return array_map(function (int $number) {
return [$number];
}, \range(5, 50, 5));
}, range(5, 50, 5));
}
}

View File

@@ -14,6 +14,8 @@ use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use Shlinkio\Shlink\Core\Options\DeleteShortUrlsOptions;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface;
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlService;
use function array_map;
use function range;
class DeleteShortUrlServiceTest extends TestCase
{
@@ -29,9 +31,9 @@ class DeleteShortUrlServiceTest extends TestCase
public function setUp()
{
$shortUrl = (new ShortUrl())->setShortCode('abc123')
->setVisits(new ArrayCollection(\array_map(function () {
->setVisits(new ArrayCollection(array_map(function () {
return new Visit();
}, \range(0, 10))));
}, range(0, 10))));
$this->em = $this->prophesize(EntityManagerInterface::class);