Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error, unexpected XYZ #8083

Closed
Metztli opened this issue Jul 24, 2023 · 4 comments
Closed

Syntax error, unexpected XYZ #8083

Metztli opened this issue Jul 24, 2023 · 4 comments
Labels

Comments

@Metztli
Copy link

Metztli commented Jul 24, 2023

Bug Report

Syntax error, unexpected After 50 such errors rector stops process
Rector 0.17.6 e.g. v0.11.5 (invoke vendor/bin/rector --version)

Applied ECS coding rules, one by one,
SetList::SPACES,
SetList::ARRAY,
SetList::DOCBLOCK,
SetList::NAMESPACES
SetList::COMMENTS,
SetList::PSR_12,

to essentially PHP App source b2evolution. Subsequently, I used rector to attempt upgrade to PHP 8.0

Minimal PHP Code Causing Issue

https://github.com/b2evolution/b2evolution/blob/master/inc/_ext/phpwhois/whois.eu.php

`require_once('whois.parser.php');

if (!defined('EU_HANDLER')) {
define('EU_HANDLER', 1);
}

class eu_handler
{
public function parse($data, $query)
{
$r = [];
$items = [
'domain.name' => 'Domain:',
'domain.status' => 'Status:',
'domain.nserver' => 'Name servers:',
'domain.created' => 'Registered:',
'domain.registrar' => 'Registrar:',
'tech' => 'Registrar Technical Contacts:',
'owner' => 'Registrant:',
'' => 'Please visit',
];

    $extra = [
'organisation:' => 'organization',
        'website:' => 'url',

];

    $r['regrinfo'] = get_blocks($data['rawdata'], $items);

    if (!empty($r['regrinfo']['domain']['status'])) {
        $r['regrinfo']['registered'] = match ($r['regrinfo']['domain']['status']) {
            'FREE', 'AVAILABLE' => 'no',
            'APPLICATION PENDING' => 'pending',
            default => 'unknown',
        };
    } else {
        $r['regrinfo']['registered'] = 'yes';
    }

    if (isset($r['regrinfo']['tech'])) {
        $r['regrinfo']['tech'] = get_contact($r['regrinfo']['tech'], $extra);
    }

    if (isset($r['regrinfo']['domain']['registrar'])) {
        $r['regrinfo']['domain']['registrar'] = get_contact($r['regrinfo']['domain']['registrar'], $extra);
    }

    $r['regyinfo']['referrer'] = 'http://www.eurid.eu';
    $r['regyinfo']['registrar'] = 'EURID';
    return $r;
}

}
`

Nothing is output at:
rector-error-fragment.txt

https://getrector.com/demo/9ae5cd57-4ed0-41cb-927e-f40649217bf7

Expected Behaviour

Upgrade to PHP 8.0 should be smooth.

I am guessing issues are in rector...

@Metztli Metztli added the bug label Jul 24, 2023
@TomasVotruba
Copy link
Member

Hi, thanks for reporting.

The provided demo link passes well 👍 Could you update it to fail?
Otherwise we cannot do anything without seeing the bug.

@Metztli
Copy link
Author

Metztli commented Jul 24, 2023

Hello-
Thanks for your reply. However, I placed another file of 1277 lines of code (including comments) the online rector bombed out stating that I should decrease it by 100 lines of code.

I removed all the comment lines and the file decreased to 940 lines of code; notwithstanding, the online rector bombed out again stating that I should decrease by 100 lines of code(again!).

I got fifty(50) similar errors on my side before rector bombs out on me and probably I will try again the online rector sometime during the weekend. Feel free to close this issue as I do not know what's going on -- as seen in the attached file.

Best regards.

@TomasVotruba
Copy link
Member

There is a limit of 100 lines max for the demo website, to keep test fixtures low. The origin of bugs is usually 2-3 lines of code and single Rector rule.

We're unable to handle the issue without the code causing it, so we have to close this one.
Feel free to re-open with reproducible repository on Github or failing demo link with reproducer error. Thanks for understanding

@Metztli
Copy link
Author

Metztli commented Nov 17, 2023

Upgraded to Rector 0.18.10.

Given the fact that Rector does not seem to scale well, I have fed it a few problematic php files, i.e., showstoppers when I run the PHP application:

This function here:

function widget_container_customize_params($params, $wico_code, $wico_name)
{
    global $Collection, $Blog, $Session;

    $params = array_merge([
        'container_display_if_empty' => true, // FALSE - If no widget, don't display container at all, TRUE - Display container anyway
        'container_start' => '',
        'container_end' => '',
    ], $params);

    // Enable the designer mode when it is turned on from evo menu under "Designer Mode/Exit Designer" or "Collection" -> "Enable/Disable designer mode"
    if (is_logged_in() && $Session->get('designer_mode_' . $Blog->ID)) {	// Initialize hidden element with data which are used by JavaScript to build overlay designer mode html elements:
        if ($wico_code === null) {	// Display error if container cannot be detected in DB by name:
            echo ' <span class="text-danger">' . sprintf(T_('Container "%s" cannot be manipulated because it lacks a code name in the skin template.'), $wico_name) . '</span> ';
        } elseif (preg_match('#<[^>]+evo_container[^>]+>#', $params['container_start'], $container_start_wrapper)) {	// If container start param has a wrapper like '<div class="evo_container">':
            $designer_mode_data = [
                'data-name' => $wico_name,
                'data-code' => $wico_code,
            ];
            if (check_user_perm('blog_properties', 'edit', false, $Blog->ID)) {	// Set data to know current user has a permission to edit this widget:
                $designer_mode_data['data-can-edit'] = 1;
            }
            // Append new data for container wrapper:
            $attrib_actions = [
                'data-name' => 'replace',
                'data-code' => 'replace',
                'data-can-edit' => 'replace',
            ];
            $params['container_start'] = str_replace($container_start_wrapper[0], update_html_tag_attribs($container_start_wrapper[0], $designer_mode_data, $attrib_actions), $params['container_start']);
        } else {	// If container code is NOT defined or detected by name or container wrapper is not correct:
            echo ' <span class="text-danger">' . sprintf(T_('Container %s cannot be manipulated because wrapper html tag has no %s.'), '"' . $wico_name . '"(<code>' . $wico_code . '</code>)', '<code>class="evo_container"</code>') . '</span> ';
        }

        // Force to display container even if no widget:
        $params['container_display_if_empty'] = true;
    }

    // Replace variables/masks in params with widget container properties;
    // Possible variables/masks in params:
    //   - $wico_class$ - Widget container class
    $params = str_replace('$wico_class$', 'evo_container__' . str_replace(' ', '_', $wico_code), $params);

    return $params;
}

from:
https://github.com/Metztli/b2evolution/blob/master/inc/skins/_skin.funcs.php

produces error when the PHP application is run locally, in development machine:
Fatal error: Uncaught Error: Object of class WidgetContainer could not be converted to string in /var/www/b2evoecs/inc/skins/_skin.funcs.php:2803 Stack trace: #0 /var/www/b2evoecs/inc/skins/_skin.funcs.php(2803): str_replace() #1 /var/www/b2evoecs/inc/skins/model/_skin.class.php(441): widget_container_customize_params() #2 /var/www/b2evoecs/inc/skins/_skin.funcs.php(2709): Skin->container() #3 /var/www/b2evoecs/skins/default_site_skin/_site_body_header.inc.php(21): widget_container() #4 /var/www/b2evoecs/inc/skins/_skin.funcs.php(2162): require('...') #5 /var/www/b2evoecs/skins/bootstrap_blog_skin/index.main.php(37): siteskin_include() #6 /var/www/b2evoecs/inc/_blog_main.inc.php(995): require('...') #7 /var/www/b2evoecs/index.php(68): require('...') #8 {main} thrown in /var/www/b2evoecs/inc/skins/_skin.funcs.php on line 2803

I have ran that function through your demo:
https://getrector.com/demo/55e52c13-7b0a-4966-bdff-bdb313c435a5

which leaves the function untouched.

Obviously, Rector is not upgrading the PHP 7.4 application code to (at least) PHP 8.0 .

P.S. I have inherited (forked) this PHP application from developers who should have fixed the code when it was PHP 7.4 as since then it was showing a warning to that effect. Notwithstanding, PHP 8.0 will not output a warning but will produce a failure, as shown above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants