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}
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

View file

@ -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
]);
};

View file

@ -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.

View file

@ -690,22 +690,18 @@ class Parser {
* for transparency. It isnt indented though (the PHP open tag neither).
*/
if ( General::$alternative_tooltips_enabled ) {
// Start internal script.
?>
<script content="text/javascript">
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');
}
</script>
<?php
// Indenting this PHP open tag would mess up the page source.
// End internal script.
echo ('
<script content="text/javascript">
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");
}
</script>
');
};
}
@ -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' => '&nbsp;&#x2013;',
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 = '&nbsp;&#x2013;';
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 {