Skip to content

Commit

Permalink
Merge pull request #2 from Jontsa/symfony-6-support
Browse files Browse the repository at this point in the history
bumb minimum to PHP 7.4 and Symfony 5.3 minimum, add Symfony 6 support
  • Loading branch information
Jontsa authored Feb 16, 2022
2 parents d683396 + 544bc65 commit 649a382
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
31 changes: 11 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="JontsaMaintenanceBundle test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" forceCoversAnnotation="false" beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="JontsaMaintenanceBundle test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
10 changes: 3 additions & 7 deletions src/Command/MaintenanceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand All @@ -64,8 +62,6 @@ private function enable(OutputInterface $output) : void

/**
* Disables maintenance mode if enabled.
*
* @param OutputInterface $output
*/
private function disable(OutputInterface $output) : void
{
Expand All @@ -77,4 +73,4 @@ private function disable(OutputInterface $output) : void
}
}

}
}
16 changes: 4 additions & 12 deletions src/EventListener/MaintenanceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand All @@ -53,8 +47,6 @@ public function onKernelRequest(RequestEvent $event) : void

/**
* Check if maintenance mode is active.
*
* @return bool
*/
protected function inMaintenance() : bool
{
Expand All @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Maintenance
{

protected $filePath;
protected string $filePath;

public function __construct(string $filePath)
{
Expand All @@ -18,8 +18,6 @@ public function __construct(string $filePath)

/**
* Check if maintenance mode is active.
*
* @return bool
*/
public function isEnabled() : bool
{
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/MaintenanceListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/MaintenanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class MaintenanceTest extends TestCase
{

private $lockFile;
private string $lockFile;

public function setUp(): void
{
Expand Down

0 comments on commit 649a382

Please sign in to comment.