From 94c480900a625bc5bf166a228a358c7141b0a660 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Wed, 12 May 2021 08:18:15 +0100 Subject: [PATCH] fix: fix Rector downgrading See https://github.com/rectorphp/rector/issues/6315 --- _tools/build.sh | 4 ++ rector.php | 17 +++---- src/includes/class-convert.php | 2 +- src/public/class-parser.php | 82 +++++++++++++++++++++------------- 4 files changed, 63 insertions(+), 42 deletions(-) diff --git a/_tools/build.sh b/_tools/build.sh index 6ef7346..eca7823 100755 --- a/_tools/build.sh +++ b/_tools/build.sh @@ -34,6 +34,10 @@ echo "Deleting unminified files from `dist/`..." rm -r dist/*/{js,css}/*[^\.min].{js,css} echo "Minification complete." +echo "Downgrading to PHP 7.4..." +./vendor/bin/rector process +echo "Downgrading complete." + if [[ $1 == "-v" ]]; then rm -rf ../VVV/www/wordpress-two/public_html/wp-content/plugins/footnotes mv dist footnotes && mv footnotes ../VVV/www/wordpress-two/public_html/wp-content/plugins diff --git a/rector.php b/rector.php index fd5241c..d068f29 100644 --- a/rector.php +++ b/rector.php @@ -4,8 +4,8 @@ declare(strict_types=1); use Rector\Core\Configuration\Option; use Rector\Core\ValueObject\PhpVersion; -use Rector\Set\ValueObject\SetList; -//use Rector\Set\ValueObject\DowngradeSetList; +//use Rector\Set\ValueObject\SetList; +use Rector\Set\ValueObject\DowngradeSetList; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { @@ -13,19 +13,14 @@ return static function (ContainerConfigurator $containerConfigurator): void { $parameters = $containerConfigurator->parameters(); $parameters->set(Option::PATHS, [ - __DIR__ . '/src', + __DIR__ . '/dist', ]); - $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74); // Define what rule sets will be applied $parameters->set(Option::SETS, [ - // TODO: - //SetList::PRIVATIZATION - // TODO: in Build - // DowngradeSetList::PHP_80, - // DowngradeSetList::PHP_74, - // DowngradeSetList::PHP_73, - //DowngradeSetList::PHP_72, + //TODO: SetList::PRIVATIZATION + DowngradeSetList::PHP_80 ]); }; diff --git a/src/includes/class-convert.php b/src/includes/class-convert.php index d9c7f1e..3393500 100644 --- a/src/includes/class-convert.php +++ b/src/includes/class-convert.php @@ -75,7 +75,7 @@ class Convert { * Get an HTML array short code depending on Arrow-Array key index. * * @param int $index Index representing the arrow. If empty, all arrows are specified. - * @return string|string[] Array of all arrows if index is empty, otherwise HTML tag of a specific arrow. + * @return string|string[] Array of all arrows if index is empty, otherwise HTML tag of a specific arrow. * * @since 1.3.2 * @todo Review. diff --git a/src/public/class-parser.php b/src/public/class-parser.php index 42ca4f9..41c5c5b 100644 --- a/src/public/class-parser.php +++ b/src/public/class-parser.php @@ -690,22 +690,18 @@ class Parser { * for transparency. It isn’t indented though (the PHP open tag neither). */ if ( General::$alternative_tooltips_enabled ) { - - // Start internal script. - ?> - - + function footnote_tooltip_show(footnote_tooltip_id) { + document.getElementById(footnote_tooltip_id).classList.remove("hidden"); + document.getElementById(footnote_tooltip_id).classList.add("shown"); + } + function footnote_tooltip_hide(footnote_tooltip_id) { + document.getElementById(footnote_tooltip_id).classList.remove("shown"); + document.getElementById(footnote_tooltip_id).classList.add("hidden"); + } + + '); }; } @@ -792,7 +788,9 @@ class Parser { $footnote_section_shortcode = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTE_SECTION_SHORTCODE ); $footnote_section_shortcode_length = strlen( $footnote_section_shortcode ); - if ( ! str_contains( $content, (string) $footnote_section_shortcode ) ) { + // TODO: Replace with `str_contains()`, but currently breaks Rector downgrade. + // https://github.com/rectorphp/rector/issues/6315 + if ( ! strpos( $content, (string) $footnote_section_shortcode ) ) { // phpcs:disable WordPress.PHP.YodaConditions.NotYoda // Appends the reference container if set to "post_end". @@ -809,7 +807,9 @@ class Parser { $section_end = strpos( $rest_content, (string) $footnote_section_shortcode ); $sections_raw[] = substr( $rest_content, 0, $section_end ); $rest_content = substr( $rest_content, $section_end + $footnote_section_shortcode_length ); - } while ( str_contains( $rest_content, (string) $footnote_section_shortcode ) ); + // TODO: Replace with `str_contains()`, but currently breaks Rector downgrade. + // https://github.com/rectorphp/rector/issues/6315 + } while ( strpos( $rest_content, (string) $footnote_section_shortcode ) ); $sections_raw[] = $rest_content; foreach ( $sections_raw as $section ) { @@ -1717,12 +1717,23 @@ class Parser { // If it is not, check which option is on. $separator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_OPTION ); - $separator = match ($separator_option) { - 'comma' => ',', - 'semicolon' => ';', - 'en_dash' => ' –', - default => Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_CUSTOM ), - }; + // TODO: replace with `match` (but currently it breaks the Rector + // downgrade to PHP 7.4. + // https://github.com/rectorphp/rector/issues/6315 + switch ($separator_option) { + case 'comma': + $separator = ','; + break; + case 'semicolon': + $separator = ';'; + break; + case 'en_dash': + $separator = ' –'; + break; + default: + $separator = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_CUSTOM ); + break; + } } } else { @@ -1740,12 +1751,23 @@ class Parser { // If it is not, check which option is on. $terminator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_OPTION ); - $terminator = match ($terminator_option) { - 'period' => '.', - 'parenthesis' => ')', - 'colon' => ':', - default => Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_CUSTOM ), - }; + // TODO: replace with `match` (but currently it breaks the Rector + // downgrade to PHP 7.4. + // https://github.com/rectorphp/rector/issues/6315 + switch ($terminator_option) { + case 'period': + $terminator = '.'; + break; + case 'parenthesis': + $terminator = ')'; + break; + case 'colon': + $terminator = ':'; + break; + default: + $terminator = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_CUSTOM ); + break; + } } } else {