digitalutsc / islandora_lite_docs

Contains a Wiki with documentation for the UTSC Library's Islandora Lite System
GNU General Public License v3.0
2 stars 0 forks source link

Check deprecation code in PHP 8.1 for our modules #84

Open kylehuynh205 opened 1 year ago

kylehuynh205 commented 1 year ago

Download and run build for islandora lite isle-dc with islandora_lite_2023: https://github.com/digitalutsc/isle-dc/tree/islandora_lite_2023

Tools:

Other sources:

https://www.drupal.org/docs/upgrading-drupal/prepare-major-upgrade/deprecation-checking-and-correction-tools-to-prepare-for-a-new-drupal-major-version

amym-li commented 1 year ago

PHP Deprecation

Phan Logs (Updated)

phan_logs.zip

The contrib modules were tested against PHP 8.1 using Phan. A complete set of log messages can be found in analysis.txt. The other text files are named after their respective modules and contain errors specific to that module. The files in phan_logs/deprecated contain deprecation-related errors only. (Some 8.2 deprecation warnings are included as well).

Edit: The zip file also contains logs for assign_calc and Views URL Path Arguments

To generate these logs:

  1. Install Phan and php-ast
  2. Create isle-dc/codebase/.phan/config.php
    
    <?php

return [ // Supported values: '5.6', '7.0', '7.1', '7.2', '7.3', // '7.4', '8.0', '8.1', null. 'target_php_version' => 8.1,

// directories to parse and analyze
'directory_list' => [
    'web/modules/contrib',
    'web/core/lib/Drupal',
    'vendor'
],

'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
'exclude_analysis_directory_list' => [
    'web/core/lib/Drupal',
    'vendor/'
],

'analyzed_file_extensions' => [
    'php',
]

];

3. Create `isle-dc/codebase/generate_phan.sh`

```bash 
#!/bin/bash

src=web/modules/contrib # directory to analyze
dest=phan_logs # output directory
depdest=$dest/deprecated

mkdir -p $dest
mkdir -p $depdest

# get phan output
output=$dest/analysis.txt
# ./vendor/bin/phan -o $output

# generate separate files for each module
for module in $src/*; do

    msgs=$dest/$(basename "$module").txt
    deponly=$depdest/$(basename "$module").txt

    grep "$module" $output > $msgs

    # get lines containing deprecation messages
    grep 'PhanDeprecated' $msgs > $deponly

    # remove file if empty (no logs)
    if [[ -z $(grep '[^[:space:]]' $msgs) ]]; then
        rm $msgs
    fi

    if [[ -z $(grep '[^[:space:]]' $deponly) ]]; then
        rm $deponly
    fi

    echo $module
done
  1. Run script inside isle-dc/codebase
./generate_phan.sh

** If permission denied, check if you have execute permissions by running ls -l generate_phan.sh. If not, run chmod +x generate_phan.sh.

Additional Logs

PHPStan Logs

phpstan_logs.zip

I did a quick search through the logs for deprecation warnings and there don't seem to be any specific to PHP 8.1, though there were some module specific deprecation warnings (i.e. facets, group, migrate_plus). The contrib modules were analyzed using rule level 9 and PHPStan Deprecation Rules.

PHP_CodeSniffer Logs

phpcs_pc_logs.txt

The contrib modules were tested using the PHPCompatibility (dev) coding standard with PHP 8.1. There weren't any PHP 8.1 deprecation warnings, but there were a few messages about the soft reserved keyword resource which was added in PHP 7.0 being used as part of a namespace.

amym-li commented 1 year ago

Drupal 10 Deprecation

Checking Drupal Deprecation using PHPStan

drupal_phpstan_logs.zip

These logs contain only Drupal 10 deprecation errors without any additional code analysis or code checking. This differs from the drupal-check logs which include code analysis, coding style and PHPDoc errors.

References: mglaman/drupal-check: Rollback update to PHPStan level 2 for deprecation analysis was used to set up PHPStan for drupal deprecation checking.

drupal-check logs

drupal_check_logs.zip (includes logs for assign_calc and views_url_path_arguments)

The zip file above contains the output of running drupal-check. Each text file is named after its respective module.

To generate these logs:

  1. Install drupal-check

  2. Create isle-dc/codebase/generate.sh

    
    #!/bin/bash

dir="web/modules/contrib" target="drupal_check_logs" # output directory

mkdir -p $target

for module in $dir/*; do out=$target/$(basename "$module").txt ./vendor/bin/drupal-check -d $module > $out done


3. Run script inside codebase
```bash
isle-dc/codebase$ ./generate.sh
kstapelfeldt commented 1 year ago

Task list for review

  1. Report back PhP 8 errors on the 11 or so modules
  2. Advanced Search fixes
  3. Citation Select fixes
  4. Rest OAIPMH fixes
amym-li commented 1 year ago

Checking PHP 8.1 Errors: (task complete)

https://docs.google.com/spreadsheets/d/1BpmG4V_6tfpmPsmeYon62ty9q-_9fEKQYffL4wSjYKs/edit?usp=sharing

Checking Drupal 10 Errors: