Skip to content

Commit

Permalink
Add support for Symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Sep 3, 2024
1 parent c0f24d8 commit c9ea0b5
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 44 deletions.
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;
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"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": ">=8.0",
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:
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,
) {
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
24 changes: 12 additions & 12 deletions src/UrlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
*/
class UrlExtension extends AbstractExtension
{
const DEFAULT_SCHEME = 'http';

const SCHEME = 'scheme';
const USER = 'user';
const PASS = 'pass';
const HOST = 'host';
const PORT = 'port';
const PATH = 'path';
const QUERY = 'query';
const FRAGMENT = 'fragment';

const DEFAULT_FLAGS = [
public const DEFAULT_SCHEME = 'http';

public const SCHEME = 'scheme';
public const USER = 'user';
public const PASS = 'pass';
public const HOST = 'host';
public const PORT = 'port';
public const PATH = 'path';
public const QUERY = 'query';
public const FRAGMENT = 'fragment';

public const DEFAULT_FLAGS = [
self::SCHEME => true,
self::USER => true,
self::PASS => true,
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/ImageExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ public function testIgnoreAdditionalTypesForSvg(): void
$imageExtension = new ImageExtension(null, [], ['webp' => 'image/webp']);

$this->assertSame(
'<img alt="Title"' .
' title="Description"' .
' src="/uploads/media/sulu-100x100/01/image.svg?v=1-0">',
'<img alt="Title"' .
' title="Description"' .
' src="/uploads/media/sulu-100x100/01/image.svg?v=1-0">',
$imageExtension->getImage($this->svgImage, [
'src' => 'sulu-100x100',
])
Expand Down Expand Up @@ -665,7 +665,7 @@ public function testAspectRatioNoProperties(): void
[
'thumbnails' => [
'200x100-inset' => '/uploads/media/200x100-inset/01/image.jpg?v=1-0',
'200x100-inset' . '.webp' => '/uploads/media/200x100-inset/01/image.webp?v=1-0',
'200x100-inset.webp' => '/uploads/media/200x100-inset/01/image.webp?v=1-0',
],
]
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/UrlExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class UrlExtensionTest extends TestCase
{
const URL = 'https://john.doe:[email protected]:8080/admin?resource=pages&limit=20#1234';
private const URL = 'https://john.doe:[email protected]:8080/admin?resource=pages&limit=20#1234';

/**
* @var UrlExtension
Expand Down

0 comments on commit c9ea0b5

Please sign in to comment.