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

[Batch] Add composer-require-checker CI #44

Merged
merged 12 commits into from
Dec 9, 2022
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
33 changes: 33 additions & 0 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

name: Composer require checker

jobs:
composer-require-checker:
uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 2.0.2 under development

- Enh #41: Add `yiisoft/view` of version `^5.0` and `^6.0` support (@vjik)
- Chg #43: Raise minimum PHP version to `^8.0` (@xepozz, @rustamwin)
- Chg #44: Update version of `yiisoft/view` to `^6.0|^7.0` (@rustamwin)
- Enh #44: Add support `^2.0` version of `psr/container` (@rustamwin)

## 2.0.1 October 25, 2021

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
The package is an extension of the [Yii View Rendering Library](https://github.com/yiisoft/view/). This extension
provides a `ViewRender` that would allow you to use [Twig](https://twig.symfony.com/) view template engine.

## Requirements

- PHP 8.0 or higher.

## Installation

The package could be installed with composer:
Expand Down Expand Up @@ -197,7 +201,7 @@ The default main layout of the [application template](https://github.com/yiisoft
And the view template of the main page (`site/index`) will be as follows:

```twig
{{ this.setTitle(applicationParameters.getName()) }}
{% do this.setTitle(applicationParameters.getName()) %}

<h1 class="title">Hello!</h1>

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
"source": "https://github.com/yiisoft/view-twig"
},
"require": {
"php": "^7.4|^8.0",
"psr/container": "^1.0",
"php": "^8.0",
"psr/container": "^1.0|^2.0",
"twig/twig": "^3.3",
"yiisoft/view": "^4.0|^5.0|^6.0"
"yiisoft/view": "^6.0|^7.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.15",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"vimeo/psalm": "^4.30|^5.1",
"yiisoft/aliases": "^2.0",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/test-support": "^1.3"
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
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);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
8 changes: 2 additions & 6 deletions src/Extensions/YiiTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
*/
final class YiiTwigExtension extends AbstractExtension
{
private ContainerInterface $container;

public function __construct(ContainerInterface $container)
public function __construct(private ContainerInterface $container)
{
$this->container = $container;
}

/**
Expand All @@ -28,8 +25,7 @@ public function getFunctions(): array
return [
new TwigFunction(
'get',
/** @return mixed */
fn (string $id) => $this->container->get($id),
fn (string $id): mixed => $this->container->get($id),
),
];
}
Expand Down
10 changes: 3 additions & 7 deletions src/ViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
*/
final class ViewRenderer implements TemplateRendererInterface
{
private Environment $environment;

public function __construct(Environment $environment)
public function __construct(private Environment $environment)
{
$this->environment = $environment;
}

public function render(ViewInterface $view, string $template, array $parameters): string
Expand All @@ -42,12 +39,11 @@ public function render(ViewInterface $view, string $template, array $parameters)

$obInitialLevel = ob_get_level();
ob_start();
/** @psalm-suppress InvalidArgument */
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
ob_implicit_flush(false);

try {
/** @psalm-suppress PossiblyInvalidFunctionCall */
$renderer->bindTo($view)($template, $parameters);
$renderer->bindTo($view)();
return ob_get_clean();
} catch (Throwable $e) {
while (ob_get_level() > $obInitialLevel) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testExceptionDuringRendering(): void

try {
$renderer->render($view, __DIR__ . '/public/views/error.twig', []);
} catch (RuntimeError $e) {
} catch (RuntimeError) {
}

$this->assertSame(ob_get_level(), $obInitialLevel);
Expand Down