From 544bc650c0e467b54b0bf43abf8972eddd0d806b Mon Sep 17 00:00:00 2001 From: Jontsa Date: Wed, 16 Feb 2022 10:19:14 +0200 Subject: [PATCH] bumb minimum to PHP 7.4 and Symfony 5.3 minimum, add Symfony 6 support --- .github/workflows/php.yml | 4 +-- composer.json | 13 ++++---- phpunit.xml.dist | 31 +++++++------------ src/Command/MaintenanceCommand.php | 10 ++---- src/EventListener/MaintenanceListener.php | 16 +++------- src/Maintenance.php | 4 +-- .../EventListener/MaintenanceListenerTest.php | 4 +-- tests/MaintenanceTest.php | 2 +- 8 files changed, 30 insertions(+), 54 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1c01f04..6fd45f8 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,12 +12,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.2', '7.3', '7.4', '8.0' ] + php: [ '7.4', '8.0' ] name: PHP ${{ matrix.php }} CI steps: - uses: actions/checkout@v2 - + - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/composer.json b/composer.json index df5e9f0..5466395 100644 --- a/composer.json +++ b/composer.json @@ -5,16 +5,15 @@ "type": "symfony-bundle", "require": { - "php": "^7.1|^8.0", - "symfony/http-kernel": "^4.4|^5.1", - "symfony/console": "^4.4|^5.1", - "symfony/config": "^4.4|^5.1", - "symfony/dependency-injection": "^4.4|^5.1" + "php": "^7.4|^8.0", + "symfony/http-kernel": "^5.3|^6.0", + "symfony/console": "^5.3|^6.0", + "symfony/config": "^5.3|^6.0", + "symfony/dependency-injection": "^5.3|^6.0" }, "require-dev": { - "symfony/phpunit-bridge": "^4.4|^5.1" + "symfony/phpunit-bridge": "^5.3|^6.0" }, - "autoload": { "psr-4": { "Jontsa\\Bundle\\MaintenanceBundle\\": "src/" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6812178..f349eaf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,13 @@ - - - - tests - - - - - - src - - + + + + src + + + + + tests + + diff --git a/src/Command/MaintenanceCommand.php b/src/Command/MaintenanceCommand.php index 51e709b..da477b3 100644 --- a/src/Command/MaintenanceCommand.php +++ b/src/Command/MaintenanceCommand.php @@ -15,7 +15,7 @@ class MaintenanceCommand extends Command protected static $defaultName = 'jontsa:maintenance'; - private $maintenance; + private Maintenance $maintenance; public function __construct(Maintenance $maintenance, string $name = null) { @@ -44,13 +44,11 @@ public function execute(InputInterface $input, OutputInterface $output) : int default: throw new InvalidArgumentException(sprintf('Unsupported action "%s".', $action)); } - return 0; + return Command::SUCCESS; } /** * Enables maintenance mode if not yet enabled. - * - * @param OutputInterface $output */ private function enable(OutputInterface $output) : void { @@ -64,8 +62,6 @@ private function enable(OutputInterface $output) : void /** * Disables maintenance mode if enabled. - * - * @param OutputInterface $output */ private function disable(OutputInterface $output) : void { @@ -77,4 +73,4 @@ private function disable(OutputInterface $output) : void } } -} \ No newline at end of file +} diff --git a/src/EventListener/MaintenanceListener.php b/src/EventListener/MaintenanceListener.php index 24ac3ec..725e4a8 100644 --- a/src/EventListener/MaintenanceListener.php +++ b/src/EventListener/MaintenanceListener.php @@ -14,15 +14,9 @@ class MaintenanceListener { - /** - * @var Maintenance - */ - protected $maintenance; + protected Maintenance $maintenance; - /** - * @var array|null - */ - protected $ips; + protected ?array $ips; public function __construct(Maintenance $maintenance, ?array $ips = null) { @@ -36,7 +30,7 @@ public function __construct(Maintenance $maintenance, ?array $ips = null) */ public function onKernelRequest(RequestEvent $event) : void { - if(false === $event->isMasterRequest()){ + if(false === $event->isMainRequest()){ return; } @@ -53,8 +47,6 @@ public function onKernelRequest(RequestEvent $event) : void /** * Check if maintenance mode is active. - * - * @return bool */ protected function inMaintenance() : bool { @@ -72,7 +64,7 @@ protected function checkIps(string $requestedIp, $ips) : bool { $ips = array_filter((array) $ips); - foreach ((array) $ips as $ip) { + foreach ($ips as $ip) { if (true === IpUtils::checkIp($requestedIp, $ip)) { return true; } diff --git a/src/Maintenance.php b/src/Maintenance.php index a531f56..0d64412 100644 --- a/src/Maintenance.php +++ b/src/Maintenance.php @@ -9,7 +9,7 @@ class Maintenance { - protected $filePath; + protected string $filePath; public function __construct(string $filePath) { @@ -18,8 +18,6 @@ public function __construct(string $filePath) /** * Check if maintenance mode is active. - * - * @return bool */ public function isEnabled() : bool { diff --git a/tests/EventListener/MaintenanceListenerTest.php b/tests/EventListener/MaintenanceListenerTest.php index 7e5b27f..176cff8 100644 --- a/tests/EventListener/MaintenanceListenerTest.php +++ b/tests/EventListener/MaintenanceListenerTest.php @@ -40,7 +40,7 @@ private function mockMasterRequestEvent() : RequestEvent $mock = $this->createMock(RequestEvent::class); $mock ->expects($this->once()) - ->method('isMasterRequest') + ->method('isMainRequest') ->willReturn(true); $mock ->expects($this->once()) @@ -58,7 +58,7 @@ private function mockNonMasterRequestEvent() : RequestEvent $mock = $this->createMock(RequestEvent::class); $mock ->expects($this->once()) - ->method('isMasterRequest') + ->method('isMainRequest') ->willReturn(false); $mock ->expects($this->never()) diff --git a/tests/MaintenanceTest.php b/tests/MaintenanceTest.php index d37b3e1..06b3c94 100644 --- a/tests/MaintenanceTest.php +++ b/tests/MaintenanceTest.php @@ -9,7 +9,7 @@ class MaintenanceTest extends TestCase { - private $lockFile; + private string $lockFile; public function setUp(): void {