Skip to content

Commit 260223b

Browse files
committed
minor #6996 Improve some phpdoc thanks to phpstan (VincentLanglet)
This PR was merged into the 4.x branch. Discussion ---------- Improve some phpdoc thanks to phpstan Commits ------- 5e93713 Improve phpdoc
2 parents 2b95dc1 + 5e93713 commit 260223b

File tree

9 files changed

+51
-7
lines changed

9 files changed

+51
-7
lines changed

src/Dto/CrudDto.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class CrudDto
2222
private ?string $actionName = null;
2323
private ?ActionConfigDto $actionConfigDto = null;
2424
private ?FilterConfigDto $filters = null;
25+
/** @var class-string|null */
2526
private ?string $entityFqcn = null;
2627
/** @var TranslatableInterface|string|callable|null */
2728
private $entityLabelInSingular;
@@ -111,11 +112,17 @@ public function setFieldAssets(AssetsDto $assets): void
111112
$this->fieldAssetsDto = $assets;
112113
}
113114

115+
/**
116+
* @return class-string
117+
*/
114118
public function getEntityFqcn(): string
115119
{
116120
return $this->entityFqcn;
117121
}
118122

123+
/**
124+
* @param class-string $entityFqcn
125+
*/
119126
public function setEntityFqcn(string $entityFqcn): void
120127
{
121128
$this->entityFqcn = $entityFqcn;

src/Event/BeforeEntityUpdatedEvent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
/**
66
* @author Javier Eguiluz <[email protected]>
7+
*
8+
* @template TEntity of object
9+
*
10+
* @extends AbstractLifecycleEvent<TEntity>
711
*/
812
final class BeforeEntityUpdatedEvent extends AbstractLifecycleEvent
913
{

src/EventListener/AdminRouterSubscriber.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ public function onKernelController(ControllerEvent $event): void
250250
* Because of how EasyAdmin works, all backend requests are handled via the
251251
* Dashboard controller, so its enough to check if the request controller implements
252252
* the DashboardControllerInterface.
253+
*
254+
* @return class-string|null
253255
*/
254256
private function getDashboardControllerFqcn(Request $request): ?string
255257
{

src/Factory/ControllerFactory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ private function getCrudController(?string $crudControllerFqcn, ?string $crudAct
4444
return $this->getController(CrudControllerInterface::class, $crudControllerFqcn, $crudAction, $request);
4545
}
4646

47+
/**
48+
* @template T of object
49+
*
50+
* @param class-string<T> $controllerInterface
51+
*
52+
* @return T|null
53+
*/
4754
private function getController(string $controllerInterface, ?string $controllerFqcn, ?string $controllerAction, Request $request): ?object
4855
{
4956
if (null === $controllerFqcn || null === $controllerAction) {
@@ -68,6 +75,9 @@ private function getController(string $controllerInterface, ?string $controllerF
6875
}
6976

7077
$controllerInstance = $controllerCallable[0];
78+
if (!\is_object($controllerInstance)) {
79+
return null;
80+
}
7181

7282
return is_subclass_of($controllerInstance, $controllerInterface) ? $controllerInstance : null;
7383
}

src/Factory/EntityFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ private function doCreate(?string $entityFqcn = null, mixed $entityId = null, st
143143
return $entityDto;
144144
}
145145

146+
/**
147+
* @param class-string $entityFqcn
148+
*/
146149
private function getEntityManager(string $entityFqcn): ObjectManager
147150
{
148151
if (null === $entityManager = $this->doctrine->getManagerForClass($entityFqcn)) {
@@ -171,6 +174,10 @@ private function getEntityInstance(string $entityFqcn, mixed $entityIdValue): ob
171174
* Code copied from Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser
172175
* because Doctrine ORM 3.x removed the ClassUtil class where this method was defined
173176
* (c) Fabien Potencier <[email protected]> - MIT License.
177+
*
178+
* @param class-string $class
179+
*
180+
* @return class-string
174181
*/
175182
private function getRealClass(string $class): string
176183
{

src/Field/Configurator/ImageConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
5353
}
5454
$relativeUploadDir = u($relativeUploadDir)->trimStart(\DIRECTORY_SEPARATOR)->ensureEnd(\DIRECTORY_SEPARATOR)->toString();
5555
$isStreamWrapper = filter_var($relativeUploadDir, \FILTER_VALIDATE_URL);
56-
if ($isStreamWrapper) {
56+
if (false !== $isStreamWrapper) {
5757
$absoluteUploadDir = $relativeUploadDir;
5858
} else {
5959
$absoluteUploadDir = u($relativeUploadDir)->ensureStart($this->projectDir.\DIRECTORY_SEPARATOR)->toString();

src/Form/Type/FileUploadType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ public function configureOptions(OptionsResolver $resolver): void
145145
}
146146

147147
$isStreamWrapper = filter_var($value, \FILTER_VALIDATE_URL);
148-
if (!$isStreamWrapper && !str_starts_with($value, $this->projectDir)) {
148+
if (false !== $isStreamWrapper && !str_starts_with($value, $this->projectDir)) {
149149
$value = $this->projectDir.'/'.$value;
150150
}
151151

152-
if (!$isStreamWrapper && (!is_dir($value) || !is_writable($value))) {
152+
if (false !== $isStreamWrapper && (!is_dir($value) || !is_writable($value))) {
153153
throw new InvalidArgumentException(sprintf('Invalid upload directory "%s" it does not exist or is not writable.', $value));
154154
}
155155

src/Resources/bin/logical-css-properties-linter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function lintFileCssProperties(string $file, array $logicalCssProperties): int
102102
}
103103

104104
$pattern = '/(?<!-)\b'.preg_quote($forbidden, '/').'\s*:/';
105-
if (preg_match($pattern, $line)) {
105+
if (1 === preg_match($pattern, $line)) {
106106
echo sprintf("File: %s\n", $file);
107107
echo sprintf("Line: %d\n", $lineNumber + 1);
108108
echo sprintf("Issue: you can't use the property '%s' because it's not safe for different writing systems; use instead the logical property '%s'\n", $forbidden, $alternative);

src/Router/AdminRouteGenerator.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminCrud;
77
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
88
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
9+
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
10+
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
911
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Router\AdminRouteGeneratorInterface;
1012
use Psr\Cache\CacheItemPoolInterface;
1113
use Symfony\Component\Filesystem\Filesystem;
@@ -215,7 +217,7 @@ private function getDefaultRoutesConfig(string $dashboardFqcn): array
215217
throw new \RuntimeException(sprintf('In the #[AdminDashboard] attribute of the "%s" dashboard controller, the route configuration for the "%s" action defines some unsupported keys. You can only define these keys: "routePath" and "routeName".', $dashboardFqcn, $action));
216218
}
217219

218-
if (isset($customRouteConfig['routeName']) && !preg_match('/^[a-zA-Z0-9_-]+$/', $customRouteConfig['routeName'])) {
220+
if (isset($customRouteConfig['routeName']) && 1 !== preg_match('/^[a-zA-Z0-9_-]+$/', $customRouteConfig['routeName'])) {
219221
throw new \RuntimeException(sprintf('In the #[AdminDashboard] attribute of the "%s" dashboard controller, the route name "%s" for the "%s" action is not valid. It can only contain letter, numbers, dashes, and underscores.', $dashboardFqcn, $customRouteConfig['routeName'], $action));
220222
}
221223

@@ -298,6 +300,11 @@ private function getDashboardsRouteConfig(): array
298300
return $config;
299301
}
300302

303+
/**
304+
* @param class-string<CrudControllerInterface> $crudControllerFqcn
305+
*
306+
* @return array{routeName: string, routePath: string}
307+
*/
301308
private function getCrudControllerRouteConfig(string $crudControllerFqcn): array
302309
{
303310
$crudControllerConfig = [];
@@ -320,7 +327,7 @@ private function getCrudControllerRouteConfig(string $crudControllerFqcn): array
320327
}
321328

322329
if (null !== $attributeInstance->routeName) {
323-
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $attributeInstance->routeName)) {
330+
if (1 !== preg_match('/^[a-zA-Z0-9_-]+$/', $attributeInstance->routeName)) {
324331
throw new \RuntimeException(sprintf('In the #[AdminCrud] attribute of the "%s" CRUD controller, the route name "%s" is not valid. It can only contain letter, numbers, dashes, and underscores.', $crudControllerFqcn, $attributeInstance->routeName));
325332
}
326333

@@ -340,6 +347,11 @@ private function getCrudControllerRouteConfig(string $crudControllerFqcn): array
340347
return $crudControllerConfig;
341348
}
342349

350+
/**
351+
* @param class-string<CrudControllerInterface> $crudControllerFqcn
352+
*
353+
* @return array<string, array{routeName?: string, routePath?: string, methods?: array<string>}>
354+
*/
343355
private function getCustomActionsConfig(string $crudControllerFqcn): array
344356
{
345357
$customActionsConfig = [];
@@ -370,7 +382,7 @@ private function getCustomActionsConfig(string $crudControllerFqcn): array
370382
}
371383

372384
if (null !== $attributeInstance->routeName) {
373-
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $attributeInstance->routeName)) {
385+
if (1 !== preg_match('/^[a-zA-Z0-9_-]+$/', $attributeInstance->routeName)) {
374386
throw new \RuntimeException(sprintf('In the "%s" CRUD controller, the #[AdminAction] attribute applied to the "%s()" action defines an invalid route name: "%s". Valid route names can only contain letters, numbers, dashes, and underscores.', $crudControllerFqcn, $action, $attributeInstance->routeName));
375387
}
376388

@@ -397,6 +409,8 @@ private function getCustomActionsConfig(string $crudControllerFqcn): array
397409
}
398410

399411
/**
412+
* @param class-string<DashboardControllerInterface> $dashboardFqcn
413+
*
400414
* @return array{routeName: string, route: Route}|null
401415
*/
402416
private function createDashboardRoute(string $dashboardFqcn): ?array

0 commit comments

Comments
 (0)