-
- Notifications
You must be signed in to change notification settings - Fork 1.1k
Bump PHPStan to level 7 #7026
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
base: 4.x
Are you sure you want to change the base?
Bump PHPStan to level 7 #7026
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2,7 +2,7 @@ includes: | |
| - phpstan-baseline.neon | ||
| | ||
| parameters: | ||
| level: 6 | ||
| level: 7 | ||
| paths: | ||
| - src/ | ||
| excludePaths: | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -59,6 +59,7 @@ public function getFields(): array | |
| */ | ||
| public function getFieldsInTab(string $tabUniqueId): array | ||
| { | ||
| /** @phpstan-ignore-next-line return.type */ | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class is deprecated, let's avoid this issue. | ||
| return $this->fields[$tabUniqueId] ?? []; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -36,7 +36,7 @@ public function processEntityActions(EntityDto $entityDto, ActionConfigDto $acti | |
| { | ||
| $currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage(); | ||
| $entityActions = []; | ||
| foreach ($actionsDto->getActions()->all() as $actionDto) { | ||
| foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) { | ||
| if (!$actionDto->isEntityAction()) { | ||
| continue; | ||
| } | ||
| | @@ -79,7 +79,7 @@ public function processGlobalActions(?ActionConfigDto $actionsDto = null): Actio | |
| | ||
| $currentPage = $this->adminContextProvider->getContext()->getCrud()->getCurrentPage(); | ||
| $globalActions = []; | ||
| foreach ($actionsDto->getActions()->all() as $actionDto) { | ||
| foreach ($actionsDto->getPageActions($currentPage)->all() as $actionDto) { | ||
| if (!$actionDto->isGlobalAction() && !$actionDto->isBatchAction()) { | ||
| continue; | ||
| } | ||
| | @@ -171,7 +171,7 @@ private function processActionLabel(ActionDto $actionDto, ?EntityDto $entityDto, | |
| return; | ||
| } | ||
| | ||
| if (\is_callable($label) && $label instanceof \Closure) { | ||
| if (!\is_string($label) && !$label instanceof TranslatableInterface && \is_callable($label)) { | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bug existed for array-callable ; I added a test. | ||
| $label = \call_user_func_array($label, array_filter([$entityDto?->getInstance()], static fn ($item): bool => null !== $item)); | ||
| | ||
| if (!\is_string($label) && !$label instanceof TranslatableInterface) { | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -16,6 +16,7 @@ | |
| use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneCloseType; | ||
| use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneGroupCloseType; | ||
| use EasyCorp\Bundle\EasyAdminBundle\Form\Type\Layout\EaFormTabPaneGroupOpenType; | ||
| use Stringable; | ||
| use Symfony\Component\String\Slugger\AsciiSlugger; | ||
| use Symfony\Component\Uid\Ulid; | ||
| | ||
| | @@ -78,7 +79,10 @@ private function validateLayoutConfiguration(FieldCollection $fields): void | |
| } | ||
| | ||
| if ($theFirstFieldWhichIsATabOrColumn->isFormColumn() && $fieldDto->isFormTab()) { | ||
| throw new \InvalidArgumentException(sprintf('When using form columns, you can\'t define tabs inside columns (but you can define columns inside tabs). Move the tab "%s" outside any column.', $fieldDto->getLabel())); | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and in multiple place, TranslatableInterface does not extends Stringable. Only TranslatableMessage does. Not sure if this fix is enough, or you want to improve/extract logic somewhere else (like a TranslatableHelper::toString method) @javiereguiluz | ||
| $label = $fieldDto->getLabel(); | ||
| $labelAsString = (\is_string($label) || $label instanceof \Stringable) ? (string) $label : ''; | ||
| | ||
| throw new \InvalidArgumentException(sprintf('When using form columns, you can\'t define tabs inside columns (but you can define columns inside tabs). Move the tab "%s" outside any column.', $labelAsString)); | ||
| } | ||
| } | ||
| } | ||
| | @@ -181,7 +185,9 @@ private function linearizeLayoutConfiguration(FieldCollection $fields): void | |
| | ||
| if ($fieldDto->isFormTab()) { | ||
| $isTabActive = 0 === \count($tabs); | ||
| $tabId = sprintf('tab-%s', $fieldDto->getLabel() ? $slugger->slug(strip_tags($fieldDto->getLabel()))->lower()->toString() : ++$tabsWithoutLabelCounter); | ||
| $label = $fieldDto->getLabel(); | ||
| $labelAsString = (\is_string($label) || $label instanceof Stringable) ? (string) $label : ''; | ||
| $tabId = sprintf('tab-%s', '' !== $labelAsString ? $slugger->slug(strip_tags($labelAsString))->lower()->toString() : ++$tabsWithoutLabelCounter); | ||
| $fieldDto->setCustomOption(FormField::OPTION_TAB_ID, $tabId); | ||
| $fieldDto->setCustomOption(FormField::OPTION_TAB_IS_ACTIVE, $isTabActive); | ||
| | ||
| | @@ -395,6 +401,7 @@ public static function createFromFieldDtos(?FieldCollection $fieldDtos): FieldLa | |
| $tabs[$fieldDto->getUniqueId()] = $fieldDto; | ||
| } else { | ||
| if ($hasTabs) { | ||
| /** @phpstan-ignore-next-line offsetAccess.nonOffsetAccessible */ | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method is deprecated, let's just ignore the error | ||
| $fields[$currentTab->getUniqueId()][] = $fieldDto; | ||
| } else { | ||
| $fields[] = $fieldDto; | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -96,7 +96,10 @@ public function configureOptions(OptionsResolver $resolver): void | |
| | ||
| $index = 1; | ||
| $pathInfo = pathinfo($filename); | ||
| while (file_exists($filename = sprintf('%s/%s_%d.%s', $pathInfo['dirname'], $pathInfo['filename'], $index, $pathInfo['extension']))) { | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I handle the case. | ||
| | ||
| $basePath = isset($pathInfo['dirname']) ? sprintf('%s/%s', $pathInfo['dirname'], $pathInfo['filename']) : $pathInfo['filename']; | ||
| $endPath = isset($pathInfo['extension']) ? '.'.$pathInfo['extension'] : ''; | ||
| while (file_exists($filename = sprintf('%s_%d%s', $basePath, $index, $endPath))) { | ||
| ++$index; | ||
| } | ||
| | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -62,6 +62,6 @@ private function renderSkeleton(string $filePath, array $parameters): string | |
| extract($parameters, \EXTR_SKIP); | ||
| include $filePath; | ||
| | ||
| return ob_get_clean(); | ||
| return (string) ob_get_clean(); | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can technically be false, but not in our case, let's just ignore this by casting it | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -230,6 +230,7 @@ private function addFilterClause(QueryBuilder $queryBuilder, SearchDto $searchDt | |
| 'value' => $submittedData, | ||
| ]; | ||
| } | ||
| /** @var array{comparison: string, value: mixed, value2?: mixed} $submittedData */ | ||
| | ||
| /** @var string $rootAlias */ | ||
| $rootAlias = current($queryBuilder->getRootAliases()); | ||
| | @@ -328,7 +329,6 @@ private function getSearchablePropertiesConfig(QueryBuilder $queryBuilder, Searc | |
| : $entityDto->getFqcn() | ||
| ; | ||
| | ||
| /** @var \ReflectionNamedType|\ReflectionUnionType|null $idClassType */ | ||
| $idClassType = null; | ||
| $reflectionClass = new \ReflectionClass($entityFqcn); | ||
| | ||
| | @@ -342,8 +342,7 @@ private function getSearchablePropertiesConfig(QueryBuilder $queryBuilder, Searc | |
| $reflectionClass = $reflectionClass->getParentClass(); | ||
| } | ||
| | ||
| if (null !== $idClassType) { | ||
| /** @var \ReflectionNamedType|\ReflectionUnionType $idClassType */ | ||
| if ($idClassType instanceof \ReflectionNamedType) { | ||
| Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReflectionUnionType::getName does not exists | ||
| $idClassName = $idClassType->getName(); | ||
| | ||
| if (class_exists($idClassName)) { | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is small phpstan issue with array_map.
PHPStan is loosing some informations about
sortFieldsAndOrder; I fixed it on PHPStan side. But anyway, I feel like it's better to include the strtoupper in the foreach in order to have one loop instead of two.