The update modifies several test classes within the "chill-project" to change non-static class-level variables and methods to static ones. This change has been made to improve readability, performance, and to eliminate unnecessary instantiation of class objects in test scenarios. Also, flush and clear actions on the entity manager are moved to individual data providers.
Implemented additional code to handle version conflicts when editing accompanying period work. By keeping track of the current version and returning an HTTP conflict response when it doesn't match with the provided entity version, users are properly alerted to update their entity before continuing. Furthermore, adjusted BadRequestHttpException to match correct arguments order and introduced entity version as query parameter for the URL.
ensure kernel is shutdown after generating data
Try to add api logic
check for version being the same instead of smaller
implementing optimistic locking and displaying correct message in frontend
rector fixes
adjust violation message and add translation in translation.yaml
add translator in apiController
Replaced most of the invocations of getDoctrine()->getManager() with ManagerRegistry->getManager(), and added ManagerRegistry injection to controllers where needed. This is part of an ongoing effort to improve code clarity, and avoid unnecessary method chaining in various parts of the codebase.
This change is made to comply with the new Symfony standards and to avoid deprecation warnings for future versions. The update touches various functionalities, including retrieving EntityManagerInterface instance and various service classes within the test files.
Removed unnecessary comments and added type hinting to the function parseDate in the AbstractSearch class. Any string passed to this function will now explicitly be expected as a string data type, increasing code robustness and easing debugging process.
En symfony 5.4 le typage a été vraiment amélioré, et phpstan peut détecter plus d'erreur potentielles.
Mais le problème est que Symfony "type" les `User` avec son propre `Symfony\Component\Security\Core\User\UserInterface` alors qu'on a besoin de `Chill\MainBundle\Entity\User`.
Imaginons qu'on a ceci:
```php
namespace Chill\Bundle\Service;
final readonly class SomeService
{
public function myMethod(\Chill\MainBundle\Entity\User $user): void
{
// ...
}
}
```
Quand on l'appelle dans un contrôleur ou dans un service:
```php
namespace Chill\Bundle\Service;
use Symfony\Component\Security\Core\Security;
final readonly OtherService
{
public function __construct(private Security $security, private SomeService $service) {}
public function __invoke(): void
{
$this->service->myMethod($this->security->getUser());
}
}
```
PHPstan va se plaindre:
```
Parameter #1 $user of method SomeService::myMethod() expects Chill\MainBundle\Entity\User, Symfony\Component\Security\Core\User\UserInterface|null given.
```
Du coup, j'ai créé ce service:
```php
<?php
namespace Chill\MainBundle\Security;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Security;
/**
* Security helper for Chill user
*
* Provides security-related functionality such as user retrieval, authorization checks,
* and token retrieval, in a context where only an authenticated @see{User::class} is expected.
*
*/
final readonly class ChillSecurity implements AuthorizationCheckerInterface
{
public function hasUser(): bool
{
// implementation detail not shown here
}
public function getUser(): User
{
// implementation detail not shown here
}
public function isGranted($attribute, $subject = null): bool
{
// implementation detail not shown here
}
public function getToken(): ?TokenInterface
{
// implementation detail not shown here
}
}
```
Et maintenant, on peut faire:
```php
namespace Chill\Bundle\Service;
use Chill\MainBundle\Security\ChillSecurity;
final readonly OtherService
{
public function __construct(private ChillSecurity $security, private SomeService $service) {}
public function __invoke(): void
{
$this->service->myMethod($this->security->getUser());
}
}
```
Et tout va bien se passer.
Ca sera dans la version de chill qui fait passer à symfony 5.4.