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

Add symfony 7 support #50

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 16 additions & 5 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,29 @@ jobs:
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.3'
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: ${{ matrix.tools }}

- name: Remove Lint Tools
# These tools are not required to run tests, so we are removing them to improve dependency resolving and
# testing lowest versions.
run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependency-versions }}

Expand All @@ -59,16 +70,16 @@ jobs:

steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3
tools: composer

- name: Install composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2

- name: Lint code
run: composer lint
29 changes: 19 additions & 10 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
with this source code in the file LICENSE.
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
$finder = PhpCsFixer\Finder::create()
->exclude(['vendor'])
->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'ordered_imports' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'phpdoc_align' => false,
'class_definition' => [
'multiLineExtendsEachSingleLine' => true,
],
'class_definition' => false,
'linebreak_after_opening_tag' => true,
'declare_strict_types' => true,
'mb_str_functions' => false,
Expand All @@ -35,9 +37,16 @@
'strict_comparison' => true,
'strict_param' => true,
'header_comment' => ['header' => $header],
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => false,
'get_class_to_class_keyword' => false, // should be enabled as soon as support for php < 8 is dropped
'nullable_type_declaration_for_default_null_value' => true,
'no_null_property_initialization' => false,
'fully_qualified_strict_types' => false,
'new_with_parentheses' => true,
'modernize_strpos' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
);
->setFinder($finder);

return $config;
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
"twig/twig": "^1.38 || ^2.7 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.11",
"jangregor/phpstan-prophecy": "^0.8",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"php-cs-fixer/shim": "^3.64",
"jangregor/phpstan-prophecy": "^1.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.5",
"symfony/intl": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/property-access": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"thecodingmachine/phpstan-strict-rules": "^0.12"
"symfony/property-access": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"thecodingmachine/phpstan-strict-rules": "^1.0"
},
"conflict": {
"symfony/intl": ">=7.0",
"symfony/property-access": ">=7.0"
"symfony/intl": ">=8.0",
"symfony/property-access": ">=8.0"
},
"suggest": {
"symfony/property-access": "The ImageExtension requires the symfony/property-access service.",
Expand Down
34 changes: 34 additions & 0 deletions docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ This could be:
) }}
```

Retina example:

```twig
<img alt="Title"
title="Description"
src="/uploads/media/452x452/01/image.jpg?v=1-0"
srcset="/uploads/media/452x452/01/image.jpg?v=1-0 1x, /uploads/media/452x452@2x/01/image.jpg?v=1-0 2x">
```

This could be:

```twig
{{ get_image(image,
Prokyonn marked this conversation as resolved.
Show resolved Hide resolved
{
src: '452x452',
srcset: '452x452 1x, 452x452@2x 2x',
}
) }}
```

##### 5. Lazy images

> See also 6. Native lazy loading for a modern implementation.
Expand Down Expand Up @@ -197,6 +217,20 @@ services:
loading: 'lazy'
```

If you are setting the default to lazy which is recommended you maybe want the
first image of hero slider be loaded immediately this can be achieved via
setting `loading` to `null` for the first element:

```twig
{% for image in images %}
{{ get_image(image, {
src: '452x452',
srcset: '452x452 1x, 452x452@2x 2x',
loading: loop.first ? null : 'lazy',
}) }}
{% endfor %}
```

##### 7. Webp Support

If your server supports converting images to webp you can automatically enable webp
Expand Down
151 changes: 151 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
parameters:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update phpstan to ^1

ignoreErrors:
-
message: "#^Cannot access offset 'className' on mixed\\.$#"
count: 2
path: src/IconExtension.php

-
message: "#^Cannot access offset 'classPrefix' on mixed\\.$#"
count: 2
path: src/IconExtension.php

-
message: "#^Cannot access offset 'classSuffix' on mixed\\.$#"
count: 2
path: src/IconExtension.php

-
message: "#^Cannot access offset 'path' on mixed\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Cannot access offset 'type' on mixed\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Method Sulu\\\\Twig\\\\Extensions\\\\IconExtension\\:\\:getIconSet\\(\\) should return array but returns mixed\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Parameter \\#4 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Parameter \\#6 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: src/IconExtension.php

-
message: "#^Cannot access offset 'height' on mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Cannot access offset 'media' on mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Cannot access offset 'srcset' on mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Cannot access offset 'type' on mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Cannot access offset 'width' on mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:getMimeType\\(\\) should return string but returns mixed\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Offset 'filename' on array\\{dirname\\?\\: string, basename\\: string, extension\\?\\: string, filename\\: string\\} on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$array of function reset expects array\\|object, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:getValue\\(\\) expects array\\|object, mixed given\\.$#"
count: 6
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:isReadable\\(\\) expects array\\|object, mixed given\\.$#"
count: 3
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$path of function pathinfo expects string, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$srcsets of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:addExtension\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\$thumbnails of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:getLazyThumbnails\\(\\) expects array\\<string, string\\>, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#2 \\$attributes of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:createTag\\(\\) expects array\\<string, string\\|null\\>, array given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#2 \\$attributes of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:createTag\\(\\) expects array\\<string, string\\|null\\>, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
count: 1
path: src/ImageExtension.php

-
message: "#^Parameter \\#3 \\$thumbnails of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:createTag\\(\\) expects array\\<string\\>, mixed given\\.$#"
count: 3
path: src/ImageExtension.php

-
message: "#^Parameter \\#5 \\$additionalTypes of method Sulu\\\\Twig\\\\Extensions\\\\ImageExtension\\:\\:createImage\\(\\) expects array\\<string\\>, array given\\.$#"
count: 2
path: src/ImageExtension.php

-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/PortalExtension.php

-
message: "#^Cannot access an offset on mixed\\.$#"
count: 1
path: src/PortalExtension.php
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
includes:
- phpstan-baseline.neon
- vendor/jangregor/phpstan-prophecy/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand All @@ -10,7 +11,7 @@ parameters:
- src
- tests
inferPrivatePropertyTypeFromConstructor: true
excludes_analyse:
excludePaths:
- %currentWorkingDirectory%/vendor/*
ignoreErrors:
- '#Call to an undefined static method Symfony\\Component\\Intl\\Intl#'
4 changes: 2 additions & 2 deletions src/IconExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/
class IconExtension extends AbstractExtension
{
const ICON_SET_TYPE_SVG = 'svg';
const ICON_SET_TYPE_FONT = 'font';
public const ICON_SET_TYPE_SVG = 'svg';
public const ICON_SET_TYPE_FONT = 'font';

/**
* @var mixed[]
Expand Down
4 changes: 2 additions & 2 deletions src/ImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(
array $defaultAttributes = [],
array $defaultAdditionalTypes = [],
bool $aspectRatio = false,
array $imageFormatConfiguration = null
?array $imageFormatConfiguration = null,
Prokyonn marked this conversation as resolved.
Show resolved Hide resolved
) {
if (null !== $placeholderPath) {
$this->placeholderPath = rtrim($placeholderPath, '/') . '/';
Expand Down Expand Up @@ -193,7 +193,7 @@ private function createImage(
$attributes = [],
array $sources = [],
?array $lazyThumbnails = null,
array $additionalTypes = []
array $additionalTypes = [],
): string {
// Return an empty string if no one of the needed parameters is set.
if (empty($media) || empty($attributes)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/PortalNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PortalNode extends Node
/**
* @param Node<Node> $body
*/
public function __construct(string $name, Node $body, int $lineno, string $tag = null)
public function __construct(string $name, Node $body, int $lineno, ?string $tag = null)
{
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
}
Expand Down
Loading
Loading