Skip to content

Commit 1958642

Browse files
authored
Code cleanup (#35)
1 parent b6b3bb0 commit 1958642

40 files changed

Lines changed: 568 additions & 468 deletions

.github/workflows/ci.yml

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,35 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
strategy:
14+
fail-fast: false
1415
matrix:
15-
php: [ '7.3', '7.4', '8.0', '8.1' ]
16+
php: [ 8.1, 8.2, 8.3, 8.4 ]
17+
dependencies: [lowest, highest]
18+
include:
19+
- php: 8.4
20+
coverage: true
1621

1722
steps:
18-
- uses: actions/checkout@master
23+
- uses: actions/checkout@v4
1924

2025
- uses: shivammathur/setup-php@v2
2126
with:
2227
php-version: ${{ matrix.php }}
23-
coverage: xdebug
24-
25-
- name: Get composer cache directory
26-
id: composercache
27-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28-
29-
- name: Cache dependencies
30-
uses: actions/cache@v2
31-
with:
32-
path: ${{ steps.composercache.outputs.dir }}
33-
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
34-
restore-keys: ${{ runner.os }}-composer-
28+
coverage: ${ matrix.coverage && 'xdebug' || 'none' }
3529

3630
- name: Install dependencies
37-
run: composer update --ansi --no-interaction --no-scripts --no-progress --prefer-dist
31+
uses: ramsey/composer-install@v3
32+
with:
33+
dependency-versions: "${{ matrix.dependencies }}"
3834

3935
- name: Run test suite
40-
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
36+
run: |
37+
${{ matrix.coverage && 'vendor/bin/phpunit --coverage-clover build/logs/clover.xml' || 'vendor/bin/phpunit' }}
4138
4239
- uses: codecov/codecov-action@v1
40+
if: ${{ matrix.coverage }}
4341
with:
4442
token: ${{ secrets.CODECOV_TOKEN }}
4543
file: build/logs/clover.xml
4644
fail_ci_if_error: true
4745
verbose: true
48-
49-
unit_tests-lowest:
50-
runs-on: ubuntu-latest
51-
52-
steps:
53-
- uses: actions/checkout@master
54-
55-
- uses: shivammathur/setup-php@v2
56-
with:
57-
php-version: 7.4
58-
coverage: none
59-
60-
- name: Get composer cache directory
61-
id: composercache
62-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
63-
64-
- name: Cache dependencies
65-
uses: actions/cache@v2
66-
with:
67-
path: ${{ steps.composercache.outputs.dir }}
68-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
69-
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
70-
71-
- name: Install dependencies
72-
run: composer update --ansi --no-interaction --no-scripts --no-progress --prefer-dist --prefer-lowest
73-
74-
- name: Run test suite
75-
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

.github/workflows/phpstan.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,18 @@ jobs:
1212

1313
runs-on: ubuntu-latest
1414

15-
strategy:
16-
matrix:
17-
php-version:
18-
- "7.4"
19-
2015
steps:
2116
- name: "Checkout"
22-
uses: "actions/checkout@v2"
17+
uses: "actions/checkout@v4"
2318

2419
- name: "Install PHP"
2520
uses: "shivammathur/setup-php@v2"
2621
with:
2722
coverage: "none"
28-
php-version: "${{ matrix.php-version }}"
29-
30-
- name: "Determine composer cache directory"
31-
id: "determine-composer-cache-directory"
32-
run: "echo \"::set-output name=directory::$(composer config cache-dir)\""
33-
34-
- name: "Cache dependencies installed with composer"
35-
uses: "actions/cache@v2"
36-
with:
37-
path: "${{ steps.determine-composer-cache-directory.outputs.directory }}"
38-
key: "php-${{ matrix.php-version }}-${{ hashFiles('composer.json') }}"
39-
restore-keys: "php-${{ matrix.php-version }}-"
23+
php-version-file: .php-version
4024

41-
- name: "Install dependencies"
42-
run: "composer update"
25+
- name: Install dependencies
26+
uses: ramsey/composer-install@v3
4327

4428
- name: Run PHPStan
4529
run: vendor/bin/phpstan analyse --configuration=phpstan.neon

.php-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.3
1+
8.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This is useful in a continues deployment environment, where you can deploy not-y
2525

2626
## Requirements
2727

28-
Toggler requires PHP 7.3+ and Symfony 4.0+
28+
Toggler requires PHP 8.1+ and Symfony 6.1+
2929

3030
## Installation
3131

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.3",
22-
"symfony/polyfill-php80": "^1.20"
21+
"php": ">=8.1"
2322
},
2423
"require-dev": {
25-
"mikey179/vfsstream": "^1.6",
24+
"mikey179/vfsstream": "^1.6.8",
2625
"phpstan/extension-installer": "^1.0",
2726
"phpstan/phpstan": "^1.10",
2827
"phpstan/phpstan-deprecation-rules": "^1.1",
@@ -31,12 +30,14 @@
3130
"phpstan/phpstan-symfony": "^1.2",
3231
"phpunit/phpunit": "^9.5",
3332
"predis/predis": "^1.1 || ^2.0",
34-
"symfony/console": "^4.4 || ^5.0",
35-
"symfony/expression-language": "^4.4 || ^5.0",
36-
"symfony/framework-bundle": "^4.1 || ^5.0",
37-
"symfony/security-core": "^4.4 || ^5.0",
38-
"symfony/yaml": "^4.4 || ^5.0",
39-
"twig/twig": "^2.7 || ^3.0"
33+
"rector/rector": "^1.2",
34+
"symfony/console": "^6.1 || ^7.0",
35+
"symfony/expression-language": "^6.1 || ^7.0",
36+
"symfony/framework-bundle": "^6.1 || ^7.0",
37+
"symfony/security-core": "^6.1 || ^7.0",
38+
"symfony/yaml": "^6.1 || ^7.0",
39+
"symplify/easy-coding-standard": "^12.5",
40+
"twig/twig": "^3.15"
4041
},
4142
"suggest": {
4243
"symfony/expression-language": "To use expressions for conditions",

ecs.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of SolidWorx Toggler project.
7+
*
8+
* (c) SolidWorx <open-source@solidworx.co>
9+
*
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
12+
*/
13+
14+
use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer;
15+
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
16+
use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer;
17+
use PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer;
18+
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
19+
use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer;
20+
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
21+
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
22+
use PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer;
23+
use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer;
24+
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
25+
use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer;
26+
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
27+
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
28+
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
29+
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
30+
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
31+
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
32+
use Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer;
33+
use Symplify\EasyCodingStandard\Config\ECSConfig;
34+
35+
$header = <<<'EOF'
36+
This file is part of SolidWorx Toggler project.
37+
38+
(c) SolidWorx <open-source@solidworx.co>
39+
40+
This source file is subject to the MIT license that is bundled
41+
with this source code in the file LICENSE.
42+
EOF;
43+
44+
return ECSConfig::configure()
45+
->withPaths([
46+
__DIR__ . '/src',
47+
__DIR__ . '/tests',
48+
])
49+
->withRootFiles()
50+
->withPreparedSets(
51+
psr12: true,
52+
symplify: true,
53+
arrays: true,
54+
comments: true,
55+
docblocks: true,
56+
spaces: true,
57+
namespaces: true,
58+
controlStructures: true,
59+
phpunit: true,
60+
strict: true,
61+
cleanCode: true,
62+
)
63+
->withRules([
64+
PhpUnitMethodCasingFixer::class,
65+
FunctionToConstantFixer::class,
66+
ExplicitStringVariableFixer::class,
67+
ExplicitIndirectVariableFixer::class,
68+
NewWithBracesFixer::class,
69+
StandardizeIncrementFixer::class,
70+
SelfAccessorFixer::class,
71+
MagicConstantCasingFixer::class,
72+
NoUselessElseFixer::class,
73+
SingleQuoteFixer::class,
74+
VoidReturnFixer::class,
75+
])
76+
->withConfiguredRule(SingleClassElementPerStatementFixer::class, [
77+
'elements' => ['const', 'property'],
78+
])
79+
->withConfiguredRule(ClassDefinitionFixer::class, [
80+
'single_line' => true,
81+
])
82+
->withConfiguredRule(OrderedImportsFixer::class, [
83+
'imports_order' => ['const', 'class', 'function'],
84+
])
85+
->withConfiguredRule(HeaderCommentFixer::class, [
86+
'comment_type' => 'comment',
87+
'header' => trim($header),
88+
'location' => 'after_declare_strict',
89+
'separate' => 'both',
90+
])
91+
->withConfiguredRule(GeneralPhpdocAnnotationRemoveFixer::class, [
92+
'annotations' => ['author', 'package', 'group', 'covers', 'category'],
93+
])
94+
->withSkip(
95+
[
96+
MethodChainingNewlineFixer::class,
97+
LineLengthFixer::class,
98+
MethodChainingIndentationFixer::class => [
99+
__DIR__ . '/src/Symfony/DependencyInjection/Configuration.php',
100+
],
101+
]
102+
)
103+
;

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
parameters:
22
level: max
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src
56
- tests

phpunit.xml.dist

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
54
colors="true"
65
bootstrap="vendor/autoload.php"
76
>
7+
<coverage>
8+
<include>
9+
<directory>./src</directory>
10+
</include>
11+
</coverage>
812
<testsuites>
913
<testsuite name="Toggler Test Suite">
1014
<directory>./tests/</directory>
1115
</testsuite>
1216
</testsuites>
13-
14-
<filter>
15-
<whitelist>
16-
<directory>./src</directory>
17-
</whitelist>
18-
</filter>
1917
</phpunit>

rector.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of SolidWorx Toggler project.
7+
*
8+
* (c) SolidWorx <open-source@solidworx.co>
9+
*
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
12+
*/
13+
14+
use Rector\Config\RectorConfig;
15+
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector;
16+
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
17+
use Rector\PHPUnit\Set\PHPUnitSetList;
18+
use Rector\Set\ValueObject\LevelSetList;
19+
use Rector\Set\ValueObject\SetList;
20+
use Rector\ValueObject\PhpVersion;
21+
22+
return RectorConfig::configure()
23+
->withPaths([
24+
__DIR__ . '/src',
25+
__DIR__ . '/tests',
26+
])
27+
->withImportNames(removeUnusedImports: true)
28+
->withPhpVersion(PhpVersion::PHP_84)
29+
->withSets([
30+
// General
31+
SetList::CODE_QUALITY,
32+
SetList::CODING_STYLE,
33+
SetList::DEAD_CODE,
34+
SetList::EARLY_RETURN,
35+
SetList::INSTANCEOF,
36+
SetList::PHP_84,
37+
SetList::STRICT_BOOLEANS,
38+
SetList::TYPE_DECLARATION,
39+
SetList::PRIVATIZATION,
40+
41+
// PHP
42+
LevelSetList::UP_TO_PHP_73,
43+
44+
// PHPUnit
45+
PHPUnitSetList::PHPUNIT_90,
46+
PHPUnitSetList::PHPUNIT_100,
47+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
48+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
49+
])
50+
->withRules([
51+
PreferPHPUnitSelfCallRector::class,
52+
])
53+
->withSkip([
54+
PreferPHPUnitThisCallRector::class,
55+
]);

src/Storage/ArrayStorage.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
declare(strict_types=1);
44

55
/*
6-
* This file is part of the Toggler package.
6+
* This file is part of SolidWorx Toggler project.
77
*
88
* (c) SolidWorx <open-source@solidworx.co>
99
*
10-
* For the full copyright and license information, please view the LICENSE
11-
* file that was distributed with this source code.
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
1212
*/
1313

1414
namespace SolidWorx\Toggler\Storage;
@@ -20,7 +20,7 @@ class ArrayStorage implements StorageInterface
2020
/**
2121
* @var array<string, bool|string|int|Expression|object|callable|null>
2222
*/
23-
protected $config;
23+
protected array $config;
2424

2525
/**
2626
* @param array<string, bool|string|int|Expression|object|callable|null> $config
@@ -30,9 +30,6 @@ public function __construct(array $config)
3030
$this->config = $config;
3131
}
3232

33-
/**
34-
* {@inheritdoc}
35-
*/
3633
public function get(string $key)
3734
{
3835
return $this->config[$key] ?? null;

0 commit comments

Comments
 (0)