fix: fix Rector downgrading

See https://github.com/rectorphp/rector/issues/6315
This commit is contained in:
Ben Goldsworthy 2021-05-12 08:18:15 +01:00
parent f8d5d73443
commit 94c480900a
4 changed files with 63 additions and 42 deletions

View file

@ -34,6 +34,10 @@ echo "Deleting unminified files from `dist/`..."
rm -r dist/*/{js,css}/*[^\.min].{js,css} rm -r dist/*/{js,css}/*[^\.min].{js,css}
echo "Minification complete." echo "Minification complete."
echo "Downgrading to PHP 7.4..."
./vendor/bin/rector process
echo "Downgrading complete."
if [[ $1 == "-v" ]]; then if [[ $1 == "-v" ]]; then
rm -rf ../VVV/www/wordpress-two/public_html/wp-content/plugins/footnotes 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 mv dist footnotes && mv footnotes ../VVV/www/wordpress-two/public_html/wp-content/plugins

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion; use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList; //use Rector\Set\ValueObject\SetList;
//use Rector\Set\ValueObject\DowngradeSetList; use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void { return static function (ContainerConfigurator $containerConfigurator): void {
@ -13,19 +13,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters(); $parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [ $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 // Define what rule sets will be applied
$parameters->set(Option::SETS, [ $parameters->set(Option::SETS, [
// TODO: //TODO: SetList::PRIVATIZATION
//SetList::PRIVATIZATION DowngradeSetList::PHP_80
// TODO: in Build
// DowngradeSetList::PHP_80,
// DowngradeSetList::PHP_74,
// DowngradeSetList::PHP_73,
//DowngradeSetList::PHP_72,
]); ]);
}; };

View file

@ -690,22 +690,18 @@ class Parser {
* for transparency. It isnt indented though (the PHP open tag neither). * for transparency. It isnt indented though (the PHP open tag neither).
*/ */
if ( General::$alternative_tooltips_enabled ) { if ( General::$alternative_tooltips_enabled ) {
echo ('
// Start internal script. <script content="text/javascript">
?>
<script content="text/javascript">
function footnote_tooltip_show(footnote_tooltip_id) { function footnote_tooltip_show(footnote_tooltip_id) {
document.getElementById(footnote_tooltip_id).classList.remove('hidden'); document.getElementById(footnote_tooltip_id).classList.remove("hidden");
document.getElementById(footnote_tooltip_id).classList.add('shown'); document.getElementById(footnote_tooltip_id).classList.add("shown");
} }
function footnote_tooltip_hide(footnote_tooltip_id) { function footnote_tooltip_hide(footnote_tooltip_id) {
document.getElementById(footnote_tooltip_id).classList.remove('shown'); document.getElementById(footnote_tooltip_id).classList.remove("shown");
document.getElementById(footnote_tooltip_id).classList.add('hidden'); document.getElementById(footnote_tooltip_id).classList.add("hidden");
} }
</script> </script>
<?php ');
// Indenting this PHP open tag would mess up the page source.
// End internal script.
}; };
} }
@ -792,7 +788,9 @@ class Parser {
$footnote_section_shortcode = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTE_SECTION_SHORTCODE ); $footnote_section_shortcode = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTE_SECTION_SHORTCODE );
$footnote_section_shortcode_length = strlen( $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 // phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end". // Appends the reference container if set to "post_end".
@ -809,7 +807,9 @@ class Parser {
$section_end = strpos( $rest_content, (string) $footnote_section_shortcode ); $section_end = strpos( $rest_content, (string) $footnote_section_shortcode );
$sections_raw[] = substr( $rest_content, 0, $section_end ); $sections_raw[] = substr( $rest_content, 0, $section_end );
$rest_content = substr( $rest_content, $section_end + $footnote_section_shortcode_length ); $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; $sections_raw[] = $rest_content;
foreach ( $sections_raw as $section ) { foreach ( $sections_raw as $section ) {
@ -1717,12 +1717,23 @@ class Parser {
// If it is not, check which option is on. // If it is not, check which option is on.
$separator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_OPTION ); $separator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_OPTION );
$separator = match ($separator_option) { // TODO: replace with `match` (but currently it breaks the Rector
'comma' => ',', // downgrade to PHP 7.4.
'semicolon' => ';', // https://github.com/rectorphp/rector/issues/6315
'en_dash' => '&nbsp;&#x2013;', switch ($separator_option) {
default => Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_CUSTOM ), case 'comma':
}; $separator = ',';
break;
case 'semicolon':
$separator = ';';
break;
case 'en_dash':
$separator = '&nbsp;&#x2013;';
break;
default:
$separator = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_SEPARATOR_CUSTOM );
break;
}
} }
} else { } else {
@ -1740,12 +1751,23 @@ class Parser {
// If it is not, check which option is on. // If it is not, check which option is on.
$terminator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_OPTION ); $terminator_option = Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_OPTION );
$terminator = match ($terminator_option) { // TODO: replace with `match` (but currently it breaks the Rector
'period' => '.', // downgrade to PHP 7.4.
'parenthesis' => ')', // https://github.com/rectorphp/rector/issues/6315
'colon' => ':', switch ($terminator_option) {
default => Includes\Settings::instance()->get( \footnotes\includes\Settings::BACKLINKS_TERMINATOR_CUSTOM ), 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 { } else {