$ phpcs --standard=Drupalpractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml panolens/

FILE: C:\xampp\htdocs\contribution\web\modules\contrib\panolens\src\Commands\PanolensCommands.php
-------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
-------------------------------------------------------------------------------------------------
74 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
79 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
90 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
181 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\contribution\web\modules\contrib\panolens\src\Plugin\Field\FieldFormatter\ImagePanoramaFormatter.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
47 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------------------------------

Time: 132ms; Memory: 6MB

Comments

Rakhi Soni created an issue. See original summary.

rakhi soni’s picture

Assigned: rakhi soni » Unassigned
Status: Active » Needs review
StatusFileSize
new4.28 KB

I have created a patch to fix the issue of '\Drupal calls should be avoided in classes, use dependency injection instead',, please review.

sanduhrs’s picture

Status: Needs review » Needs work

Good idea, you might want to consider using phpcs Drupal standard aswell:
phpcs --standard=Drupal,Drupalpractice

  1. +++ b/src/Commands/PanolensCommands.php
    @@ -5,12 +5,43 @@ namespace Drupal\panolens\Commands;
    +  public function __construct(FileSystemInterface $file_system)
    +  {
    

    Opening brace should be on the same line as the declaration

  2. +++ b/src/Commands/PanolensCommands.php
    @@ -5,12 +5,43 @@ namespace Drupal\panolens\Commands;
    +  {
    ...
    +  public static function create(ContainerInterface $container)
    

    Opening brace should be on the same line as the declaration

  3. +++ b/src/Commands/PanolensCommands.php
    @@ -5,12 +5,43 @@ namespace Drupal\panolens\Commands;
    +  }
    

    Expected 1 blank line after function; 2 found

  4. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -19,6 +21,33 @@ use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
    +  public function __construct(FileUrlGeneratorInterface $file_url_generator)
    

    Opening brace should be on the same line as the declaration.

    Missing semicolon at the end of the line.

    Also take care of the parent constructor ImageFormatter::__construct

  5. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -19,6 +21,33 @@ use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
    +  public static function create(ContainerInterface $container)
    

    Opening brace should be on the same line as the declaration.

    Also take care of parent creator ImageFormatter::create

  6. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -19,6 +21,33 @@ use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
    +  }
    

    Expected 1 blank line after function

  7. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -44,7 +73,7 @@ class ImagePanoramaFormatter extends ImageFormatter {
    +      $file_url_generator = $this->fileUrlGenerator;
    

    No need for a local copy if injected.

sourabhjain’s picture

Status: Needs work » Needs review
StatusFileSize
new4.27 KB
new1.7 KB

I have resolved the issue mentioned in #3.
Please review.

sanduhrs’s picture

Status: Needs review » Needs work
  1. +++ b/src/Commands/PanolensCommands.php
    @@ -5,12 +5,40 @@ namespace Drupal\panolens\Commands;
    +  public function __construct(FileSystemInterface $file_system) {
    +    $this->fileSystem = $file_system;
    +  }
    

    ArgumentCountError: Too few arguments to function Drupal\panolens\Commands\PanolensCommands::__construct(), 0 passed
    The argument probably needs to be declared in the service definition.

  2. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -19,6 +21,32 @@ use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
    +  public function __construct(FileUrlGeneratorInterface $file_url_generator) {
    +    $this->fileUrlGenerator = $file_url_generator
    +  }
    

    The parent constructor call is missing.
    ; is missing after $file_url_generator.

  3. +++ b/src/Plugin/Field/FieldFormatter/ImagePanoramaFormatter.php
    @@ -19,6 +21,32 @@ use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
    +  public static function create(ContainerInterface $container) {
    

    Declaration must be compatible with ImageFormatter::create

dipayanpramanik5’s picture

Assigned: Unassigned » dipayanpramanik5
dipayanpramanik5’s picture

StatusFileSize
new6.58 KB
dipayanpramanik5’s picture

Assigned: dipayanpramanik5 » Unassigned
Status: Needs work » Needs review
sanduhrs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new10.09 KB

Adding the same to VideoPanoramaFormatter.
Committing to *dev, thanks!

  • sanduhrs committed f7f6d83 on 1.0.x
    Issue #3291712 by sourabhjain, Rakhi Soni, sanduhrs, dipayanpramanik5: \...
sanduhrs’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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