Skip to content

Commit

Permalink
Update for PHP 8.0 and 8.1 (#26)
Browse files Browse the repository at this point in the history
* Update for PHP 8.0 and 8.1

* Update workflow job name
  • Loading branch information
svenluijten committed Feb 5, 2022
1 parent 08f3d7f commit dcd66ab
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 35 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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);
}

/**
* {@inheritdoc}
*/
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);
}
}
3 changes: 1 addition & 2 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

class File
{
/** @var string */
protected $path;
protected string $path;

public function __construct(string $path)
{
Expand Down
13 changes: 2 additions & 11 deletions src/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
9 changes: 0 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down

0 comments on commit dcd66ab

Please sign in to comment.