Skip to content

Commit

Permalink
Merge pull request #43 from koriym/drop_php7x
Browse files Browse the repository at this point in the history
Drop support for PHP 7.x and optimize for PHP 8
  • Loading branch information
koriym authored Jan 10, 2023
2 parents 120ae3d + 73b92b1 commit 85fc33d
Show file tree
Hide file tree
Showing 42 changed files with 544 additions and 484 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:

jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@next_stable
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
old_stable: '["7.4", "8.0"]'
current_stable: 8.1
next_stable: 8.2
old_stable: '["8.0", "8.1"]'
current_stable: 8.2
16 changes: 12 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"bear/resource": "^1.15.2",
"bear/sunday": "^1.2",
"bear/app-meta": "^1.1",
"twig/twig": "^2.14 || ^v3.3",
"twig/twig": "^2.15.3 || ^v3.4.3",
"mobiledetect/mobiledetectlib": "^2.7",
"ray/di": "^2.7",
"doctrine/annotations": "^1.13.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5.21",
"squizlabs/php_codesniffer": "^2.8",
"phpmd/phpmd": "^2.6"
"squizlabs/php_codesniffer": "^3.7",
"phpmd/phpmd": "^2.6",
"rector/rector": "^0.15.3",
"ray/rector-ray": "^1.0",
"doctrine/coding-standard": "^11.1"
},
"autoload":{
"psr-4":{
Expand All @@ -48,5 +51,10 @@
"coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"],
"cs-fix": ["phpcbf src tests"]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
104 changes: 87 additions & 17 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,90 @@
<?xml version="1.0"?>
<ruleset>
<!-- 2. General -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength"/>
</rule>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="PEAR.Commenting.FunctionComment">
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="PEAR.Commenting.FunctionComment.Missing"/>
<exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned"/>
<ruleset
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 8.0 -->
<config name="php_version" value="80000"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<!-- Directories to be checked -->
<file>src</file>
<file>tests</file>
<exclude-pattern>*/tests/tmp/*</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 -->
<!-- Base -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="Squiz.Commenting.FunctionComment.InvalidNoReturn"/>
<!-- /Base -->
<!-- Option -->
<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">
<element value="@param, @psalm-param, @phpstan-param"/>
<element value="@return, @psalm-return, @phpstan-return"/>
<element value="@throws"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<include-pattern>tests/*</include-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithoutComment" value="0"/>
</properties>
</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>
43 changes: 43 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use Madapaja\TwigModule\Annotation\TwigDebug;
use Madapaja\TwigModule\Annotation\TwigErrorPath;
use Madapaja\TwigModule\Annotation\TwigLoader;
use Madapaja\TwigModule\Annotation\TwigOptions;
use Madapaja\TwigModule\Annotation\TwigPaths;
use Madapaja\TwigModule\Annotation\TwigRedirectPath;
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Ray\AnnotationBinding\Rector\ClassMethod\AnnotationBindingRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->rule(AnnotationBindingRector::class);
$rectorConfig->ruleWithConfiguration(
AnnotationToAttributeRector::class,
[
new AnnotationToAttribute(TwigDebug::class),
new AnnotationToAttribute(TwigErrorPath::class),
new AnnotationToAttribute(TwigLoader::class),
new AnnotationToAttribute(TwigOptions::class),
new AnnotationToAttribute(TwigPaths::class),
new AnnotationToAttribute(TwigRedirectPath::class),
]
);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80
]);
};
16 changes: 7 additions & 9 deletions src/Annotation/TwigDebug.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Madapaja\TwigModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;

/**
Expand All @@ -17,14 +18,11 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TwigDebug
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
16 changes: 7 additions & 9 deletions src/Annotation/TwigErrorPath.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Madapaja\TwigModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;

/**
Expand All @@ -17,14 +18,11 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TwigErrorPath
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
18 changes: 8 additions & 10 deletions src/Annotation/TwigLoader.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Madapaja\TwigModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;

/**
* @Annotation
* @Target("METHOD")
* @Qualifier
* @NamedArgumentConstructor()
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TwigLoader
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
16 changes: 7 additions & 9 deletions src/Annotation/TwigOptions.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Madapaja\TwigModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;

/**
Expand All @@ -17,14 +18,11 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TwigOptions
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
16 changes: 7 additions & 9 deletions src/Annotation/TwigPaths.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Madapaja\TwigModule\Annotation;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;

/**
Expand All @@ -17,14 +18,11 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
#[Qualifier]
final class TwigPaths
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
Loading

0 comments on commit 85fc33d

Please sign in to comment.