mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Replaced all FQ global function and constants by explicit imports
This commit is contained in:
parent
e1222de05b
commit
77d810b735
@ -6,6 +6,7 @@ namespace Shlinkio\Shlink;
|
||||
use Acelaya\ExpressiveErrorHandler;
|
||||
use Zend\ConfigAggregator;
|
||||
use Zend\Expressive;
|
||||
use function class_exists;
|
||||
|
||||
return (new ConfigAggregator\ConfigAggregator([
|
||||
Expressive\ConfigProvider::class,
|
||||
@ -13,7 +14,7 @@ return (new ConfigAggregator\ConfigAggregator([
|
||||
Expressive\Router\FastRouteRouter\ConfigProvider::class,
|
||||
Expressive\Plates\ConfigProvider::class,
|
||||
Expressive\Helper\ConfigProvider::class,
|
||||
\class_exists(Expressive\Swoole\ConfigProvider::class)
|
||||
class_exists(Expressive\Swoole\ConfigProvider::class)
|
||||
? Expressive\Swoole\ConfigProvider::class
|
||||
: new ConfigAggregator\ArrayProvider([]),
|
||||
ExpressiveErrorHandler\ConfigProvider::class,
|
||||
|
@ -6,6 +6,7 @@ namespace ShlinkMigrations;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use PDO;
|
||||
use Shlinkio\Shlink\Common\Exception\WrongIpException;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
|
||||
@ -38,7 +39,7 @@ final class Version20180913205455 extends AbstractMigration
|
||||
->set('v.remote_addr', ':obfuscatedAddr')
|
||||
->where('v.id=:id');
|
||||
|
||||
while ($row = $st->fetch(\PDO::FETCH_ASSOC)) {
|
||||
while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
|
||||
$addr = $row['remote_addr'] ?? null;
|
||||
if ($addr === null) {
|
||||
continue;
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Command\Api;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@ -47,7 +48,7 @@ class DisableKeyCommand extends Command
|
||||
try {
|
||||
$this->apiKeyService->disable($apiKey);
|
||||
$io->success(sprintf($this->translator->translate('API key "%s" properly disabled'), $apiKey));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$io->error(sprintf($this->translator->translate('API key "%s" does not exist.'), $apiKey));
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class DeleteShortUrlCommand extends Command
|
||||
{
|
||||
@ -68,7 +69,7 @@ class DeleteShortUrlCommand extends Command
|
||||
$this->runDelete($io, $shortCode, $ignoreThreshold);
|
||||
} catch (Exception\InvalidShortCodeException $e) {
|
||||
$io->error(
|
||||
\sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode)
|
||||
sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode)
|
||||
);
|
||||
} catch (Exception\DeleteShortUrlException $e) {
|
||||
$this->retry($io, $shortCode, $e);
|
||||
@ -77,7 +78,7 @@ class DeleteShortUrlCommand extends Command
|
||||
|
||||
private function retry(SymfonyStyle $io, string $shortCode, Exception\DeleteShortUrlException $e): void
|
||||
{
|
||||
$warningMsg = \sprintf($this->translator->translate(
|
||||
$warningMsg = sprintf($this->translator->translate(
|
||||
'It was not possible to delete the short URL with short code "%s" because it has more than %s visits.'
|
||||
), $shortCode, $e->getVisitsThreshold());
|
||||
$io->writeln('<bg=yellow>' . $warningMsg . '</>');
|
||||
@ -93,7 +94,7 @@ class DeleteShortUrlCommand extends Command
|
||||
private function runDelete(SymfonyStyle $io, string $shortCode, bool $ignoreThreshold): void
|
||||
{
|
||||
$this->deleteShortUrlService->deleteByShortCode($shortCode, $ignoreThreshold);
|
||||
$io->success(\sprintf(
|
||||
$io->success(sprintf(
|
||||
$this->translator->translate('Short URL with short code "%s" successfully deleted.'),
|
||||
$shortCode
|
||||
));
|
||||
|
@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class GeneratePreviewCommand extends Command
|
||||
{
|
||||
@ -71,7 +72,7 @@ class GeneratePreviewCommand extends Command
|
||||
private function processUrl($url, OutputInterface $output): void
|
||||
{
|
||||
try {
|
||||
$output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url));
|
||||
$output->write(sprintf($this->translator->translate('Processing URL %s...'), $url));
|
||||
$this->previewGenerator->generatePreview($url);
|
||||
$output->writeln($this->translator->translate(' <info>Success!</info>'));
|
||||
} catch (PreviewGenerationException $e) {
|
||||
|
@ -16,6 +16,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\Diactoros\Uri;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function array_merge;
|
||||
use function explode;
|
||||
use function sprintf;
|
||||
|
||||
class GenerateShortUrlCommand extends Command
|
||||
{
|
||||
@ -107,8 +110,8 @@ class GenerateShortUrlCommand extends Command
|
||||
$tags = $input->getOption('tags');
|
||||
$processedTags = [];
|
||||
foreach ($tags as $key => $tag) {
|
||||
$explodedTags = \explode(',', $tag);
|
||||
$processedTags = \array_merge($processedTags, $explodedTags);
|
||||
$explodedTags = explode(',', $tag);
|
||||
$processedTags = array_merge($processedTags, $explodedTags);
|
||||
}
|
||||
$tags = $processedTags;
|
||||
$customSlug = $input->getOption('customSlug');
|
||||
@ -126,16 +129,16 @@ class GenerateShortUrlCommand extends Command
|
||||
$shortUrl = $this->buildShortUrl($this->domainConfig, $shortCode);
|
||||
|
||||
$io->writeln([
|
||||
\sprintf('%s <info>%s</info>', $this->translator->translate('Processed long URL:'), $longUrl),
|
||||
\sprintf('%s <info>%s</info>', $this->translator->translate('Generated short URL:'), $shortUrl),
|
||||
sprintf('%s <info>%s</info>', $this->translator->translate('Processed long URL:'), $longUrl),
|
||||
sprintf('%s <info>%s</info>', $this->translator->translate('Generated short URL:'), $shortUrl),
|
||||
]);
|
||||
} catch (InvalidUrlException $e) {
|
||||
$io->error(\sprintf(
|
||||
$io->error(sprintf(
|
||||
$this->translator->translate('Provided URL "%s" is invalid. Try with a different one.'),
|
||||
$longUrl
|
||||
));
|
||||
} catch (NonUniqueSlugException $e) {
|
||||
$io->error(\sprintf(
|
||||
$io->error(sprintf(
|
||||
$this->translator->translate(
|
||||
'Provided slug "%s" is already in use by another URL. Try with a different one.'
|
||||
),
|
||||
|
@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function array_values;
|
||||
|
||||
class GetVisitsCommand extends Command
|
||||
{
|
||||
@ -95,7 +96,7 @@ class GetVisitsCommand extends Command
|
||||
|
||||
$rowData['country'] = $row->getVisitLocation()->getCountryName();
|
||||
|
||||
$rows[] = \array_values($rowData);
|
||||
$rows[] = array_values($rowData);
|
||||
}
|
||||
$io->table([
|
||||
$this->translator->translate('Referer'),
|
||||
|
@ -13,6 +13,11 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
class ListShortUrlsCommand extends Command
|
||||
{
|
||||
@ -97,7 +102,7 @@ class ListShortUrlsCommand extends Command
|
||||
$page = (int) $input->getOption('page');
|
||||
$searchTerm = $input->getOption('searchTerm');
|
||||
$tags = $input->getOption('tags');
|
||||
$tags = ! empty($tags) ? \explode(',', $tags) : [];
|
||||
$tags = ! empty($tags) ? explode(',', $tags) : [];
|
||||
$showTags = $input->getOption('showTags');
|
||||
$transformer = new ShortUrlDataTransformer($this->domainConfig);
|
||||
|
||||
@ -120,13 +125,13 @@ class ListShortUrlsCommand extends Command
|
||||
foreach ($result as $row) {
|
||||
$shortUrl = $transformer->transform($row);
|
||||
if ($showTags) {
|
||||
$shortUrl['tags'] = \implode(', ', $shortUrl['tags']);
|
||||
$shortUrl['tags'] = implode(', ', $shortUrl['tags']);
|
||||
} else {
|
||||
unset($shortUrl['tags']);
|
||||
}
|
||||
|
||||
unset($shortUrl['originalUrl']);
|
||||
$rows[] = \array_values($shortUrl);
|
||||
$rows[] = array_values($shortUrl);
|
||||
}
|
||||
$io->table($headers, $rows);
|
||||
|
||||
@ -135,7 +140,7 @@ class ListShortUrlsCommand extends Command
|
||||
$io->success($this->translator->translate('Short URLs properly listed'));
|
||||
} else {
|
||||
$continue = $io->confirm(
|
||||
\sprintf($this->translator->translate('Continue with page') . ' <options=bold>%s</>?', $page),
|
||||
sprintf($this->translator->translate('Continue with page') . ' <options=bold>%s</>?', $page),
|
||||
false
|
||||
);
|
||||
}
|
||||
@ -149,7 +154,7 @@ class ListShortUrlsCommand extends Command
|
||||
return null;
|
||||
}
|
||||
|
||||
$orderBy = \explode(',', $orderBy);
|
||||
return \count($orderBy) === 1 ? $orderBy[0] : [$orderBy[0] => $orderBy[1]];
|
||||
$orderBy = explode(',', $orderBy);
|
||||
return count($orderBy) === 1 ? $orderBy[0] : [$orderBy[0] => $orderBy[1]];
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class ResolveUrlCommand extends Command
|
||||
{
|
||||
@ -71,15 +72,15 @@ class ResolveUrlCommand extends Command
|
||||
try {
|
||||
$url = $this->urlShortener->shortCodeToUrl($shortCode);
|
||||
$output->writeln(
|
||||
\sprintf('%s <info>%s</info>', $this->translator->translate('Long URL:'), $url->getLongUrl())
|
||||
sprintf('%s <info>%s</info>', $this->translator->translate('Long URL:'), $url->getLongUrl())
|
||||
);
|
||||
} catch (InvalidShortCodeException $e) {
|
||||
$io->error(
|
||||
\sprintf($this->translator->translate('Provided short code "%s" has an invalid format.'), $shortCode)
|
||||
sprintf($this->translator->translate('Provided short code "%s" has an invalid format.'), $shortCode)
|
||||
);
|
||||
} catch (EntityDoesNotExistException $e) {
|
||||
$io->error(
|
||||
\sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode)
|
||||
sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Zend\I18n\Translator\Translator;
|
||||
use function array_pop;
|
||||
use function sprintf;
|
||||
|
||||
class DeleteShortCodeCommandTest extends TestCase
|
||||
{
|
||||
@ -47,7 +49,7 @@ class DeleteShortCodeCommandTest extends TestCase
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
$this->assertContains(\sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output);
|
||||
$this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output);
|
||||
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ class DeleteShortCodeCommandTest extends TestCase
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
$this->assertContains(\sprintf('Provided short code "%s" could not be found.', $shortCode), $output);
|
||||
$this->assertContains(sprintf('Provided short code "%s" could not be found.', $shortCode), $output);
|
||||
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
|
||||
}
|
||||
|
||||
@ -76,7 +78,7 @@ class DeleteShortCodeCommandTest extends TestCase
|
||||
$shortCode = 'abc123';
|
||||
$deleteByShortCode = $this->service->deleteByShortCode($shortCode, Argument::type('bool'))->will(
|
||||
function (array $args) {
|
||||
$ignoreThreshold = \array_pop($args);
|
||||
$ignoreThreshold = array_pop($args);
|
||||
|
||||
if (!$ignoreThreshold) {
|
||||
throw new Exception\DeleteShortUrlException(10);
|
||||
@ -88,11 +90,11 @@ class DeleteShortCodeCommandTest extends TestCase
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
$this->assertContains(\sprintf(
|
||||
$this->assertContains(sprintf(
|
||||
'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.',
|
||||
$shortCode
|
||||
), $output);
|
||||
$this->assertContains(\sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output);
|
||||
$this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output);
|
||||
$deleteByShortCode->shouldHaveBeenCalledTimes(2);
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ class DeleteShortCodeCommandTest extends TestCase
|
||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
$this->assertContains(\sprintf(
|
||||
$this->assertContains(sprintf(
|
||||
'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.',
|
||||
$shortCode
|
||||
), $output);
|
||||
|
@ -15,6 +15,7 @@ use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Zend\I18n\Translator\Translator;
|
||||
use function strpos;
|
||||
|
||||
class GetVisitsCommandTest extends TestCase
|
||||
{
|
||||
@ -88,8 +89,8 @@ class GetVisitsCommandTest extends TestCase
|
||||
'shortCode' => $shortCode,
|
||||
]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
$this->assertGreaterThan(0, \strpos($output, 'foo'));
|
||||
$this->assertGreaterThan(0, \strpos($output, 'Spain'));
|
||||
$this->assertGreaterThan(0, \strpos($output, 'bar'));
|
||||
$this->assertGreaterThan(0, strpos($output, 'foo'));
|
||||
$this->assertGreaterThan(0, strpos($output, 'Spain'));
|
||||
$this->assertGreaterThan(0, strpos($output, 'bar'));
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common;
|
||||
use const JSON_ERROR_NONE;
|
||||
use function getenv;
|
||||
use function in_array;
|
||||
use function json_decode as spl_json_decode;
|
||||
use function json_last_error;
|
||||
use function json_last_error_msg;
|
||||
use function strtolower;
|
||||
@ -50,11 +51,14 @@ function contains($needle, array $haystack): bool
|
||||
return in_array($needle, $haystack, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
function json_decode(string $json, int $depth = 512, int $options = 0): array
|
||||
{
|
||||
$data = \json_decode($json, true, $depth, $options);
|
||||
$data = spl_json_decode($json, true, $depth, $options);
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new Exception\InvalidArgumentException('Error decoding JSON: ' . json_last_error_msg());
|
||||
throw new Exception\InvalidArgumentException(sprintf('Error decoding JSON: %s', json_last_error_msg()));
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Exception;
|
||||
|
||||
interface ExceptionInterface extends \Throwable
|
||||
use Throwable;
|
||||
|
||||
interface ExceptionInterface extends Throwable
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Exception;
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||
use InvalidArgumentException as SplInvalidArgumentException;
|
||||
|
||||
class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Exception;
|
||||
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
use RuntimeException as SplRuntimeException;
|
||||
|
||||
class RuntimeException extends SplRuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -3,11 +3,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Exception;
|
||||
|
||||
use Throwable;
|
||||
use function sprintf;
|
||||
|
||||
class WrongIpException extends RuntimeException
|
||||
{
|
||||
public static function fromIpAddress($ipAddress, \Throwable $prev = null): self
|
||||
public static function fromIpAddress($ipAddress, Throwable $prev = null): self
|
||||
{
|
||||
return new self(sprintf('Provided IP "%s" is invalid', $ipAddress), 0, $prev);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Factory;
|
||||
|
||||
use ArrayAccess;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Interop\Container\Exception\ContainerException;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
@ -72,7 +73,7 @@ class DottedAccessConfigAbstractFactory implements AbstractFactoryInterface
|
||||
}
|
||||
|
||||
$value = $array[$key];
|
||||
if (! empty($keys) && (is_array($value) || $value instanceof \ArrayAccess)) {
|
||||
if (! empty($keys) && (is_array($value) || $value instanceof ArrayAccess)) {
|
||||
$value = $this->readKeysFromArray($keys, $value);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ namespace Shlinkio\Shlink\Common\Paginator\Adapter;
|
||||
|
||||
use Shlinkio\Shlink\Common\Repository\PaginableRepositoryInterface;
|
||||
use Zend\Paginator\Adapter\AdapterInterface;
|
||||
use function strip_tags;
|
||||
use function trim;
|
||||
|
||||
class PaginableRepositoryAdapter implements AdapterInterface
|
||||
{
|
||||
@ -34,7 +36,7 @@ class PaginableRepositoryAdapter implements AdapterInterface
|
||||
$orderBy = null
|
||||
) {
|
||||
$this->paginableRepository = $paginableRepository;
|
||||
$this->searchTerm = $searchTerm !== null ? \trim(\strip_tags($searchTerm)) : null;
|
||||
$this->searchTerm = $searchTerm !== null ? trim(strip_tags($searchTerm)) : null;
|
||||
$this->orderBy = $orderBy;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common\Paginator\Util;
|
||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||
use Zend\Paginator\Paginator;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
use function array_map;
|
||||
|
||||
trait PaginatorUtilsTrait
|
||||
{
|
||||
@ -25,7 +26,7 @@ trait PaginatorUtilsTrait
|
||||
|
||||
private function serializeItems(array $items, ?DataTransformerInterface $transformer = null): array
|
||||
{
|
||||
return $transformer === null ? $items : \array_map([$transformer, 'transform'], $items);
|
||||
return $transformer === null ? $items : array_map([$transformer, 'transform'], $items);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common\Response;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
use function base64_decode;
|
||||
|
||||
class PixelResponse extends Response
|
||||
{
|
||||
@ -26,7 +27,7 @@ class PixelResponse extends Response
|
||||
private function createBody(): StreamInterface
|
||||
{
|
||||
$body = new Stream('php://temp', 'wb+');
|
||||
$body->write((string) \base64_decode(self::BASE_64_IMAGE));
|
||||
$body->write((string) base64_decode(self::BASE_64_IMAGE));
|
||||
$body->rewind();
|
||||
return $body;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Common\Type;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\ConversionException;
|
||||
use Doctrine\DBAL\Types\DateTimeImmutableType;
|
||||
@ -39,14 +40,14 @@ class ChronosDateTimeType extends DateTimeImmutableType
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
return $value->format($platform->getDateTimeFormatString());
|
||||
}
|
||||
|
||||
throw ConversionException::conversionFailedInvalidType(
|
||||
$value,
|
||||
$this->getName(),
|
||||
['null', \DateTimeInterface::class]
|
||||
['null', DateTimeInterface::class]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Util;
|
||||
|
||||
use finfo;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Stream;
|
||||
@ -31,7 +32,7 @@ trait ResponseUtilsTrait
|
||||
{
|
||||
$body = new Stream($path);
|
||||
return new Response($body, 200, ArrayUtils::merge([
|
||||
'Content-Type' => (new \finfo(FILEINFO_MIME))->file($path),
|
||||
'Content-Type' => (new finfo(FILEINFO_MIME))->file($path),
|
||||
'Content-Length' => (string) $body->getSize(),
|
||||
], $extraHeaders));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Common\Factory;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||
@ -37,7 +38,7 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
||||
{
|
||||
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
||||
|
||||
$ref = new \ReflectionObject($instance);
|
||||
$ref = new ReflectionObject($instance);
|
||||
$prop = $ref->getProperty('responseFactory');
|
||||
$prop->setAccessible(true);
|
||||
$this->assertInstanceOf(EmptyResponse::class, $prop->getValue($instance)());
|
||||
|
@ -5,6 +5,7 @@ namespace ShlinkioTest\Shlink\Common\Image;
|
||||
|
||||
use mikehaertl\wkhtmlto\Image;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Common\Image\ImageFactory;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
@ -31,7 +32,7 @@ class ImageFactoryTest extends TestCase
|
||||
]]), '');
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
|
||||
$ref = new \ReflectionObject($image);
|
||||
$ref = new ReflectionObject($image);
|
||||
$page = $ref->getProperty('_page');
|
||||
$page->setAccessible(true);
|
||||
$this->assertNull($page->getValue($image));
|
||||
@ -50,7 +51,7 @@ class ImageFactoryTest extends TestCase
|
||||
]]), '', ['url' => $expectedPage]);
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
|
||||
$ref = new \ReflectionObject($image);
|
||||
$ref = new ReflectionObject($image);
|
||||
$page = $ref->getProperty('_page');
|
||||
$page->setAccessible(true);
|
||||
$this->assertEquals($expectedPage, $page->getValue($image));
|
||||
|
@ -9,6 +9,7 @@ use GuzzleHttp\Psr7\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Common\Service\IpApiLocationResolver;
|
||||
use function json_encode;
|
||||
|
||||
class IpApiLocationResolverTest extends TestCase
|
||||
{
|
||||
@ -47,7 +48,7 @@ class IpApiLocationResolverTest extends TestCase
|
||||
'time_zone' => '',
|
||||
];
|
||||
$response = new Response();
|
||||
$response->getBody()->write(\json_encode($actual));
|
||||
$response->getBody()->write(json_encode($actual));
|
||||
$response->getBody()->rewind();
|
||||
|
||||
$this->client->get('http://ip-api.com/json/1.2.3.4')->willReturn($response)
|
||||
|
@ -4,11 +4,15 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Common\Type;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\ConversionException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Type\ChronosDateTimeType;
|
||||
use stdClass;
|
||||
|
||||
class ChronosDateTimeTypeTest extends TestCase
|
||||
{
|
||||
@ -65,7 +69,7 @@ class ChronosDateTimeTypeTest extends TestCase
|
||||
* @test
|
||||
* @dataProvider providePhpValues
|
||||
*/
|
||||
public function valueIsConvertedToDatabaseFormat(?\DateTimeInterface $value, ?string $expected)
|
||||
public function valueIsConvertedToDatabaseFormat(?DateTimeInterface $value, ?string $expected)
|
||||
{
|
||||
$platform = $this->prophesize(AbstractPlatform::class);
|
||||
$platform->getDateTimeFormatString()->willReturn('Y-m-d');
|
||||
@ -77,9 +81,9 @@ class ChronosDateTimeTypeTest extends TestCase
|
||||
{
|
||||
return [
|
||||
[null, null],
|
||||
[new \DateTimeImmutable('2017-01-01'), '2017-01-01'],
|
||||
[new DateTimeImmutable('2017-01-01'), '2017-01-01'],
|
||||
[Chronos::parse('2017-02-01'), '2017-02-01'],
|
||||
[new \DateTime('2017-03-01'), '2017-03-01'],
|
||||
[new DateTime('2017-03-01'), '2017-03-01'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -89,6 +93,6 @@ class ChronosDateTimeTypeTest extends TestCase
|
||||
public function exceptionIsThrownIfInvalidValueIsParsedToDatabase()
|
||||
{
|
||||
$this->expectException(ConversionException::class);
|
||||
$this->type->convertToDatabaseValue(new \stdClass(), $this->prophesize(AbstractPlatform::class)->reveal());
|
||||
$this->type->convertToDatabaseValue(new stdClass(), $this->prophesize(AbstractPlatform::class)->reveal());
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Exception;
|
||||
|
||||
interface ExceptionInterface extends \Throwable
|
||||
use Throwable;
|
||||
|
||||
interface ExceptionInterface extends Throwable
|
||||
{
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
{
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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());
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Installer\Model;
|
||||
|
||||
use PDO;
|
||||
use Shlinkio\Shlink\Common\Collection\PathCollection;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\ApplicationConfigCustomizer;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\DatabaseConfigCustomizer;
|
||||
@ -206,7 +207,7 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
||||
|
||||
if ($dbDriver === 'pdo_mysql') {
|
||||
$config['entity_manager']['connection']['driverOptions'] = [
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\MethodProphecy;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Installer\Command\InstallCommand;
|
||||
use Shlinkio\Shlink\Installer\Config\ConfigCustomizerManagerInterface;
|
||||
use Shlinkio\Shlink\Installer\Config\Plugin\ConfigCustomizerInterface;
|
||||
@ -124,7 +125,7 @@ class InstallCommandTest extends TestCase
|
||||
*/
|
||||
public function whenCommandIsUpdatePreviousConfigCanBeImported()
|
||||
{
|
||||
$ref = new \ReflectionObject($this->command);
|
||||
$ref = new ReflectionObject($this->command);
|
||||
$prop = $ref->getProperty('isUpdate');
|
||||
$prop->setAccessible(true);
|
||||
$prop->setValue($this->command, true);
|
||||
|
@ -8,6 +8,7 @@ use Fig\Http\Message\StatusCodeInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use function array_merge;
|
||||
|
||||
abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface
|
||||
{
|
||||
@ -28,7 +29,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet
|
||||
{
|
||||
return [
|
||||
'name' => static::class,
|
||||
'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware),
|
||||
'middleware' => array_merge($prevMiddleware, [static::class], $postMiddleware),
|
||||
'path' => static::ROUTE_PATH,
|
||||
'allowed_methods' => static::ROUTE_ALLOWED_METHODS,
|
||||
];
|
||||
|
@ -14,8 +14,10 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Throwable;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
@ -80,7 +82,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
$this->logger->warning('Provided Invalid URL. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf(
|
||||
'message' => sprintf(
|
||||
$this->translator->translate('Provided URL %s is invalid. Try with a different one.'),
|
||||
$longUrl
|
||||
),
|
||||
@ -89,12 +91,12 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
$this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf(
|
||||
'message' => sprintf(
|
||||
$this->translator->translate('Provided slug %s is already in use. Try with a different one.'),
|
||||
$customSlug
|
||||
),
|
||||
], self::STATUS_BAD_REQUEST);
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::UNKNOWN_ERROR,
|
||||
|
@ -13,6 +13,7 @@ use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class DeleteShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
@ -55,7 +56,7 @@ class DeleteShortUrlAction extends AbstractRestAction
|
||||
);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
], self::STATUS_NOT_FOUND);
|
||||
} catch (Exception\DeleteShortUrlException $e) {
|
||||
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
|
||||
@ -65,7 +66,7 @@ class DeleteShortUrlAction extends AbstractRestAction
|
||||
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf($messagePlaceholder, $shortCode, $e->getVisitsThreshold()),
|
||||
'message' => sprintf($messagePlaceholder, $shortCode, $e->getVisitsThreshold()),
|
||||
], self::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class EditShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
@ -63,7 +64,7 @@ class EditShortUrlAction extends AbstractRestAction
|
||||
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
], self::STATUS_NOT_FOUND);
|
||||
} catch (Exception\ValidationException $e) {
|
||||
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -59,7 +60,7 @@ class ListShortUrlsAction extends AbstractRestAction
|
||||
return new JsonResponse(['shortUrls' => $this->serializePaginator($shortUrls, new ShortUrlDataTransformer(
|
||||
$this->domainConfig
|
||||
))]);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error('Unexpected error while listing short URLs. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::UNKNOWN_ERROR,
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -14,6 +15,7 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
use function sprintf;
|
||||
|
||||
class ResolveShortUrlAction extends AbstractRestAction
|
||||
{
|
||||
@ -62,7 +64,7 @@ class ResolveShortUrlAction extends AbstractRestAction
|
||||
$this->logger->warning('Provided short code with invalid format. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => \sprintf(
|
||||
'message' => sprintf(
|
||||
$this->translator->translate('Provided short code "%s" has an invalid format'),
|
||||
$shortCode
|
||||
),
|
||||
@ -71,9 +73,9 @@ class ResolveShortUrlAction extends AbstractRestAction
|
||||
$this->logger->warning('Provided short code couldn\'t be found. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::INVALID_ARGUMENT_ERROR,
|
||||
'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode),
|
||||
], self::STATUS_NOT_FOUND);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error('Unexpected error while resolving the URL behind a short code. {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::UNKNOWN_ERROR,
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Rest\Action\Visit;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -67,7 +68,7 @@ class GetVisitsAction extends AbstractRestAction
|
||||
$shortCode
|
||||
),
|
||||
], self::STATUS_NOT_FOUND);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error('Unexpected error while parsing short code {e}', ['e' => $e]);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::UNKNOWN_ERROR,
|
||||
|
@ -7,6 +7,7 @@ use Firebase\JWT\JWT;
|
||||
use Shlinkio\Shlink\Core\Options\AppOptions;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use Shlinkio\Shlink\Rest\Exception\AuthenticationException;
|
||||
use UnexpectedValueException;
|
||||
use function time;
|
||||
|
||||
class JWTService implements JWTServiceInterface
|
||||
@ -68,7 +69,7 @@ class JWTService implements JWTServiceInterface
|
||||
// If no exception is thrown while decoding the token, it is considered valid
|
||||
$this->decode($jwt);
|
||||
return true;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
} catch (UnexpectedValueException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -84,7 +85,7 @@ class JWTService implements JWTServiceInterface
|
||||
{
|
||||
try {
|
||||
return $this->decode($jwt);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
} catch (UnexpectedValueException $e) {
|
||||
throw AuthenticationException::expiredJWT($e);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ use Acelaya\ExpressiveErrorHandler\ErrorHandler\ErrorResponseGeneratorInterface;
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Throwable;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use function str_replace;
|
||||
use function strtoupper;
|
||||
|
||||
class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, StatusCodeInterface
|
||||
{
|
||||
@ -20,7 +23,7 @@ class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, Sta
|
||||
* @return Response
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __invoke(?\Throwable $e, Request $request, Response $response)
|
||||
public function __invoke(?Throwable $e, Request $request, Response $response)
|
||||
{
|
||||
$status = $response->getStatusCode();
|
||||
$responsePhrase = $status < 400 ? 'Internal Server Error' : $response->getReasonPhrase();
|
||||
@ -34,6 +37,6 @@ class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, Sta
|
||||
|
||||
private function responsePhraseToCode(string $responsePhrase): string
|
||||
{
|
||||
return \strtoupper(\str_replace(' ', '_', $responsePhrase));
|
||||
return strtoupper(str_replace(' ', '_', $responsePhrase));
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class AuthenticationException extends RuntimeException
|
||||
{
|
||||
public static function expiredJWT(\Exception $prev = null): self
|
||||
public static function expiredJWT(Exception $prev = null): self
|
||||
{
|
||||
return new self('The token has expired.', -1, $prev);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
interface ExceptionInterface extends \Throwable
|
||||
use Throwable;
|
||||
|
||||
interface ExceptionInterface extends Throwable
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
use RuntimeException as SplRuntimeException;
|
||||
|
||||
class RuntimeException extends SplRuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use function strpos;
|
||||
|
||||
class PathVersionMiddleware implements MiddlewareInterface
|
||||
{
|
||||
@ -26,7 +27,7 @@ class PathVersionMiddleware implements MiddlewareInterface
|
||||
$path = $uri->getPath();
|
||||
|
||||
// If the path does not begin with the version number, prepend v1 by default for BC compatibility purposes
|
||||
if (\strpos($path, '/v') !== 0) {
|
||||
if (strpos($path, '/v') !== 0) {
|
||||
$request = $request->withUri($uri->withPath('/v1' . $uri->getPath()));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,10 @@ use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use function array_shift;
|
||||
use function explode;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
|
||||
class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface
|
||||
{
|
||||
@ -54,15 +58,15 @@ class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface
|
||||
return self::JSON;
|
||||
}
|
||||
|
||||
$format = \strtolower((string) $query['format']);
|
||||
$format = strtolower((string) $query['format']);
|
||||
return $format === 'txt' ? self::PLAIN_TEXT : self::JSON;
|
||||
}
|
||||
|
||||
private function determineAcceptTypeFromHeader(string $acceptValue): string
|
||||
{
|
||||
$accepts = \explode(',', $acceptValue);
|
||||
$accept = \strtolower(\array_shift($accepts));
|
||||
return \strpos($accept, 'text/plain') !== false ? self::PLAIN_TEXT : self::JSON;
|
||||
$accepts = explode(',', $acceptValue);
|
||||
$accept = strtolower(array_shift($accepts));
|
||||
return strpos($accept, 'text/plain') !== false ? self::PLAIN_TEXT : self::JSON;
|
||||
}
|
||||
|
||||
private function determineBody(JsonResponse $resp): string
|
||||
|
@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use function str_replace;
|
||||
|
||||
class ShortCodePathMiddleware implements MiddlewareInterface
|
||||
{
|
||||
@ -24,7 +25,7 @@ class ShortCodePathMiddleware implements MiddlewareInterface
|
||||
|
||||
// If the path starts with the old prefix, replace it by the new one
|
||||
return $handler->handle(
|
||||
$request->withUri($uri->withPath(\str_replace(self::OLD_PATH_PREFIX, self::NEW_PATH_PREFIX, $path)))
|
||||
$request->withUri($uri->withPath(str_replace(self::OLD_PATH_PREFIX, self::NEW_PATH_PREFIX, $path)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Rest\Util;
|
||||
use Shlinkio\Shlink\Common\Exception as Common;
|
||||
use Shlinkio\Shlink\Core\Exception as Core;
|
||||
use Shlinkio\Shlink\Rest\Exception as Rest;
|
||||
use Throwable;
|
||||
|
||||
class RestUtils
|
||||
{
|
||||
@ -22,7 +23,7 @@ class RestUtils
|
||||
public const NOT_FOUND_ERROR = 'NOT_FOUND';
|
||||
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
||||
|
||||
public static function getRestErrorCodeFromException(\Throwable $e)
|
||||
public static function getRestErrorCodeFromException(Throwable $e)
|
||||
{
|
||||
switch (true) {
|
||||
case $e instanceof Core\InvalidShortCodeException:
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
@ -111,7 +112,7 @@ class CreateShortUrlActionTest extends TestCase
|
||||
public function aGenericExceptionWillReturnError()
|
||||
{
|
||||
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
|
||||
->willThrow(\Exception::class)
|
||||
->willThrow(Exception::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
|
||||
|
@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Exception;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction;
|
||||
use Shlinkio\Shlink\Rest\Util\RestUtils;
|
||||
use Throwable;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\I18n\Translator\Translator;
|
||||
@ -49,7 +50,7 @@ class DeleteShortUrlActionTest extends TestCase
|
||||
* @test
|
||||
* @dataProvider provideExceptions
|
||||
*/
|
||||
public function returnsErrorResponseInCaseOfException(\Throwable $e, string $error, int $statusCode)
|
||||
public function returnsErrorResponseInCaseOfException(Throwable $e, string $error, int $statusCode)
|
||||
{
|
||||
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e);
|
||||
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlService;
|
||||
@ -53,7 +54,7 @@ class ListShortUrlsActionTest extends TestCase
|
||||
public function anExceptionsReturnsErrorResponse()
|
||||
{
|
||||
$page = 3;
|
||||
$this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
|
||||
$this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
|
||||
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
@ -83,7 +84,7 @@ class ResolveShortUrlActionTest extends TestCase
|
||||
public function unexpectedExceptionWillReturnError()
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(\Exception::class)
|
||||
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
@ -65,7 +66,7 @@ class GetVisitsActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
|
||||
\Exception::class
|
||||
Exception::class
|
||||
)->shouldBeCalledTimes(1);
|
||||
|
||||
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
|
||||
|
@ -12,6 +12,7 @@ use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\Diactoros\Uri;
|
||||
use function array_shift;
|
||||
|
||||
class PathVersionMiddlewareTest extends TestCase
|
||||
{
|
||||
@ -49,7 +50,7 @@ class PathVersionMiddlewareTest extends TestCase
|
||||
|
||||
$delegate = $this->prophesize(RequestHandlerInterface::class);
|
||||
$delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) {
|
||||
$req = \array_shift($args);
|
||||
$req = array_shift($args);
|
||||
|
||||
Assert::assertNotSame($request, $req);
|
||||
Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath());
|
||||
|
@ -39,6 +39,8 @@
|
||||
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
|
||||
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
|
||||
<!-- Enforce all global namespace classes, functions and constants to be explicitly imported -->
|
||||
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
|
||||
|
||||
<!-- Paths to check -->
|
||||
<file>bin</file>
|
||||
|
Loading…
Reference in New Issue
Block a user