ankushgautam@GGN-199732-C02ZT1F1MD6V contrib % drupal-check -ad gamw
3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

------ -------------------------------------------------------------------------------
Line src/Form/GamwSettingsForm.php
------ -------------------------------------------------------------------------------
117 Call to an undefined method Drupal\Core\Entity\EntityInterface::getFileUri().
------ -------------------------------------------------------------------------------

------ -------------------------------------------------------
Line src/Plugin/Block/Gamw.php
------ -------------------------------------------------------
38 Unsafe usage of new static().
💡 Consider making the class or the constructor final.
------ -------------------------------------------------------

[ERROR] Found 2 errors

Comments

vatsalkhanna’s picture

Status: Active » Needs review
Issue tags: +Drupal 9 compatibility, +Drupal 9 porting weekend, +DIACWMay2020
StatusFileSize
new1.52 KB

Here's the patch

mradcliffe’s picture

Status: Needs review » Needs work
Issue tags: -Drupal 9 compatibility
  1. +++ b/src/Form/GamwSettingsForm.php
    @@ -5,6 +5,7 @@ namespace Drupal\gamw\Form;
    +use Drupal\file\Entity\File;
    
    @@ -114,7 +115,7 @@ class GamwSettingsForm extends ConfigFormBase {
           if ($this->entityTypeManager->getStorage('file')->load($csv_file_id)) {
    -        $file_entity_uri = $this->entityTypeManager->getStorage('file')->load($csv_file_id)->getFileUri();
    +        $file_entity_uri = File::load($csv_file_id)->getFileUri();
    

    There's not anything wrong. The report is a false negative.

    However, if caching isn't used, then this will load the file twice.

    It may be better to try loading the file outside of the if statement assigned to a variable. Then we check if the variable is truthy and if it is an instanceof FileInterface.

    Inside the if, then $file_entity_uri can be assigned.

  2. +++ b/src/Plugin/Block/Gamw.php
    @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
    -class Gamw extends BlockBase implements ContainerFactoryPluginInterface {
    +final class Gamw extends BlockBase implements ContainerFactoryPluginInterface {
    

    This also seems like a result of phpstan static analysis rather than Drupal 9 compatibility. If the maintainer doesn't want the class to ever be extended, final could be used, but I think this is a false negative.

I would probably run drupal-check with the -d not the -a command, but I don't think there is anything needed to make this compatible with Drupal 9. It already is compatible. I removed the Drupal 9 compatibility tag because it doesn't seem to matter. The Drupal 9 porting weekend tag should remain because this is work that was done during a virtual contribution event.

vatsalkhanna’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB

Thanks @mradcliffe for the suggestions. I have updated the patch with the changes. For #1, my bad, I didn't see that $this->entityTypeManager->getStorage('file')->load($csv_file_id) was there in the if condition too. For #2, I removed final from the class. I made the changes as per your suggestions.

kristen pol’s picture

Issue tags: +Drupal 9 compatibility

Adding missing tag.

eliaspapa’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.