-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Raise phpstan to max level #1386
Conversation
@@ -50,6 +50,12 @@ public function buildField(?string $type, FieldDescriptionInterface $fieldDescri | |||
{ | |||
if (null === $type) { | |||
$guessType = $this->guesser->guess($fieldDescription); | |||
if (null === $guessType) { |
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.
If every time we are returning null we throw an exception, wouldnt it be better to only return non null values or throw exception inside the guesser?
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.
I made sonata-project/SonataAdminBundle#6987 because the TypeGuesserChain could return null...
If you have a TypeGuesserChain with no guesser how can you return a type ?
And the Guesser interface from Symfony was allowing null
as return type...
The Guesser from this bundle never return null, but just in case, I added the exception...
@@ -39,16 +39,21 @@ public function __construct(Environment $twig, AuditReader $auditReader) | |||
|
|||
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response | |||
{ | |||
$template = $blockContext->getTemplate(); | |||
\assert(null !== $template); | |||
$limit = $blockContext->getSetting('limit'); |
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.
maybe cast is better here?
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.
Since there is
public function configureSettings(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'limit' => 10,
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
]);
}
What do you think about using allowedTypes
?
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.
Is that a feature from the options resolver? I think it would be great but not sure if phpstan will understand it tho.
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.
Phpstan won't understand, so I'll keep the assert
, but it still a code improvement
@@ -39,16 +39,21 @@ public function __construct(Environment $twig, AuditReader $auditReader) | |||
|
|||
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response | |||
{ | |||
$template = $blockContext->getTemplate(); |
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 a block return null here?
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.
I assume that no because of
public function configureSettings(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'limit' => 10,
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
]);
}
af7d5e3
to
431a293
Compare
$this->getQuery()->setFirstResult(null); | ||
$this->getQuery()->setMaxResults(null); | ||
$query = $this->getQuery(); | ||
if (null === $query) { |
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.
Probably out of scope of this Pr, but wouldnt be nice if we ensure somehow that the query is never null, maybe as a parameter of this method or as a parameter of construct?
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.
Currently the pager and the query are constructor param of the Datagrid.
In this one we're running
$this->pager->setQuery($this->query);
$this->pager->init();
Maybe we could remove setQuery and use the query as a param of init indeed.
It's more a SonataAdmin change, so I'll recommend an issue.
@@ -38,6 +38,7 @@ public function load(array $configs, ContainerBuilder $container): void | |||
$loader->load('doctrine_orm_filter_types.xml'); | |||
|
|||
$bundles = $container->getParameter('kernel.bundles'); | |||
\assert(\is_array($bundles)); |
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.
seems strange having to add this around each getParameter to ensure 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.
getParameter is considered as returning mixed
for phpstan because of the symfony phpdoc
@@ -79,7 +80,9 @@ public function testEdit(): void | |||
|
|||
public function testDelete(): void | |||
{ | |||
$entityManager = static::bootKernel()->getContainer()->get('doctrine')->getManager(); | |||
$doctrine = static::bootKernel()->getContainer()->get('doctrine'); |
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.
I think the container resolution can be solved warming up cache before running phpstan. (can be done executing test previously). Then you add the xml to the phpstan config and it can solve those issues
b4f29fe
to
37abc94
Compare
37abc94
to
9e569d1
Compare
9e569d1
to
cb57898
Compare
This is ready @sonata-project/contributors :) |
Need