-
-
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
Changes from 2 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 |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Since there is
What do you think about using 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Phpstan won't understand, so I'll keep the |
||
\assert(\is_int($limit)); | ||
|
||
$revisions = []; | ||
|
||
foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) { | ||
foreach ($this->auditReader->findRevisionHistory($limit, 0) as $revision) { | ||
$revisions[] = [ | ||
'revision' => $revision, | ||
'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()), | ||
]; | ||
} | ||
|
||
return $this->renderResponse($blockContext->getTemplate(), [ | ||
return $this->renderResponse($template, [ | ||
'block' => $blockContext->getBlock(), | ||
'settings' => $blockContext->getSettings(), | ||
'revisions' => $revisions, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 ? The Guesser from this bundle never return null, but just in case, I added the exception... |
||
throw new \InvalidArgumentException(sprintf( | ||
'Cannot guess a type for the field description "%s", You MUST provide a type.', | ||
$fieldDescription->getName() | ||
)); | ||
} | ||
|
||
$fieldDescription->setType($guessType->getType()); | ||
} else { | ||
|
@@ -69,7 +75,16 @@ public function addField(FieldDescriptionCollection $list, ?string $type, FieldD | |
|
||
public function fixFieldDescription(FieldDescriptionInterface $fieldDescription): void | ||
{ | ||
if (ListMapper::TYPE_ACTIONS === $fieldDescription->getType()) { | ||
$type = $fieldDescription->getType(); | ||
if (!$type) { | ||
throw new \RuntimeException(sprintf( | ||
'Please define a type for field `%s` in `%s`', | ||
$fieldDescription->getName(), | ||
\get_class($fieldDescription->getAdmin()) | ||
)); | ||
} | ||
|
||
if (ListMapper::TYPE_ACTIONS === $type) { | ||
$this->buildActionFieldDescription($fieldDescription); | ||
} | ||
|
||
|
@@ -83,16 +98,8 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription) | |
$fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); | ||
} | ||
|
||
if (!$fieldDescription->getType()) { | ||
throw new \RuntimeException(sprintf( | ||
'Please define a type for field `%s` in `%s`', | ||
$fieldDescription->getName(), | ||
\get_class($fieldDescription->getAdmin()) | ||
)); | ||
} | ||
|
||
if (!$fieldDescription->getTemplate()) { | ||
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); | ||
$fieldDescription->setTemplate($this->getTemplate($type)); | ||
|
||
if (!$fieldDescription->getTemplate()) { | ||
switch ($fieldDescription->getMappingType()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,14 +47,9 @@ public function getCurrentPageResults(): iterable | |
->getMetadataFor(current($query->getQueryBuilder()->getRootEntities())) | ||
->getIdentifierFieldNames(); | ||
|
||
// NEXT_MAJOR: Remove the check and the else part. | ||
if (method_exists($query, 'getDoctrineQuery')) { | ||
// Paginator with fetchJoinCollection doesn't work with composite primary keys | ||
// https://github.com/doctrine/orm/issues/2910 | ||
$paginator = new Paginator($query->getDoctrineQuery(), 1 === \count($identifierFieldNames)); | ||
} else { | ||
$paginator = new Paginator($query->getQueryBuilder(), 1 === \count($identifierFieldNames)); | ||
} | ||
// Paginator with fetchJoinCollection doesn't work with composite primary keys | ||
// https://github.com/doctrine/orm/issues/2910 | ||
$paginator = new Paginator($query->getDoctrineQuery(), 1 === \count($identifierFieldNames)); | ||
|
||
return $paginator->getIterator(); | ||
} | ||
|
@@ -68,8 +63,13 @@ public function init(): void | |
{ | ||
$this->resultsCount = $this->computeResultsCount(); | ||
|
||
$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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Currently the pager and the query are constructor param of the Datagrid.
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. |
||
throw new \LogicException('The pager need a query to be initialised'); | ||
} | ||
|
||
$query->setFirstResult(null); | ||
$query->setMaxResults(null); | ||
|
||
if (0 === $this->getPage() || 0 === $this->getMaxPerPage() || 0 === $this->countResults()) { | ||
$this->setLastPage(0); | ||
|
@@ -78,8 +78,8 @@ public function init(): void | |
|
||
$this->setLastPage((int) ceil($this->countResults() / $this->getMaxPerPage())); | ||
|
||
$this->getQuery()->setFirstResult($offset); | ||
$this->getQuery()->setMaxResults($this->getMaxPerPage()); | ||
$query->setFirstResult($offset); | ||
$query->setMaxResults($this->getMaxPerPage()); | ||
} | ||
} | ||
|
||
|
@@ -91,12 +91,7 @@ private function computeResultsCount(): int | |
throw new \TypeError(sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class)); | ||
} | ||
|
||
// NEXT_MAJOR: Remove the check and the else part. | ||
if (method_exists($query, 'getDoctrineQuery')) { | ||
$paginator = new Paginator($query->getDoctrineQuery()); | ||
} else { | ||
$paginator = new Paginator($query->getQueryBuilder()); | ||
} | ||
$paginator = new Paginator($query->getDoctrineQuery()); | ||
|
||
return \count($paginator); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. getParameter is considered as returning |
||
|
||
if (isset($bundles['SimpleThingsEntityAuditBundle'])) { | ||
$loader->load('audit.xml'); | ||
|
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