From dcd66ab40c945a103d950af9c90ee16ada990986 Mon Sep 17 00:00:00 2001 From: Sven Luijten <11269635+svenluijten@users.noreply.github.com> Date: Sat, 5 Feb 2022 15:37:37 +0100 Subject: [PATCH] Update for PHP 8.0 and 8.1 (#26) * Update for PHP 8.0 and 8.1 * Update workflow job name --- .github/workflows/tests.yml | 17 ++++++++++------- composer.json | 6 +++--- src/Drivers/DotEnv.php | 2 +- src/Drivers/Json.php | 4 ++-- src/File.php | 3 +-- src/Store.php | 13 ++----------- tests/TestCase.php | 9 --------- 7 files changed, 19 insertions(+), 35 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b566be..02a89ca 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,15 +1,15 @@ -name: Tests (PHP) -on: [push, pull_request] +name: Tests +on: [push] jobs: phpunit: - name: PHP ${{ matrix.os }}, ${{ matrix.php }} (${{ matrix.composer_flags }}) + name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: - php: [7.3, 7.4] + php: [8.0, 8.1] os: [ubuntu-latest, windows-latest] - composer_flags: ['--prefer-lowest --prefer-stable', '--prefer-stable'] + dependency-version: [lowest, highest] steps: - uses: actions/checkout@v2.4.0 @@ -20,8 +20,11 @@ jobs: extensions: mbstring, fileinfo coverage: none - - name: Install Composer dependencies - run: composer update --no-interaction --no-ansi --prefer-dist ${{ matrix.composer_flags }} + - name: Install dependencies + uses: ramsey/composer-install@v1 + with: + dependency-versions: ${{ matrix.dependency-version }} + composer-options: "--prefer-dist" - name: Execute tests run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 66c2dce..03dcb24 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ } ], "require": { - "php": "^7.1 || ^8.0", + "php": "^8.0", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "league/flysystem": "^2.0" + "phpunit/phpunit": "^9.0 | ^10.0", + "league/flysystem": "^3.0" }, "autoload": { "psr-4": { diff --git a/src/Drivers/DotEnv.php b/src/Drivers/DotEnv.php index 97f83a6..787f314 100644 --- a/src/Drivers/DotEnv.php +++ b/src/Drivers/DotEnv.php @@ -59,7 +59,7 @@ protected function isEmptyLine(string $value, $key = null): bool protected function isComment(string $value): bool { - return mb_strpos($value, '#') === 0; + return str_starts_with($value, '#'); } protected function quoteIfNecessary(string $value): string diff --git a/src/Drivers/Json.php b/src/Drivers/Json.php index e2ac63d..7e86213 100644 --- a/src/Drivers/Json.php +++ b/src/Drivers/Json.php @@ -9,7 +9,7 @@ class Json implements Driver */ public function import(string $contents): array { - return json_decode($contents, true); + return json_decode($contents, associative: true, flags: JSON_THROW_ON_ERROR); } /** @@ -17,6 +17,6 @@ public function import(string $contents): array */ public function export(array $config): string { - return json_encode($config, JSON_FORCE_OBJECT | JSON_OBJECT_AS_ARRAY); + return json_encode($config, flags: JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT | JSON_OBJECT_AS_ARRAY); } } diff --git a/src/File.php b/src/File.php index 81548fd..4fc7076 100644 --- a/src/File.php +++ b/src/File.php @@ -4,8 +4,7 @@ class File { - /** @var string */ - protected $path; + protected string $path; public function __construct(string $path) { diff --git a/src/Store.php b/src/Store.php index c3fec08..6c7123e 100644 --- a/src/Store.php +++ b/src/Store.php @@ -6,19 +6,10 @@ class Store { - /** @var \Sven\FileConfig\File */ - protected $file; + protected array $config; - /** @var array */ - protected $config; - - /** @var \Sven\FileConfig\Drivers\Driver */ - protected $driver; - - public function __construct(File $file, Driver $driver) + public function __construct(protected File $file, protected Driver $driver) { - $this->file = $file; - $this->driver = $driver; $this->config = $driver->import($file->contents()); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 256643b..04883e6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,25 +10,16 @@ abstract class TestCase extends BaseTestCase { protected const TEMP_DIRECTORY = 'temp'; - /** - * {@inheritdoc} - */ public function setUp(): void { $this->filesystem()->createDirectory(self::TEMP_DIRECTORY); } - /** - * {@inheritdoc} - */ public function tearDown(): void { $this->filesystem()->deleteDirectory(self::TEMP_DIRECTORY); } - /** - * @return \League\Flysystem\Filesystem - */ protected function filesystem(): Filesystem { $adapter = new LocalFilesystemAdapter(__DIR__);