#!/bin/bash ## Description: convertoop ## Usage: convertoop ## Example: convertoop if [ -z "$1" ]; then read -p "Please enter a directory to convert: " directory else directory="$1" fi composer config repositories.nlighteneddesign vcs https://github.com/nlighteneddesign/drupal-rector composer require palantirnet/drupal-rector:dev-rectorOOPHooks cat << 'EOF' > rector.php rule(\DrupalRector\Rector\Convert\HookConvertRector::class); if (class_exists('DrupalFinder\DrupalFinderComposerRuntime')) { $drupalFinder = new \DrupalFinder\DrupalFinderComposerRuntime(); } else { $drupalFinder = new \DrupalFinder\DrupalFinder(); $drupalFinder->locateRoot(__DIR__); } $drupalRoot = $drupalFinder->getDrupalRoot(); $rectorConfig->autoloadPaths([ $drupalRoot . '/core', $drupalRoot . '/modules', $drupalRoot . '/profiles', $drupalRoot . '/themes' ]); $rectorConfig->skip(['*/upgrade_status/tests/modules/*']); $rectorConfig->fileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); $rectorConfig->importNames(true, false); $rectorConfig->importShortClasses(false); }; EOF ./vendor/bin/rector --config ./rector.php process $directory composer phpcbf for dir in $(find $directory -type d -name "Hook"); do echo "Processing: $dir" ./vendor/bin/phpcbf \ --standard="Drupal,DrupalPractice" -n \ --extensions="php,module,inc,install,test,profile,theme" \ $dir done # Run composer fix a second time it cleans up some things after the manual run composer phpcbf find "$directory" -name \*.module| xargs grep -LE "^(function|CONST|define)" | xargs rm; git checkout HEAD core/tests/fixtures/empty_file.php.module find "$directory" -name \*.inc| xargs grep -LE "^(function|CONST|define)" | xargs rm cat << 'EOF' > core/.phpstan-baseline.php ['ignoreErrors' => $ignoreErrors]]; EOF ./vendor/bin/phpstan analyze --configuration=./core/phpstan.neon.dist --memory-limit=-1 --generate-baseline=core/.phpstan-baseline.php