Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump PHP version to ^8.1 and refactor code #130

Merged
merged 8 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.3']
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.2']
['8.3']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
8 changes: 0 additions & 8 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@ jobs:
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
psalm80:
uses: yiisoft/actions/.github/workflows/psalm.yml@master
with:
psalm-config: psalm80.xml
os: >-
['ubuntu-latest']
php: >-
['8.0']
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ composer.phar
# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
# PhpUnit
/phpunit.phar
/phpunit.xml
# phpunit cache
.phpunit.result.cache
/.phpunit.cache
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 7.1.1 under development

- Enh #129: Add support for `yiisoft/view` version `^11` (@vjik)
- Enh #130: Bump PHP version to `^8.1` and refactor code (@vjik)

## 7.1.0 July 01, 2024

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WEB-specific functionality and compatibility with [PSR-7](https://www.php-fig.or

## Requirements

- PHP 8.0 or higher.
- PHP 8.1 or higher.

## Installation

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"psr/container": "^1.0|^2.0",
"yiisoft/aliases": "^2.0|^3.0",
"yiisoft/csrf": "^1.2|^2.0",
Expand All @@ -42,15 +42,15 @@
"httpsoft/http-message": "^1.0",
"maglnet/composer-require-checker": "^4.3",
"nyholm/psr7": "^1.5",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.5",
"rector/rector": "^1.2",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.25",
"yiisoft/di": "^1.2",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/test-support": "^3.0",
"yiisoft/yii-debug": "dev-master|dev-php80"
"yiisoft/yii-debug": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 14 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true">
colors="true"
displayDetailsOnPhpunitDeprecations="true"
>
<php>
<ini name="error_reporting" value="-1"/>
</php>
Expand All @@ -21,9 +23,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
19 changes: 0 additions & 19 deletions psalm80.xml

This file was deleted.

4 changes: 3 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -18,10 +19,11 @@

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
NewInInitializerRector::class,
]);
};
7 changes: 5 additions & 2 deletions src/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

final class Csrf implements Stringable
{
public function __construct(private string $token, private string $parameterName, private string $headerName)
{
public function __construct(
private readonly string $token,
private readonly string $parameterName,
private readonly string $headerName,
) {
}

public function getToken(): string
Expand Down
8 changes: 5 additions & 3 deletions src/Exception/InvalidLinkTagException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use Yiisoft\FriendlyException\FriendlyExceptionInterface;

/**
* InvalidLinkTagException is thrown if the link tag is incorrectly configured during the injection.
* `InvalidLinkTagException` is thrown if the link tag is incorrectly configured during the injection.
*/
final class InvalidLinkTagException extends RuntimeException implements FriendlyExceptionInterface
{
public function __construct(string $message, private mixed $tag)
{
public function __construct(
string $message,
private readonly mixed $tag,
) {
parent::__construct($message);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Exception/InvalidMetaTagException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use Yiisoft\FriendlyException\FriendlyExceptionInterface;

/**
* InvalidMetaTagException is thrown if the meta tag is incorrectly configured during the injection.
* `InvalidMetaTagException` is thrown if the meta tag is incorrectly configured during the injection.
*/
final class InvalidMetaTagException extends RuntimeException implements FriendlyExceptionInterface
{
public function __construct(string $message, private mixed $tag)
{
public function __construct(
string $message,
private readonly mixed $tag,
) {
parent::__construct($message);
}

Expand Down
2 changes: 1 addition & 1 deletion src/InjectionContainer/InjectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class InjectionContainer implements InjectionContainerInterface
{
public function __construct(
private ContainerInterface $container,
private readonly ContainerInterface $container,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/LayoutSpecificInjections.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ final class LayoutSpecificInjections
/**
* @var object[]
*/
private array $injections;
private readonly array $injections;

public function __construct(
private string $layout,
private readonly string $layout,
object ...$injections
) {
$this->injections = $injections;
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/FakeCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class FakeCsrfToken implements CsrfTokenInterface
{
private string $token;
private readonly string $token;

public function __construct(?string $token = null)
{
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/RootNamespace/Fake8Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

final class Fake8Controller
{
}
7 changes: 7 additions & 0 deletions tests/Support/RootNamespace/FakeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

final class FakeController
{
}
25 changes: 14 additions & 11 deletions tests/ViewRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use HttpSoft\Message\ResponseFactory;
use HttpSoft\Message\StreamFactory;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use ReflectionObject;
use RuntimeException;
Expand Down Expand Up @@ -186,10 +187,16 @@ public function testRenderWithLocale(): void
$this->assertSame('<html><body>de_DE locale</body></html>', (string) $response->getBody());
}

public function dataWithController(): array
public static function dataWithController(): array
{
require_once __DIR__ . '/Support/RootNamespace/FakeController.php';
require_once __DIR__ . '/Support/RootNamespace/Fake8Controller.php';

return [
'controller name, no "controller" / "controllers" namespaces, no subnamespaces' => [new Support\FakeController(), '/fake'],
'controller name, no "controller" / "controllers" namespaces, no subnamespaces' => [
new Support\FakeController(),
'/fake',
],
'controller name, "controller" namespace, 1 subnamespace' => [
new Support\Controller\SubNamespace\FakeController(),
'/sub-namespace/fake',
Expand All @@ -211,11 +218,11 @@ public function dataWithController(): array
'/fake',
],
'controller name with root namespace' => [
$this->getMockBuilder('\stdClass')->setMockClassName('FakeController')->getMock(),
new \FakeController(),
'/fake',
],
'controller class contains number' => [
$this->getMockBuilder('\stdClass')->setMockClassName('Fake8Controller')->getMock(),
new \Fake8Controller(),
'/fake8',
],
'namespace contains number' => [
Expand All @@ -233,9 +240,7 @@ public function dataWithController(): array
];
}

/**
* @dataProvider dataWithController
*/
#[DataProvider('dataWithController')]
public function testWithController(object $controller, string $path): void
{
$renderer = $this->getRenderer()->withController($controller);
Expand All @@ -255,7 +260,7 @@ public function testTwiceWithController(): void
$this->assertSame($this->getViewsDir() . '/fake', $renderer->getViewPath());
}

public function dataWithIncorrectController(): array
public static function dataWithIncorrectController(): array
{
return [
'root namespace' => [new stdClass()],
Expand All @@ -267,9 +272,7 @@ public function dataWithIncorrectController(): array
];
}

/**
* @dataProvider dataWithIncorrectController
*/
#[DataProvider('dataWithIncorrectController')]
public function testWithIncorrectController(object $controller): void
{
$this->expectException(RuntimeException::class);
Expand Down
Loading