- Issue created by @Chris64
- Status changed to Closed: won't fix
9 months ago 4:18pm 27 February 2024 - π¦πΊAustralia dpi Perth, Australia
Variable $access_plugin on left side of ??= always exists and is not nullable.
Ignored error pattern #^Variable \$access_plugin in isset\(\) always exists and is not nullable\.$# in path
If either error is true, then the line should not be converted to ??=. Nor should it be left as isset().
If the change is correct, then the code leading to it should be changed. With better typehints, for example.
I'd suggest changing the code in the other issue. Just make sure you are justifying the change clearly in documenting a issue/MR comment.
- π¦πΊAustralia dpi Perth, Australia
For PathPluginBase, \Drupal\views\Plugin\views\display\DisplayPluginInterface::getPlugin the docs say it can never return null.
However I can see there a
return void;
, so lets create an issue just for this, which changes the documentation, and explicitlyreturn NULL;
This issue could be used as a template: π \Drupal\Core\Config\StorageInterface::read is typehinted as possibly returning bool, but never returns true Fixed
In this case I wouldnt recommend changing the relevant lines in the ??= issue.
- π¦πΊAustralia dpi Perth, Australia
For PreviewTest.php, lets keep the change in the ??= issue.
However, lets change
\Drupal\Tests\views_ui\FunctionalJavascript\PreviewTest::assertClass
so the method signature (and docs) match\Drupal\Tests\system\Functional\Pager\PagerTest::assertClass
. - π«π·France Chris64 France
@dpi, thank you for your answer, We can discuss.
For PreviewTest.php, lets keep the change in the ??= issue.
Well, this case block the MR, because of the phpstan error. I face this before.
For PathPluginBase, \Drupal\views\Plugin\views\display\DisplayPluginInterface::getPlugin the docs say it can never return null.
So, is not nullable, so,
if (!isset($access_plugin)) { // @todo Do we want to support a default plugin in getPlugin itself? $access_plugin = Views::pluginManager('access')->createInstance('none'); }
is inconsistent: never go in the block. Or is nullable, and this code is okay (...and could be changed to ??=).
- π«π·France Chris64 France
@dpi, I think the problem is not
??=
. The problem, as phpstan tells us, is not nullable +isset
. - π«π·France Chris64 France
I push the work, since done. It can be refused.
- Merge request !6792??= B2: multi-line case: phpstan obstruction case: + make 2 var nullable β (Open) created by Chris64
- π«π·France Chris64 France
May be refused, but nice information: with these few changes now these two cases have MR mergeable. A step forward.
- π«π·France Chris64 France
Okay @dpi, after having a look your requests about
null
are clear for me. - π«π·France Chris64 France
About #6 π Use null coalescing assignment operator ??=: phpstan obstruction case. Closed: won't fix , on one side, in
core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php
,/** * Asserts that an element has a given class. * * @param \Behat\Mink\Element\NodeElement $element * The element to test. * @param string $class * The class to assert. * @param string $message * (optional) A verbose message to output. * * @internal */ protected function assertClass(NodeElement $element, string $class, string $message = ''): void { if (!isset($message)) { $message = "Class .$class found."; } $this->assertStringContainsString($class, $element->getAttribute('class'), $message);
On the other side, in
core/modules/system/tests/src/Functional/Pager/PagerTest.php
,/** * Asserts that an element has a given class. * * @param \Behat\Mink\Element\NodeElement $element * The element to test. * @param string $class * The class to assert. * @param string $message * (optional) A verbose message to output. * * @internal */ protected function assertClass(NodeElement $element, string $class, string $message = NULL): void { if (!isset($message)) { $message = "Class .$class found."; } $this->assertTrue($element->hasClass($class), $message); }
To make the two match change,
, string $message = ''): void {
to
, string $message = NULL): void {
- π«π·France Chris64 France
@dpi, for #6 π Use null coalescing assignment operator ??=: phpstan obstruction case. Closed: won't fix and
$access_plugin
,However I can see there a return void;, so lets create an issue just for this, which changes the documentation, and explicitly return NULL;
I believe you have in head,
// Return now if no options have been loaded. if (empty($options) || !isset($options['type'])) { return; }
in
getPlugin
incore/modules/views/src/Plugin/views/display/DisplayPluginBase.php
. And if I follow π \Drupal\Core\Config\StorageInterface::read is typehinted as possibly returning bool, but never returns true Fixed I think the change needed should be,
* @return \Drupal\views\Plugin\views\ViewsPluginInterface
to
* @return \Drupal\views\Plugin\views\ViewsPluginInterface|null
in,/** * Get the instance of a plugin, for example style or row. * * @param string $type * The type of the plugin. * * @return \Drupal\views\Plugin\views\ViewsPluginInterface */ public function getPlugin($type);
in
core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php
since,
abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInterface, DependentPluginInterface {
- π«π·France Chris64 France
Finally the issue perimeter could be restricted to the nullable problems,
so lets create an issue just for this
using this issue for these problems.
- π«π·France Chris64 France
Still some phpstan errors,
------ ------------------------------------------------------------------------------------------------ Line core/modules/views/src/Plugin/views/display/DisplayPluginBase.php ------ ------------------------------------------------------------------------------------------------ Ignored error pattern #^Variable \$pager in isset\(\) always exists and is not nullable\.$# in path /builds/issue/drupal-3424107/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php was not matched in reported errors. Ignored error pattern #^Variable \$style in empty\(\) always exists and is not falsy\.$# in path /builds/issue/drupal-3424107/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php was not matched in reported errors. ------ ------------------------------------------------------------------------------------------------ ------ --------------------------------------------------------------------------------------------- Line core/modules/views/src/Plugin/views/display/PathPluginBase.php ------ --------------------------------------------------------------------------------------------- Ignored error pattern #^Variable \$access_plugin in isset\(\) always exists and is not nullable\.$# in path /builds/issue/drupal-3424107/core/modules/views/src/Plugin/views/display/PathPluginBase.php was not matched in reported errors. ------ --------------------------------------------------------------------------------------------- ------ -------------------------------------------------------------------------------------------- Line core/modules/views/src/Plugin/views/style/StylePluginBase.php ------ -------------------------------------------------------------------------------------------- Ignored error pattern #^Variable \$plugin in empty\(\) always exists and is not falsy\.$# in path /builds/issue/drupal-3424107/core/modules/views/src/Plugin/views/style/StylePluginBase.php was not matched in reported errors. ------ -------------------------------------------------------------------------------------------- ------ --------------------------------------------------------------------------------------------------- Line core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php ------ --------------------------------------------------------------------------------------------------- Ignored error pattern #^Variable \$message in isset\(\) always exists and is not nullable\.$# in path /builds/issue/drupal-3424107/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php was not matched in reported errors. ------ --------------------------------------------------------------------------------------------------- [ERROR] Found 5 errors
- Status changed to Needs work
9 months ago 4:52pm 29 February 2024 - π«π·France Chris64 France
- The phpstan errors have no line number. The corresponding items should be removed from
core/phpstan-baseline.neon
file.
- Following the messages,in empty\(\) always exists and is not falsy in isset\(\) always exists and is not nullable
since always exists, make some changes
empty($A)
to!$A
andisset($A)
to$A !== NULL
. (Not always, to keep the??=
transformations still possible.) - Status changed to Needs review
9 months ago 6:03pm 4 March 2024 - π³πΏNew Zealand quietone
The title is also the commit message, so this should be easier to understand when searching history in the future.
- Status changed to Needs work
8 months ago 1:10pm 13 March 2024 The Needs Review Queue Bot β tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide β to find step-by-step guides for working with issues.
- Status changed to Postponed
8 months ago 11:32pm 26 March 2024 - πΊπΈUnited States smustgrave
On the coding standard decision #3436307: Change !isset to the null coalescing assignment operator ??= β