More PHP 8 syntactic sugar

This commit is contained in:
Alejandro Celaya 2021-05-23 12:37:53 +02:00
parent c01121d61a
commit 9c6ba4bc61
9 changed files with 27 additions and 12 deletions

View file

@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased]
### Added
* *Nothing*
### Changed
* [#1046](https://github.com/shlinkio/shlink/issues/1046) Dropped support for PHP 7.4.
### Deprecated
* *Nothing*
### Removed
* *Nothing*
### Fixed
* *Nothing*
## [2.7.0] - 2021-05-23
### Added
* [#1044](https://github.com/shlinkio/shlink/issues/1044) Added ability to set names on API keys, which helps to identify them when the list grows.

View file

@ -57,7 +57,7 @@ final class Version20180913205455 extends AbstractMigration
try {
return (string) IpAddress::fromString($addr)->getAnonymizedCopy();
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
return null;
}
}

View file

@ -63,7 +63,7 @@ abstract class AbstractWithDateRangeCommand extends BaseCommand
));
if ($output->isVeryVerbose()) {
$this->getApplication()->renderThrowable($e, $output);
$this->getApplication()?->renderThrowable($e, $output);
}
return null;

View file

@ -69,7 +69,7 @@ class DownloadGeoLiteDbCommand extends Command
}
if ($io->isVerbose()) {
$this->getApplication()->renderThrowable($e, $io);
$this->getApplication()?->renderThrowable($e, $io);
}
return $olderDbExists ? ExitCodes::EXIT_WARNING : ExitCodes::EXIT_FAILURE;

View file

@ -119,7 +119,7 @@ class LocateVisitsCommand extends AbstractLockedCommand implements VisitGeolocat
} catch (Throwable $e) {
$this->io->error($e->getMessage());
if ($this->io->isVerbose()) {
$this->getApplication()->renderThrowable($e, $this->io);
$this->getApplication()?->renderThrowable($e, $this->io);
}
return ExitCodes::EXIT_FAILURE;
@ -151,7 +151,7 @@ class LocateVisitsCommand extends AbstractLockedCommand implements VisitGeolocat
} catch (WrongIpException $e) {
$this->io->writeln(' [<fg=red>An error occurred while locating IP. Skipped</>]');
if ($this->io->isVerbose()) {
$this->getApplication()->renderThrowable($e, $this->io);
$this->getApplication()?->renderThrowable($e, $this->io);
}
throw IpCannotBeLocatedException::forError($e);

View file

@ -104,7 +104,7 @@ class Visit extends AbstractEntity implements JsonSerializable
try {
return (string) IpAddress::fromString($address)->getAnonymizedCopy();
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
return null;
}
}

View file

@ -44,7 +44,7 @@ class CloseDbConnectionEventListenerTest extends TestCase
try {
($eventListener)(new stdClass());
} catch (Throwable $e) {
} catch (Throwable) {
// Ignore exceptions
}

View file

@ -13,7 +13,7 @@ use Psr\Http\Server\RequestHandlerInterface;
use function array_shift;
use function explode;
use function strpos;
use function str_contains;
use function strtolower;
class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface
@ -62,7 +62,7 @@ class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface
{
$accepts = explode(',', $acceptValue);
$accept = strtolower(array_shift($accepts));
return strpos($accept, 'text/plain') !== false ? self::PLAIN_TEXT : self::JSON;
return str_contains($accept, 'text/plain') ? self::PLAIN_TEXT : self::JSON;
}
private function determineBody(JsonResponse $resp): string

View file

@ -16,8 +16,6 @@ use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer;
use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use function strpos;
class ResolveShortUrlActionTest extends TestCase
{
use ProphecyTrait;
@ -46,6 +44,6 @@ class ResolveShortUrlActionTest extends TestCase
$response = $this->action->handle($request);
self::assertEquals(200, $response->getStatusCode());
self::assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0);
self::assertStringContainsString('http://domain.com/foo/bar', $response->getBody()->getContents());
}
}