Fix the issues reported by phpcs

Created on 18 April 2023, almost 2 years ago
Updated 10 June 2024, 8 months ago

GitLab CI reports PHP_CodeSniffer warnings/errors which should be fixed, if they are not false positives.

šŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India dineshkumarbollu

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

Merge Requests

Comments & Activities

  • Issue created by @dineshkumarbollu
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi dineshkumarbollu

    I applied your patch #2, some phpcs errors and warnings were fixed but there are still remaining phpcs warnings being flagged.

    Please look at the screenshots attached for your reference

    Thanks

  • šŸ‡·šŸ‡ŗRussia sorlov

    I'm not sure that we'd pass README.md to phpcs.

    It makes no sense, as it is just plain text doc.

  • Status changed to Needs review almost 2 years ago
  • šŸ‡·šŸ‡ŗRussia sorlov

    Here is patch version without changes in README files

  • šŸ‡®šŸ‡³India arpitk

    I'm able to apply patch #5. The patch excludes the readme files and no more phpcs standard errors shown. Attaching the screen shots here.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs work almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    Actually, phpcs handles also the README files. What reported by phpcs for a REAME.txt or README.md file needs to be fixed too, if what reported is correct.

  • šŸ‡·šŸ‡ŗRussia sorlov

    What is the point to run PHP CODE SNIFFER on readme text files?

    There is no code inside, just readme text.

  • Status changed to Needs review almost 2 years ago
  • šŸ‡®šŸ‡³India Rajan Kumar

    Attached patch for fix phpcs errors which also remove README.md file warnings.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    Coding standards are also for the README files, not just files containing code.

  • Status changed to RTBC almost 2 years ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi @Rajan Kumar,

    I applied your patch #10 to my local and confirmed that all PHPCS issues/erros were fixed.

    Kindly look at the screenshots attached for your reference

    Thank you.

  • Status changed to Needs work almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    -Where %arg - absolute path to directory with source .csv files. All source files should be placed there without any subfolders.
    +Where %arg - absolute path to directory with source .csv files. All source
    + files should be placed there without any subfolders.

    The last line does not need to start with a space.

    -  - **address** (we can use various properties like country_code, locality, postal_code, etc.)
    +  - **address** (we can use various properties like country_code, locality,
    +   postal_code, etc.)

    The last line must be indented.

     ------------
    -## Administration
    +## Drush command

    Why is the header changed?

    -1. Provide proper settings on /admin/config/content/migrate-generator-export page.
    +`drush migrate_generator:generate_migrations %arg %options`
     
    -2. Create neccessary configuration export entities on /admin/config/content/migrate-generator-export/types page.
    -For each entity type and bundle we may have configuration. which will be used for export.
    -This configuration may have fields, which will be included in export.
    +Where %arg - absolute path to directory with source .csv files. All source files
    +should be placed there without any subfolders.
     
    -3. Perform export on /admin/content/migrate-generator-export page.
    -There is field `Include all referenced content`. With this field checked, module will export also content,
    - related via entity reference fields, if any of them are included in export.
    +Also we have next possible options:
    +* pattern -
    +  Pattern for source CSV files. Defaults to '*.csv'.
    +* delimiter -
    +  Delimiter for source CSV files. Defaults to ;
    +* enclosure -
    +  Enclosure for source CSV files. Defaults to "
    +* values_delimiter -
    +  Delimiter for multi-valued fields. Defaults to |
    +* date_format -
    +  Date format used in CSV. Defaults to "d-m-Y H:i:s"
    +* update -
    +  Update previously-generated migrations.
    +* migrate_group -
    +  Migration Group Id. Defaults to "mgg"

    Why is that part changed? The phpcs report does not suggest such a change.

  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India sakthi_dev

    Created a patch by addressing the changes in comment #13. Please review.

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    +This command creates Migration for each source file and Migration Group for
    + these created migrations.
    +Migration group ID can be specified by **migrate_group** option in
    +drush command.

    The sentence starting with Migration group ID does not need its own line.
    Then, since that text is edited, drush should be replaced by Drush.

    -  You can see some examples in /example folder of this module, like `node-basic_page.csv`, `taxonomy_term-category.csv`, `user.csv`, etc.
    +  You can see some examples in /example folder of this module, like
    +   `node-basic_page.csv`, `taxonomy_term-category.csv`, `user.csv`, etc.
    -* Each source file should have first column filled with Ids. It will be used as unique identifier for source row only, not for Id of migrated entity.
    +* Each source file should have first column filled with Ids. It will be used
    +   as unique identifier for source row only, not for Id of migrated entity.
    -For example, `body/value`, `body/format`, `date/value`, `date/end_value`, `price/number`, `price/currency_code`, etc.
    +For example, `body/value`, `body/format`, `date/value`, `date/end_value`,
    + `price/number`, `price/currency_code`, etc.

    There is an extra space at the beginning of the last line.

    -  ...| image/alt | image/title | image/target_id | ...|
    -  ---| --- | --- | --- | --- |
    -  ...| Alt text  | Image title | https://www.drupal.org/files/cta/graphic/Wordmark_blue_RGB.png | ... | 
    -  
    +  | ... | image/alt | image/title |
    +  image/target_id                                                | ... |
    +  | --- | --------- | ----------- |
    +  -------------------------------------------------------------- | --- |
    +  | ... | Alt text  | Image title |
    +  https://www.drupal.org/files/cta/graphic/Wordmark_blue_RGB.png | ... |

    That is markup for a table and should not be changed.

    -1. Paragraph field in Basic Page CT could have references to WYSIWYG and Media paragraphs.
    -so we will have separate sources for these paragraphs `paragraph-media.csv`, `paragraph-wysiwyg.csv`
    +1. Paragraph field in Basic Page CT could have references to WYSIWYG and
    +    Media paragraphs.
    +so we will have separate sources for these paragraphs
    +`paragraph-media.csv`, `paragraph-wysiwyg.csv`

    That text is not correctly formatted.

  • Assigned to nitin_lama
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India nitin_lama India

    Addressed #15. Please review.

  • Issue was unassigned.
  • šŸ‡§šŸ‡“Bolivia vacho Cochabamba

    Rebased and fixed the last code issues.

  • šŸ‡®šŸ‡³India Yashaswi18

    Tried applying the patch provided in #19, throws error.

  • šŸ‡·šŸ‡ŗRussia sorlov

    @Yashaswi18 can you give more info?

    what version of module do you use and what error do you have?

  • šŸ‡®šŸ‡³India Yashaswi18

    Version: 8.x-1.x

    Error:

    Checking patch README.md...
    error: while searching for:
    * migrate_group -
      Migration Group Id. Defaults to "mgg"
    
    This command creates Migration for each source file and Migration Group for these created migrations.
    Migration group ID can be specified by **migrate_group** option in drush command.
    
    ## CSV file structure and contents
    
    We should use next ways of organizing source files:
    * Source CSV files should have following filename pattern `{entity_type}-{bundle}.csv` or `{entity_type}.csv`.
    
      You can see some examples in /example folder of this module, like `node-basic_page.csv`, `taxonomy_term-category.csv`, `user.csv`, etc.
    
    **Main idea here - to identify target Entity type and Bundle for source file.**
    
    There are some rules for structure and content of source csv file:
    * Each source file should have first column filled with Ids. It will be used as unique identifier for source row only, not for Id of migrated entity.
    * All other columns should be named with exact field's machine name.
    * For boolean fields you can use "1/0" or "true/false" values.
    * For list fields, we should have key values in source csv, not labels.
    * Fields with multiple values should have strict delimiter. `|` for example.
    
      This delimiter can be specified by **values_delimiter** option in drush command.
    * Date fields should have same date format everywhere in sources.
    
      This date format can be specified by **date_format** option in drush command.
    
      No timezone conversion is made for dates.
    
    ## Complex fields with multiple properties
    
    For complex fields (like Formatted text, Link, Datetime Range, Address, Price, etc.) we can have several properties in source file.
    In this case, you can use `/` separator in column name for these cases.
    
    Supported complex field types:
    
    error: patch failed: README.md:28
    error: README.md: patch does not apply
    Checking patch migrate_generator_export/README.md...
    error: while searching for:
    # migrate_generator_export
    Module to generate source CSV files to be processed by migrate_generator
    
    ## Basic idea
    
    Main idea here is to **provide funcionality for generating source csv files**.
    
    ------------
    ## Administration
    
    error: patch failed: migrate_generator_export/README.md:1
    error: migrate_generator_export/README.md: patch does not apply
    Checking patch migrate_generator_export/src/Commands/DrushCommands.php...
    error: while searching for:
            continue;
          }
          $fields = $export_config->getFields();
          list($entity_type_id, $bundle_id) = explode('--', $export_config_id);
          $this->exportManager->getOperations($batch['operations'], $entity_type_id, $bundle_id, $fields, NULL, TRUE, $options['folder'] ?? '');
        }
    
        if (empty($batch['operations'])) {
    
    error: patch failed: migrate_generator_export/src/Commands/DrushCommands.php:203
    error: migrate_generator_export/src/Commands/DrushCommands.php: patch does not apply
    Checking patch migrate_generator_export/src/ExportManager.php...
    Hunk #1 succeeded at 72 (offset -10 lines).
    Hunk #2 succeeded at 96 (offset -10 lines).
    Hunk #3 succeeded at 240 (offset -15 lines).
    Checking patch migrate_generator_export/src/FieldsExportManager.php...
    yashaswi@LAPTOP-V6R99U45:~/contribs/migrate_generator$
       */
      public function getFieldsValues(ContentEntityInterface $entity, array $fields, array $options) {
        $values = [];
        foreach ($fields as $field) {
          $field_sub_value_name = '';
          if (strpos($field, '-') !== FALSE) {
            list($field_name, $field_sub_value_name) = explode('-', $field);
          }
          if (!empty($field_sub_value_name)) {
            $field = $field_name;
    
    error: patch failed: migrate_generator_export/src/FieldsExportManager.php:53
    error: migrate_generator_export/src/FieldsExportManager.php: patch does not apply
    Checking patch migrate_generator_export/src/Form/EntityTypeExportConfigForm.php...
    Checking patch migrate_generator_export/src/Form/ExportForm.php...
    error: while searching for:
          'finished' => 'Drupal\migrate_generator_export\ExportManager::batchFinished',
        ];
        $storage = $this->entityTypeManager->getStorage('entity_type_export_config');
        foreach (Checkboxes::getCheckedCheckboxes($exports) as $export_id) {
          $export = $storage->load($export_id);
          if (!empty($export)) {
            $fields = $export->getFields();
            list($entity_type_id, $bundle_id) = explode('--', $export_id);
            $this->exportManager->getOperations($batch['operations'], $entity_type_id, $bundle_id, $fields, NULL, FALSE, $form_state->getValue('folder') ?? '');
          }
        }
        if (empty($batch['operations'])) {
    
    error: patch failed: migrate_generator_export/src/Form/ExportForm.php:194
    error: migrate_generator_export/src/Form/ExportForm.php: patch does not apply
    Checking patch migrate_generator_export/src/Plugin/GeneratorExportPluginDateBase.php...
    Checking patch migrate_generator_export/src/Plugin/migrate_generator_export/process/FileExport.php...
    error: while searching for:
        if ($entity->get($field_name)->isEmpty()) {
          return '';
        }
        $file_format = isset($this->options['file_format']) ? $this->options['file_format'] : 'url';
        $field_values = $entity->get($field_name)->getValue();
        $value = [];
        $file_storage = $this->entityTypeManager->getStorage('file');
    
    error: patch failed: migrate_generator_export/src/Plugin/migrate_generator_export/process/FileExport.php:60
    error: migrate_generator_export/src/Plugin/migrate_generator_export/process/FileExport.php: patch does not apply
    Checking patch src/Plugin/GeneratorProcessPluginBase.php...
    Checking patch src/Plugin/GeneratorProcessPluginDateBase.php...
    Checking patch src/Plugin/migrate/process/IpToBinary.php...
    error: while searching for:
    use Drupal\migrate\Row;
    
    /**
     * @MigrateProcessPlugin(
     *   id = "ip_to_binary",
     *   handle_multiples = false
    
    error: patch failed: src/Plugin/migrate/process/IpToBinary.php:8
    error: src/Plugin/migrate/process/IpToBinary.php: patch does not apply
  • šŸ‡·šŸ‡ŗRussia sorlov

    Tried to apply patch from #19 to latest 8.x-1.x version and got no errors

  • Status changed to Needs work 9 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @sorlov,

    I applied patch #19 to 8.x-1.x-dev and it was applied smoothly.

    However, when I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml, I still encountered some issues.

    āžœ  migrate_generator git:(8.x-1.6) curl https://www.drupal.org/files/issues/2023-09-18/phpcs-3354780-19.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 24849  100 24849    0     0  97920      0 --:--:-- --:--:-- --:--:-- 98217
    patching file README.md
    patching file migrate_generator_export/README.md
    patching file migrate_generator_export/src/Commands/DrushCommands.php
    patching file migrate_generator_export/src/ExportManager.php
    patching file migrate_generator_export/src/FieldsExportManager.php
    patching file migrate_generator_export/src/Form/EntityTypeExportConfigForm.php
    patching file migrate_generator_export/src/Form/ExportForm.php
    patching file migrate_generator_export/src/Plugin/GeneratorExportPluginDateBase.php
    patching file migrate_generator_export/src/Plugin/migrate_generator_export/process/FileExport.php
    patching file src/Plugin/GeneratorProcessPluginBase.php
    patching file src/Plugin/GeneratorProcessPluginDateBase.php
    patching file src/Plugin/migrate/process/IpToBinary.php
    āžœ  migrate_generator git:(8.x-1.6) āœ— ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml migrate_generator
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/README.md
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------
     120 | WARNING | Line exceeds 80 characters; contains 105 characters
    ----------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/migrate_generator_export/README.md
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 10 WARNINGS AFFECTING 10 LINES
    -----------------------------------------------------------------------------------------------------------------------
     12 | WARNING | Line exceeds 80 characters; contains 82 characters
     14 | WARNING | Line exceeds 80 characters; contains 112 characters
     15 | WARNING | Line exceeds 80 characters; contains 89 characters
     19 | WARNING | Line exceeds 80 characters; contains 106 characters
     30 | WARNING | Line exceeds 80 characters; contains 156 characters
     35 | WARNING | Line exceeds 80 characters; contains 85 characters
     40 | WARNING | Line exceeds 80 characters; contains 93 characters
     45 | WARNING | Line exceeds 80 characters; contains 121 characters
     50 | WARNING | Line exceeds 80 characters; contains 93 characters
     53 | WARNING | Line exceeds 80 characters; contains 86 characters
    -----------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/migrate_generator_export/src/GeneratorExportPluginManager.php
    --------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Plugin\FallbackPluginManagerInterface.
    --------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/migrate_generator_export/src/Plugin/GeneratorExportPluginInterface.php
    -----------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Plugin\PluginInspectionInterface.
    -----------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/migrate_generator_export/src/Commands/DrushCommands.php
    --------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------------
     77 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
    --------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/migrate_generator_export/src/FieldsExportManager.php
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Plugin\Exception\PluginNotFoundException.
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/src/Plugin/GeneratorProcessPluginBase.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Psr\Log\LoggerInterface.
    ------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/src/GeneratorProcessPluginManager.php
    ------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Plugin\FallbackPluginManagerInterface.
    ------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/src/Scanner.php
    --------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------------------------------
      7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Entity\EntityFieldManager.
     60 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     60 | ERROR | [x] The closing parenthesis of a multi-line function declaration must be on a new line
    --------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/src/Commands/DrushCommands.php
    ---------------------------------------------------------------------------------------------------------------------------
    FOUND 5 ERRORS AFFECTING 3 LINES
    ---------------------------------------------------------------------------------------------------------------------------
      6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\migrate_generator\Scanner.
     70 | ERROR | [x] The first parameter of a multi-line function declaration must be on the line after the opening bracket
     70 | ERROR | [x] Multi-line function declarations must define one parameter per line
     78 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     78 | ERROR | [x] The closing parenthesis of a multi-line function declaration must be on a new line
    ---------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/migrate_generator/src/Generator.php
    -------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------
     10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\migrate_plus\Entity\Migration.
    -------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------
    
    Time: 978ms; Memory: 12MB
    
    āžœ  contrib git:(main) āœ—

    Thank you.

  • Pipeline finished with Success
    9 months ago
    Total: 174s
    #181989
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡®šŸ‡³India dev16.addweb

    Hi,
    I have fixed the issue mentioned in #24. Please review the attached patch.

  • Status changed to Needs review 8 months ago
  • Pipeline finished with Success
    8 months ago
    Total: 143s
    #195274
  • Pipeline finished with Success
    8 months ago
    Total: 145s
    #195278
Production build 0.71.5 2024