Skip to content

Commit

Permalink
PHP 8 support
Browse files Browse the repository at this point in the history
* update Code tools
* update GitHub action
* remove usage of \Safe\DateTimeImmutable because it's not compatible with PHP 8 yet
* add LICENCE file

We also need to specify --ignore-platform-reqs at the moment because one dependency doesn't support PHP 8, yet (narrowspark/mimetypes#27).
  • Loading branch information
rieschl committed Oct 21, 2021
1 parent bc4272f commit 7445dca
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 88 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
@@ -0,0 +1,12 @@
/.github/ export-ignore
/features/ export-ignore
/tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/composer-require-checker.json export-ignore
/infection.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml export-ignore
/psalm.xml export-ignore
40 changes: 28 additions & 12 deletions .github/workflows/checks.yml
@@ -1,13 +1,20 @@
name: Check Build

on: [push, pull_request]
on: [pull_request]

jobs:
build:

strategy:
matrix:
php: ["7.4", "8.0"]
include:
- php: "8.0"
composer_args: "--ignore-platform-reqs"

runs-on: ubuntu-latest
container:
image: eventjet/checks-7.4:latest
image: eventjet/checks-${{ matrix.php }}:latest

steps:
- name: Checkout
Expand All @@ -17,23 +24,24 @@ jobs:
run: |
mkdir -p /root/.ssh
ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts
echo "COMPOSER_CACHE=$(composer config cache-dir)" >> $GITHUB_ENV
- name: Composer Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: $(composer config cache-files-dir)
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
path: |
${{ env.COMPOSER_CACHE }}
vendor
key: ${{ runner.os }}-composer

- name: Install dependencies
run: |
composer install --no-progress --no-suggest --no-interaction > /dev/null
composer update --no-progress --no-interaction ${{ matrix.composer_args }} > /dev/null
- name: Static analysis
run: |
composer check-deps
composer cs-check
composer cs-check -- --runtime-set php_version 70400
composer phpstan -- --no-progress
composer psalm
Expand All @@ -42,11 +50,19 @@ jobs:
vendor/bin/phpunit --coverage-clover=coverage.xml --stop-on-failure
composer run --timeout=0 infection
- name: Save Infection result
uses: actions/upload-artifact@v2
if: always()
with:
name: infection-log.txt
path: infection-log.txt

- name: Monitor coverage
if: github.event_name == 'pull_request'
uses: slavcodev/coverage-monitor-action@1.0.1
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
clover_file: "coverage.xml"
threshold_alert: 90
threshold_warning: 95
comment_context: PHP ${{ matrix.php }}
threshold_alert: 100
threshold_warning: 100
25 changes: 25 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,25 @@
# Changelog

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 0.1.3 - TBD

### Added

- [#8](https://github.com/eventjet/eventjet-asset-manager/pull/8) adds support for PHP 8

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.
16 changes: 16 additions & 0 deletions LICENSE.md
@@ -0,0 +1,16 @@
MIT License

Copyright (c) 2021 Eventjet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 7 additions & 8 deletions composer.json
Expand Up @@ -10,25 +10,24 @@
"fig/http-message-util": "^1.1",
"laminas/laminas-diactoros": "^2.3",
"narrowspark/mimetypes": "^1.6",
"psr/container": "^1.0",
"psr/container": "^1.1 || ^2.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"thecodingmachine/safe": "^1.1"
},
"require-dev": {
"eventjet/coding-standard": "^3.1",
"infection/infection": "^0.16",
"maglnet/composer-require-checker": "^2.0",
"eventjet/coding-standard": "^3.7",
"infection/infection": "^0.25",
"maglnet/composer-require-checker": "^3.3",
"nette/php-generator": "^3.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.5",
"phpstan/phpstan-phpunit": "^0.12.6",
"phpstan/phpstan-strict-rules": "^0.12.1",
"phpunit/phpunit": "^9.0",
"thecodingmachine/phpstan-safe-rule": "^1.0",
"vimeo/psalm": "^3.8"
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.10"
},
"config": {
"sort-packages": true
Expand Down Expand Up @@ -63,7 +62,7 @@
"check-deps": "vendor/bin/composer-require-checker",
"cs-check": "vendor/bin/phpcs",
"cs-fix": "vendor/bin/phpcbf",
"infection": "vendor/bin/infection --threads=4 --min-msi=100 --min-covered-msi=100",
"infection": "vendor/bin/infection --threads=4",
"infection-xdebug": "@composer run --timeout=0 infection -- --initial-tests-php-options='-d zend_extension=xdebug.so'",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "vendor/bin/phpunit",
Expand Down
4 changes: 3 additions & 1 deletion infection.json
Expand Up @@ -7,5 +7,7 @@
},
"logs": {
"text": "infection-log.txt"
}
},
"minMsi": 100,
"minCoveredMsi": 100
}
3 changes: 3 additions & 0 deletions phpcs.xml
@@ -1,6 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Eventjet coding standard">
<rule ref="EventjetStrict"/>

<arg name="parallel" value="80"/>

<file>src</file>
<file>tests</file>
</ruleset>
12 changes: 8 additions & 4 deletions phpunit.xml
Expand Up @@ -2,6 +2,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="Eventjet\AssetManager\Unit">
Expand All @@ -11,9 +15,9 @@
<directory>tests/functional</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
46 changes: 1 addition & 45 deletions psalm.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
strictBinaryOperands="true"
totallyTyped="false"
errorLevel="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -13,48 +13,4 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info"/>

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info"/>
<DeprecatedProperty errorLevel="info"/>
<DeprecatedClass errorLevel="info"/>
<DeprecatedConstant errorLevel="info"/>
<DeprecatedFunction errorLevel="info"/>
<DeprecatedInterface errorLevel="info"/>
<DeprecatedTrait errorLevel="info"/>

<InternalMethod errorLevel="info"/>
<InternalProperty errorLevel="info"/>
<InternalClass errorLevel="info"/>

<MissingClosureReturnType errorLevel="info"/>
<MissingReturnType errorLevel="info"/>
<MissingPropertyType errorLevel="info"/>
<InvalidDocblock errorLevel="info"/>
<MisplacedRequiredParam errorLevel="info"/>

<PropertyNotSetInConstructor errorLevel="info">
<errorLevel type="suppress">
<directory name="tests"/>
</errorLevel>
</PropertyNotSetInConstructor>
<MissingConstructor errorLevel="info"/>
<MissingClosureParamType errorLevel="info"/>
<MissingParamType errorLevel="info"/>

<RedundantCondition errorLevel="info"/>

<DocblockTypeContradiction errorLevel="info"/>
<RedundantConditionGivenDocblockType errorLevel="info"/>

<UnresolvableInclude errorLevel="info"/>

<RawObjectIteration errorLevel="info"/>

<InvalidStringClass errorLevel="info"/>
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Asset/FileAsset.php
Expand Up @@ -7,6 +7,8 @@
use Narrowspark\MimeType\MimeTypeExtensionGuesser;
use SplFileInfo;

use function strlen;

final class FileAsset implements AssetInterface
{
private ?string $content;
Expand Down
6 changes: 4 additions & 2 deletions src/Resolver/PathMappingResolver.php
Expand Up @@ -7,14 +7,16 @@
use Eventjet\AssetManager\Asset\AssetFactoryInterface;
use Eventjet\AssetManager\Asset\AssetInterface;

use function file_exists;

final class PathMappingResolver implements ResolverInterface
{
/** @var string[] */
/** @var array<array-key, string> */
private array $pathMapping;
private AssetFactoryInterface $factory;

/**
* @param string[] $pathMapping
* @param array<array-key, string> $pathMapping
*/
public function __construct(array $pathMapping, AssetFactoryInterface $factory)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/PathMappingResolverFactory.php
Expand Up @@ -18,7 +18,7 @@ public function __invoke(ContainerInterface $container): PathMappingResolver
}

/**
* @return array<string>
* @return array<array-key, string>
*/
private function paths(ContainerInterface $container): array
{
Expand Down
21 changes: 12 additions & 9 deletions src/Service/AssetManager.php
Expand Up @@ -4,6 +4,7 @@

namespace Eventjet\AssetManager\Service;

use DateTimeImmutable;
use DateTimeZone;
use Eventjet\AssetManager\Resolver\ResolverInterface;
use Fig\Http\Message\StatusCodeInterface;
Expand All @@ -13,8 +14,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use RuntimeException;
use Safe\DateTimeImmutable;
use Safe\Exceptions\DatetimeException;

use function gmdate;
use function is_string;
Expand Down Expand Up @@ -49,17 +48,21 @@ public function buildAssetResponse(ServerRequestInterface $request): ResponseInt
$etagFile = \Safe\md5_file($asset->getPath());

$serverParams = $request->getServerParams();
/** @var string|null $ifModifiedSince */
$ifModifiedSince = $serverParams['HTTP_IF_MODIFIED_SINCE'] ?? null;
/** @var string|null $etagHeader */
$etagHeader = $serverParams['HTTP_IF_NONE_MATCH'] ?? null;

if (is_string($ifModifiedSince)) {
try {
$ifModifiedSince = DateTimeImmutable::createFromFormat(
DATE_RFC7231,
$ifModifiedSince,
new DateTimeZone('UTC')
)->getTimestamp();
} catch (DatetimeException $exception) {
$modifiedDate = DateTimeImmutable::createFromFormat(
DATE_RFC7231,
$ifModifiedSince,
new DateTimeZone('UTC')
);

if ($modifiedDate instanceof DateTimeImmutable) {
$ifModifiedSince = $modifiedDate->getTimestamp();
} else {
$ifModifiedSince = null;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/ObjectFactory.php
Expand Up @@ -18,6 +18,8 @@
use function str_replace;
use function stream_get_meta_data;

use const DIRECTORY_SEPARATOR;

final class ObjectFactory
{
public static function tmpFileName(): string
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Service/AssetManagerTest.php
Expand Up @@ -15,6 +15,8 @@

use function gmdate;

use const DATE_RFC7231;

class AssetManagerTest extends TestCase
{
private ResolverStub $resolver;
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/TestDouble/ContainerStub.php
Expand Up @@ -22,18 +22,14 @@ public function __construct(array $map)
}

/**
* @param mixed $id
* @return mixed
*/
public function get($id)
public function get(string $id)
{
return $this->map[$id] ?? null;
}

/**
* @param mixed $id
*/
public function has($id): bool
public function has(string $id): bool
{
return array_key_exists($id, $this->map);
}
Expand Down

0 comments on commit 7445dca

Please sign in to comment.