phpstan
This commit is contained in:
@@ -31,5 +31,7 @@ Do not use method chaining: all fluent interface, especially in Entities, are no
|
||||
- Removed `User::isExportDecimal()`
|
||||
- Use duration format `HH:mm` in default PDF exports
|
||||
- Replace Twig `AppVariable` with custom implementation
|
||||
- Replace `app.request.locale` with `app.locale`
|
||||
- Replace `app.request.attributes.get('_route')` with `app.current_route`
|
||||
- You need to adjust your templates if you access anything else then `app.locale`, `app.user`. `app.current_route`.
|
||||
- Most often used:
|
||||
- Replace `app.request.locale` with `app.locale`
|
||||
- Replace `app.request.attributes.get('_route')` with `app.current_route`
|
||||
|
||||
26
phpstan.neon
26
phpstan.neon
@@ -3345,34 +3345,24 @@ parameters:
|
||||
path: src/Twig/Context.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\DatatableExtensions\\:\\:checkInColumDefinition\\(\\) has parameter \\$columns with no value type specified in iterable type array\\.$#"
|
||||
message: "#^Method App\\\\Twig\\\\Runtime\\\\DatatableExtensions\\:\\:checkInColumDefinition\\(\\) has parameter \\$columns with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
path: src/Twig/Runtime/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\DatatableExtensions\\:\\:getClass\\(\\) has parameter \\$class with no type specified\\.$#"
|
||||
message: "#^Method App\\\\Twig\\\\Runtime\\\\DatatableExtensions\\:\\:getDatatableColumnClass\\(\\) should return string but returns bool\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
path: src/Twig/Runtime/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\DatatableExtensions\\:\\:getDatatableColumnClass\\(\\) should return string but returns bool\\|string\\.$#"
|
||||
message: "#^Method App\\\\Twig\\\\Runtime\\\\DatatableExtensions\\:\\:initializeDatatable\\(\\) has parameter \\$defaultColumns with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
path: src/Twig/Runtime/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\DatatableExtensions\\:\\:initializeDatatable\\(\\) has parameter \\$defaultColumns with no value type specified in iterable type array\\.$#"
|
||||
message: "#^Method App\\\\Twig\\\\Runtime\\\\DatatableExtensions\\:\\:initializeDatatable\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\DatatableExtensions\\:\\:initializeDatatable\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Property App\\\\Twig\\\\DatatableExtensions\\:\\:\\$tableNames type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: src/Twig/DatatableExtensions.php
|
||||
path: src/Twig/Runtime/DatatableExtensions.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Twig\\\\Extensions\\:\\:replaceNewline\\(\\) has no return type specified\\.$#"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
@@ -20,7 +21,10 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
*/
|
||||
final class AppVariable
|
||||
{
|
||||
public function __construct(private readonly RequestStack $requestStack, private readonly TokenStorageInterface $tokenStorage)
|
||||
public function __construct(
|
||||
private readonly RequestStack $requestStack,
|
||||
private readonly TokenStorageInterface $tokenStorage
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,12 +40,20 @@ final class AppVariable
|
||||
|
||||
public function getCurrent_route(): ?string
|
||||
{
|
||||
return $this->requestStack->getCurrentRequest()->attributes->get('_route');
|
||||
$route = $this->requestStack->getCurrentRequest()?->attributes->get('_route');
|
||||
if (!\is_string($route)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string[]>
|
||||
*/
|
||||
public function getFlashes(): array
|
||||
{
|
||||
$session = $this->getSession2();
|
||||
$session = $this->getSession();
|
||||
|
||||
if (!$session instanceof FlashBagAwareSessionInterface) {
|
||||
return [];
|
||||
@@ -50,13 +62,11 @@ final class AppVariable
|
||||
return $session->getFlashBag()->all();
|
||||
}
|
||||
|
||||
private function getSession2(): ?SessionInterface
|
||||
private function getSession(): ?SessionInterface
|
||||
{
|
||||
try {
|
||||
if (null !== $session = $this->requestStack->getSession()) {
|
||||
return $session;
|
||||
}
|
||||
} catch (\RuntimeException) {
|
||||
return $this->requestStack->getSession();
|
||||
} catch (SessionNotFoundException) {
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -65,6 +75,8 @@ final class AppVariable
|
||||
/**
|
||||
* The request should not be exposed under any circumstance to the frontend.
|
||||
* This here is added as fallback for old customer templates still using this object.
|
||||
*
|
||||
* @return array{locale: string}
|
||||
*/
|
||||
public function getRequest(): array
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ final class DatatableExtensions implements RuntimeExtensionInterface
|
||||
* @var array<string, array<string, array<string, string|bool>>>
|
||||
*/
|
||||
private array $dataTables = [];
|
||||
/** @var array<string, string> */
|
||||
private array $tableNames = [];
|
||||
private ?string $prefix = null;
|
||||
|
||||
@@ -167,7 +168,7 @@ final class DatatableExtensions implements RuntimeExtensionInterface
|
||||
return $newClass;
|
||||
}
|
||||
|
||||
private function getClass($class): string
|
||||
private function getClass(mixed $class): string
|
||||
{
|
||||
if (\is_array($class)) {
|
||||
if (!\array_key_exists('class', $class)) {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
namespace App\Utils;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
final class ProfileManager
|
||||
@@ -72,7 +71,7 @@ final class ProfileManager
|
||||
/**
|
||||
* Always returns a valid profile name (default: desktop).
|
||||
*/
|
||||
public function getProfileFromSession(Session $session): string
|
||||
public function getProfileFromSession(SessionInterface $session): string
|
||||
{
|
||||
$profile = $session->get(self::SESSION_PROFILE, self::PROFILE_DESKTOP);
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
namespace App\Tests\Twig\Runtime;
|
||||
|
||||
use App\Repository\BookmarkRepository;
|
||||
use App\Twig\Runtime\DatatableExtensions;
|
||||
use App\Utils\ProfileManager;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
#[CoversClass(DatatableExtensions::class)]
|
||||
class DatatableExtensionsTest extends TestCase
|
||||
@@ -23,7 +23,7 @@ class DatatableExtensionsTest extends TestCase
|
||||
{
|
||||
$repository = $this->createMock(BookmarkRepository::class);
|
||||
|
||||
return new DatatableExtensions($repository, new ProfileManager(), new Session());
|
||||
return new DatatableExtensions($repository, new ProfileManager(), new RequestStack());
|
||||
}
|
||||
|
||||
public function testGetFunctions(): void
|
||||
@@ -50,6 +50,8 @@ class RuntimeExtensionsTest extends TestCase
|
||||
'icon',
|
||||
'qr_code_data_uri',
|
||||
'user_shortcuts',
|
||||
'initialize_datatable',
|
||||
'datatable_column_class'
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
|
||||
Reference in New Issue
Block a user