-
-
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
Conversation
cfdcfd5
to
f61b69e
Compare
*/ | ||
public function setDefaultSort(array $sortFieldsAndOrder): self | ||
{ | ||
$sortFieldsAndOrder = array_map('strtoupper', $sortFieldsAndOrder); |
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.
*/ | ||
public function getFieldsInTab(string $tabUniqueId): array | ||
{ | ||
/** @phpstan-ignore-next-line return.type */ |
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.
Class is deprecated, let's avoid this issue.
} | ||
|
||
if (\is_callable($label) && $label instanceof \Closure) { | ||
if (!\is_string($label) && !$label instanceof TranslatableInterface && \is_callable($label)) { |
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.
A bug existed for array-callable ; I added a test.
} | ||
|
||
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())); |
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.
Here and in multiple place, getLabel
is considered as able to be casted to string, but this is not true.
TranslatableInterface does not extends Stringable. Only TranslatableMessage does.
And it's not possible to implement it for enum for instance.
But if someone use his own implementation, it will crash.
Not sure if this fix is enough, or you want to improve/extract logic somewhere else (like a TranslatableHelper::toString method) @javiereguiluz
src/Factory/FormLayoutFactory.php
Outdated
$isTabActive = 0 === \count($tabs); | ||
$tabId = sprintf('tab-%s', $fieldDto->getLabel() ? $slugger->slug(strip_tags($fieldDto->getLabel()))->lower()->toString() : ++$tabsWithoutLabelCounter); | ||
$label = $fieldDto->getLabel(); | ||
$tabId = sprintf( |
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.
Same issue with TranslatableInterface
src/Factory/MenuFactory.php
Outdated
if (null === $entityFqcn && null === $crudControllerFqcn) { | ||
throw new \RuntimeException(sprintf('The CRUD menu item with label "%s" must define either the entity FQCN (using the third constructor argument) or the CRUD Controller FQCN (using the "setController()" method).', $menuItemDto->getLabel())); | ||
$label = $menuItemDto->getLabel(); | ||
$labelAsString = (\is_string($label) || $label instanceof Stringable) ? (string) $label : ''; |
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.
Same issue with TranslatableInterface
src/Form/Type/CrudFormType.php
Outdated
$currentFormTab = (string) $fieldDto->getLabel(); | ||
|
||
$label = $fieldDto->getLabel(); | ||
$currentFormTab = (\is_string($label) || $label instanceof Stringable) ? (string) $label : ''; |
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.
Same issue with TranslatableInterface
|
||
$index = 1; | ||
$pathInfo = pathinfo($filename); | ||
while (file_exists($filename = sprintf('%s/%s_%d.%s', $pathInfo['dirname'], $pathInfo['filename'], $index, $pathInfo['extension']))) { |
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.
dirname
and extension
might theorically not exists.
I handle the case.
include $filePath; | ||
|
||
return ob_get_clean(); | ||
return (string) ob_get_clean(); |
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.
Can technically be false, but not in our case, let's just ignore this by casting it
|
||
if (null !== $idClassType) { | ||
/** @var \ReflectionNamedType|\ReflectionUnionType $idClassType */ | ||
if ($idClassType instanceof \ReflectionNamedType) { |
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.
ReflectionUnionType::getName does not exists
f61b69e
to
58346f9
Compare
This includes the PR #6999 which should be reviewed and merged first.
This show how I'm able to solve every phpstan issue after the merge @javiereguiluz