coding standards and best practices

Created on 19 December 2022, almost 2 years ago
Updated 12 October 2023, about 1 year ago

Hi, While reviewing the module for best practices and standards. I have found several issues with the help of PHPCS.

Problem/Motivation

FILE: /var/www/html/dcontri/hcaptcha/src/HCaptcha/HCaptcha.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 35 ERRORS AND 10 WARNINGS AFFECTING 39 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
   4 | ERROR   | [x] There must be one blank line after the namespace declaration
   7 | ERROR   | [x] Missing class doc comment
   8 | ERROR   | [x] Opening brace should be on the same line as the declaration
  11 | ERROR   | [ ] Missing member variable doc comment
  11 | ERROR   | [x] Short array syntax must be used to define arrays
  19 | ERROR   | [ ] Missing member variable doc comment
  20 | ERROR   | [ ] Missing member variable doc comment
  21 | ERROR   | [ ] Missing member variable doc comment
  21 | ERROR   | [x] Short array syntax must be used to define arrays
  22 | ERROR   | [ ] Missing member variable doc comment
  22 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
  23 | ERROR   | [ ] Missing member variable doc comment
  24 | ERROR   | [ ] Missing member variable doc comment
  26 | ERROR   | [x] Missing function doc comment
  26 | ERROR   | [x] Short array syntax must be used to define arrays
  26 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
  33 | ERROR   | [x] Inline control structures are not allowed
  40 | ERROR   | [x] There must be exactly one blank line before the tags in a doc comment
  40 | ERROR   | [ ] Description for the @return value is missing
  44 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
  46 | ERROR   | [x] Short array syntax must be used to define arrays
  53 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
  55 | ERROR   | [x] Short array syntax must be used to define arrays
  61 | ERROR   | [x] Missing function doc comment
  62 | ERROR   | [x] Short array syntax must be used to define arrays
  74 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  77 | ERROR   | [x] Closing parenthesis of array declaration must be on a new line
  91 | ERROR   | [x] Missing function doc comment
  95 | ERROR   | [x] Missing function doc comment
  99 | ERROR   | [x] Missing function doc comment
 101 | ERROR   | [x] Short array syntax must be used to define arrays
 114 | ERROR   | [x] Missing function doc comment
 115 | ERROR   | [x] Short array syntax must be used to define arrays
 116 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 117 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 118 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 119 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 120 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 121 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 122 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 123 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 124 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 129 | ERROR   | [x] Missing function doc comment
 136 | ERROR   | [x] Expected 1 blank line after function; 0 found
----------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dcontri/hcaptcha/src/HCaptcha/Drupal8Post.php
-----------------------------------------------------------------------------------------------------
FOUND 12 ERRORS AFFECTING 11 LINES
-----------------------------------------------------------------------------------------------------
  3 | ERROR | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
 15 | ERROR | [ ] Parameter $url is not described in comment
 21 | ERROR | [x] Expected "object" but found "\stdClass" for function return type
 25 | ERROR | [x] Short array syntax must be used to define arrays
 26 | ERROR | [x] Short array syntax must be used to define arrays
 29 | ERROR | [x] Expected one space after the comma, 0 found
 29 | ERROR | [x] Expected one space after the comma, 0 found
 32 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
 39 | ERROR | [x] Expected newline after closing brace
 42 | ERROR | [x] Expected newline after closing brace
 48 | ERROR | [x] Expected 1 blank line after function; 0 found
 49 | ERROR | [x] The closing brace for the class must have an empty line before it
-----------------------------------------------------------------------------------------------------


FILE: /var/www/html/dcontri/hcaptcha/src/HCaptcha/RequestMethod.php
--------------------------------------------------------------------------------
FOUND 9 ERRORS AND 1 WARNING AFFECTING 6 LINES
--------------------------------------------------------------------------------
  5 | ERROR   | [x] Missing interface doc comment
  5 | WARNING | [ ] Interface names should always have the suffix "Interface"
  6 | ERROR   | [x] Opening brace should be on the same line as the declaration
 10 | ERROR   | [ ] Missing parameter comment
 11 | ERROR   | [x] Parameter comment must be on the next line
 11 | ERROR   | [x] Parameter comment must end with a full stop
 13 | ERROR   | [ ] Description for the @return value must be on the next line
 15 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
 15 | ERROR   | [x] Expected 1 blank line before function; 0 found
 15 | ERROR   | [x] Expected 1 blank line after function; 0 found
--------------------------------------------------------------------------------


FILE: /var/www/html/dcontri/hcaptcha/src/Form/HCaptchaAdminSettingsForm.php
-------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
-------------------------------------------------------------------------------------------
 37 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 44 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 53 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 62 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 71 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
-------------------------------------------------------------------------------------------


FILE: /var/www/html/dcontri/hcaptcha/hcaptcha.module
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 11 ERRORS AND 2 WARNINGS AFFECTING 12 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
  52 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
  53 | WARNING | [x] A comma should follow the last multiline array item. Found: )
  57 | ERROR   | [x] Expected newline after closing brace
  79 | ERROR   | [ ] The $_POST super global must not be accessed directly; inject the request_stack service and use
     |         |     $stack->getCurrentRequest()->request->get('h-captcha-response') instead
  79 | ERROR   | [ ] The $_POST super global must not be accessed directly; inject the request_stack service and use
     |         |     $stack->getCurrentRequest()->request->get('h-captcha-response') instead
  80 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
  83 | ERROR   | [x] Short array syntax must be used to define arrays
  84 | ERROR   | [ ] The $_POST super global must not be accessed directly; inject the request_stack service and use
     |         |     $stack->getCurrentRequest()->request->get('h-captcha-response') instead
  88 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
  89 | ERROR   | [x] Expected newline after closing brace
  94 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
 112 | ERROR   | [x] Expected one space after the comma, 0 found
 113 | WARNING | [x] A comma should follow the last multiline array item. Found: 'https://www.drupal.org/project/hcaptcha'
----------------------------------------------------------------------------------------------------------------------------------------------

๐Ÿ› Bug report
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia akshay.singh Noida

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024