Fix the issues reported by phpcs

Created on 17 May 2023, about 1 year ago
Updated 25 May 2023, about 1 year ago

Problem/Motivation

FILE: ...ution/drupal10/web/modules/contrib/graphql_compose/graphql_compose.api.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
141 | ERROR | Expected type hint "EntityTypeInterface"; found
| | "\Drupal\Core\Field\FieldDefinitionInterface" for $field
--------------------------------------------------------------------------------

FILE: ...contribution/drupal10/web/modules/contrib/graphql_compose/js/uuid.admin.js
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
55 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...al10/web/modules/contrib/graphql_compose/src/Wrapper/EntityTypeWrapper.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
69 | ERROR | Unknown type hint "mixed" found for $entity
--------------------------------------------------------------------------------

FILE: ...ose/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
147 | ERROR | Type hint "array" missing for $element
--------------------------------------------------------------------------------

FILE: ...graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
98 | ERROR | Expected type hint "EntityInterface"; found "?EntityInterface"
| | for $entity
--------------------------------------------------------------------------------

FILE: ...trib/graphql_compose/modules/graphql_compose_edges/src/Wrappers/Cursor.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
37 | ERROR | Unknown type hint "mixed" found for $sortValue
--------------------------------------------------------------------------------

FILE: ...ontrib/graphql_compose/modules/graphql_compose_edges/src/Wrappers/Edge.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
20 | ERROR | Unknown type hint "mixed" found for $node
--------------------------------------------------------------------------------

Time: 9.16 secs; Memory: 16MB

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig graphql_compose/

Proposed resolution

Fix all the issues and warnings for Drupal and DrupalPractice standards.

Remaining tasks

Patch review.

Ignored this errors, as I believe these are false positives:
FILE: ...al10/web/modules/contrib/graphql_compose/src/Wrapper/EntityTypeWrapper.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
69 | ERROR | Unknown type hint "mixed" found for $entity
--------------------------------------------------------------------------------

FILE: ...trib/graphql_compose/modules/graphql_compose_edges/src/Wrappers/Cursor.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
37 | ERROR | Unknown type hint "mixed" found for $sortValue
--------------------------------------------------------------------------------

FILE: ...ontrib/graphql_compose/modules/graphql_compose_edges/src/Wrappers/Edge.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
20 | ERROR | Unknown type hint "mixed" found for $node
--------------------------------------------------------------------------------

Time: 9.07 secs; Memory: 16MB

๐Ÿ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

  • Issue created by @urvashi_vora
  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    The report shows errors/warnings for 20 files, but the patch changes only four files.

  • Assigned to imustakim
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia AlMunnings Melbourne

    Are you running PHPCS with PHP 8.1?

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia AlMunnings Melbourne

    Thank you for helping out on this module,

    @apaderno and @imustakim,
    Can you elaborate on your PHP/PHPCS settings and versions used? I am using the PHPCS shipped with "drupal/core-dev": "^10.0"

    www-data@bedfa839c0d8:/app$ cd web/modules/contrib/
    www-data@bedfa839c0d8:/app/web/modules/contrib$ phpcs --version
    PHP_CodeSniffer version 3.7.2 (stable) by Squiz (http://www.squiz.net)
    www-data@bedfa839c0d8:/app/web/modules/contrib$ php --version
    PHP 8.1.18 (cli) (built: May  3 2023 05:11:38) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.18, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies
    www-data@bedfa839c0d8:/app/web/modules/contrib$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig graphql_compose/
    www-data@bedfa839c0d8:/app/web/modules/contrib$ 
    

    On dev, latest, I no longer see issues, and definitely cant see issues with 20 files.
    I'm unsure what further requirements you have noticed

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    Raveen Thakur โ†’ made their first commit to this issueโ€™s fork.

  • @raveen-thakur opened merge request.
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    @AlMunnings I am referring to the phpcs report shown in the issue summary. It shows warnings/errors for 10 files, but the patch changes only four files.
    Either the patch is not changing all the files that should be fixed, or the report is not for the branch for which the patch has been created.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

    @apaderno, the report shows issue in 7 files only and not for 10 files, those are:
    1. graphql_compose.api.php
    2. uuid.admin.js
    3. contriEntityTypeWrapper.php
    4. GraphQLFieldRow.php
    5. CreateComment.php
    6. Cursor.php
    7. Edge.php

    Out of which, patch fixed errors for 4 files and if you see remaining tasks section in issue summary it mentions the issues present in the remaining 3 files.

    Hope this helps.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    @AlMunnings I just ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig for the 2.0.x branch. I do not get any warning/error either.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Let's check some of the changes done from the patch.

    diff --git a/modules/graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php b/modules/graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php
    index 3529526..bf7b4c7 100644
    --- a/modules/graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php
    +++ b/modules/graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php
    @@ -95,7 +95,7 @@ class CreateComment extends DataProducerPluginBase implements ContainerFactoryPl
        * @throws \GraphQL\Error\UserError
        *   First error violation returned from the comment entity validation.
        */
    -  public function resolve(array $data, ?EntityInterface $entity, RefinableCacheableDependencyInterface $metadata): ?CommentInterface {
    +  public function resolve(array $data, EntityInterface $entity, RefinableCacheableDependencyInterface $metadata): ?CommentInterface {
    

    The src/Plugin/GraphQL/DataProducer/CreateComment.php file does not exist in the 2.0.x branch.

    diff --git a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
    index 08af8fa..fd8fe9e 100644
    --- a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
    +++ b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
    @@ -144,7 +144,7 @@ class GraphQLFieldRow extends RowPluginBase {
        * @param \Drupal\Core\Form\FormStateInterface $form_state
        *   The form state.
        */
    -  public function validateAliasName($element, FormStateInterface $form_state) {
    +  public function validateAliasName(array $element, FormStateInterface $form_state) {
         if (preg_match('@[^A-Za-z0-9]+@', $element['#value'])) {
           $form_state->setError($element, $this->t('The machine-readable name must contain only letters and numbers.'));
         }
    

    The src/Plugin/views/row/GraphQLFieldRow.php does not exist in the 2.0.x branch.

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

    @apaderno, I'm unsure of the reviewing process at your end. In order to assist you, please find the path for the files mentioned below, and I can confirm that both files do indeed exist:
    1. "modules/graphql_compose_comments/src/Plugin/GraphQL/DataProducer/CreateComment.php"

    2. "modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php"

    Hope this helps you.

    Marking the status to "RTBC", because it seems that there has been a slight oversight in the review process before updating it to "needs work" and now, you are finding a empty report on phpcs because @AlMunnings already committed the changes done by me for those files.

    Thanks for wanting to help.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    @urvashi_vora Since you provided the patch, you cannot change the status to Reviewed & tested by the community.

    I apologize: I was looking for the files in the wrong directory.
    Still, replacing ?EntityInterface $entity with EntityInterface $entity is not correct, since a parameter declared as instance of a class implemented by a module or a parameter declared as implementing an interface can be declared as nullable.

    Then, I do not get any error/warning when I run phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig for the 2.0.x branch.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Notice that AlMunnings has already done a commit, reported in comment #5. If there is anything left, the patch needs to be rerolled.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

    Thanks for the feedback @apaderno

  • Status changed to Fixed about 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia AlMunnings Melbourne

    Yeppers, I think we can mark this one as fixed with no further work required.

  • Status changed to Fixed about 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia AlMunnings Melbourne
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
Production build 0.69.0 2024