Skip to content

Commit

Permalink
Merge pull request #171 from koriym/drop-php74
Browse files Browse the repository at this point in the history
Drop PHP 7.4 support and optimized for PHP8
  • Loading branch information
koriym authored Nov 21, 2022
2 parents 839b7d9 + e2d7bf9 commit 0e25954
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@next_stable
with:
old_stable: '["7.4", "8.0"]'
old_stable: '["8.0"]'
current_stable: 8.1
next_stable: 8.2
3 changes: 2 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "mixed",
"Doctrine\\Common\\Cache\\ArrayCache", "Doctrine\\Common\\Cache\\Cache"
"Doctrine\\Common\\Cache\\ArrayCache", "Doctrine\\Common\\Cache\\Cache",
"json_decode", "JSON_ERROR_NONE", "json_last_error", "json_last_error_msg"
],
"php-core-extensions" : [
"Core",
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"php": "^8.0",
"bear/resource": "^1.16",
"doctrine/annotations": "^1.12",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"ray/aop": "^2.12.3",
"ray/di": "^2.13"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
"doctrine/coding-standard": "^9.0",
"doctrine/coding-standard": "^10.0",
"phpmd/phpmd": "^2.9",
"phpmetrics/phpmetrics": "^2.7",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^9.5.10",
"psalm/plugin-phpunit": "^0.13",
"ray/rector-ray": "^1.0",
"rector/rector": "^0.14.8",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^4.2"
},
Expand Down Expand Up @@ -85,7 +86,7 @@
"rm -rf tests/tmp/*.php"
],
"sa": [
"./vendor/binpsalm --monochrome --show-info=true",
"./vendor/bin/psalm --monochrome --show-info=true",
"./vendor/bin/phpstan analyse --no-ansi --no-progress -c phpstan.neon"
],
"metrics": "./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src",
Expand Down
41 changes: 28 additions & 13 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="bearcs"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>

<!-- Compatibility with PHP 7.4.0 -->
<config name="php_version" value="70400"/>
<!-- Compatibility with PHP 8.0 -->
<config name="php_version" value="80000"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
Expand All @@ -18,15 +18,24 @@
<file>src</file>
<file>tests</file>
<exclude-pattern>*/tests/tmp/*</exclude-pattern>
<exclude-pattern>*/src/Annotation/*</exclude-pattern>
<exclude-pattern>*/src/Inject/*</exclude-pattern>

<!-- PSR12 Coding Standard -->
<rule ref="PSR12"/>

<!-- Exclude NativeTypeHintrule from interface and abstract class -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
<exclude-pattern>*/src/*Interface.php</exclude-pattern>
<exclude-pattern>*/src/Abstract*.php</exclude-pattern>
<exclude-pattern>*/src/ResourceObject.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<exclude-pattern>*/src/*Interface.php</exclude-pattern>
<exclude-pattern>*/src/Abstract*.php</exclude-pattern>
<exclude-pattern>*/src/ResourceObject.php</exclude-pattern>
</rule>
<!-- Doctrine Coding Standard -->
<rule ref="Doctrine">
<!-- Inapplicable for this project -->
<!-- Inapplicable for this project -->
<!-- Base -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
Expand All @@ -35,20 +44,22 @@
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
<exclude name="Squiz.Commenting.FunctionComment.InvalidNoReturn"/>
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<!-- PHP8 attribute -->
<exclude name="Squiz.WhiteSpace.FunctionSpacing.Before"/>
<!-- <exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>-->
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
<!-- /Option -->
<!-- Exclude Fake files form Doctrine CS -->
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
</rule>

<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
<property name="annotationsGroups" type="array">
Expand All @@ -68,11 +79,15 @@
<property name="maxLinesCountBeforeWithoutComment" value="0"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
<exclude-pattern>src/ClassParam.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>

<exclude-pattern>*/Fake/*</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
phpVersion="7.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="demo/autoload.php"
findUnusedPsalmSuppress="true"
>
Expand Down
29 changes: 29 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Ray\AnnotationBinding\Rector\ClassMethod\AnnotationBindingRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/src-deprecated',
__DIR__ . '/tests',
]);
$rectorConfig->skip([
__DIR__ . '/src/*Interface.php',
__DIR__ . '/tests/Provide/Error/ThrowableHandlerTest.php'
]);

// register a single rule
$rectorConfig->rule(AnnotationBindingRector::class);
$rectorConfig->rule(AnnotationBindingRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80
]);
};
32 changes: 6 additions & 26 deletions src-deprecated/Extension/Application/AbstractApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@
*/
class AbstractApp implements AppInterface
{
/** @var HttpCacheInterface */
public $httpCache;

/** @var RouterInterface */
public $router;

/** @var TransferInterface */
public $responder;

/** @var ResourceInterface */
public $resource;

/** @var ErrorInterface */
public $error;

/**
* @param HttpCacheInterface $httpCache HTTP Cache 304 responder
* @param RouterInterface $router Resource router
Expand All @@ -40,16 +25,11 @@ class AbstractApp implements AppInterface
* @param ErrorInterface $error Error handler
*/
public function __construct(
HttpCacheInterface $httpCache,
RouterInterface $router,
TransferInterface $responder,
ResourceInterface $resource,
ErrorInterface $error
) {
$this->httpCache = $httpCache;
$this->router = $router;
$this->responder = $responder;
$this->resource = $resource;
$this->error = $error;
public HttpCacheInterface $httpCache,
public RouterInterface $router,
public TransferInterface $responder,
public ResourceInterface $resource,
public ErrorInterface $error
){
}
}
9 changes: 3 additions & 6 deletions src/Annotation/DefaultSchemeHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY), Qualifier]
final class DefaultSchemeHost
{
/** @var ?string */
public $value;

public function __construct(?string $value = null)
{
$this->value = $value;
public function __construct(
public string|null $value = null,
) {
}
}
39 changes: 9 additions & 30 deletions src/Extension/Router/RouterMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,18 @@

namespace BEAR\Sunday\Extension\Router;

use Stringable;

use function http_build_query;

class RouterMatch
class RouterMatch implements Stringable
{
/**
* Request method
*
* @var string
*/
public $method;

/**
* Request path
*
* @var string
*/
public $path;

/**
* Request query
*
* @var array<string, mixed>
*/
public $query = [];

/**
* @param array<string, mixed> $query
*/
public function __construct(string $method = '', string $path = '', array $query = [])
{
$this->method = $method;
$this->path = $path;
$this->query = $query;
/** @param array<string, mixed> $query */
public function __construct(
public string $method = '',
public string $path = '',
public array $query = [],
) {
}

public function __toString(): string
Expand Down
13 changes: 4 additions & 9 deletions src/Module/Constant/NamedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@

class NamedModule extends AbstractModule
{
/** @var array<string, string> */
private array $names;

/**
* @param array<string, string> $names
*/
public function __construct(array $names)
{
$this->names = $names;
/** @param array<string, string> $names */
public function __construct(
private array $names,
) {
parent::__construct();
}

Expand Down
8 changes: 3 additions & 5 deletions src/Provide/Error/ThrowableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

final class ThrowableHandler implements ThrowableHandlerInterface
{
private ErrorInterface $error;

public function __construct(ErrorInterface $error)
{
$this->error = $error;
public function __construct(
private ErrorInterface $error,
) {
}

public function handle(Throwable $e, Request $request): ThrowableHandlerInterface
Expand Down
7 changes: 3 additions & 4 deletions src/Provide/Error/VndError.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ final class VndError implements ErrorInterface

/** @var array{message: string} */
public $body = ['message' => ''];
private TransferInterface $transfer;
private ErrorPage $errorPage;

public function __construct(TransferInterface $transfer)
{
$this->transfer = $transfer;
public function __construct(
private TransferInterface $transfer,
) {
$this->errorPage = new ErrorPage();
}

Expand Down
Loading

0 comments on commit 0e25954

Please sign in to comment.