Skip to content

Incorrect behavior of IntvalToTypeCastRector, LongArrayToShortArrayRector, TernaryToNullCoalescingRector, ListToArrayDestructRector, ReplaceEachAssignmentWithKeyCurrentRector, NullToStrictStringFuncCallArgRector #7697

@scottybcoder

Description

@scottybcoder

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/63e67a74-5e27-442a-98b7-4b396e3c642a

<?php

// function block
function get_topic_id($topic)
{
    global $db;
    $topic_id = 0;

    // is this a direct value ?
    $num_topic = intval($topic);
    if ($topic == "$num_topic")
    {
        $topic_id = intval($topic);
    }

    // is it an url with topic id or post id ?
    else
    {
        $name = explode('?', $topic);
        $parms = ( isset($name[1]) ) ? $name[1] : $name[0];
        parse_str($parms, $parm);
        $found = false;
        $topic_id = 0;
        while ((list($key, $val) = each($parm)) && !$found):
        
            $vals = explode('#', $val);
            $val = $vals[0];
            if (empty($val)) $val = 0;
            switch($key)
            {
                case POST_POST_URL:
                    $sql = "SELECT topic_id FROM " . POSTS_TABLE . " WHERE post_id=$val";
                    if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post informations', '', __LINE__, __FILE__, $sql);
                    if ($row = $db->sql_fetchrow($result))
                    {
                        $val = $row['topic_id'];
                        $found = true;
                    }
                    break;
                case POST_TOPIC_URL:
                    $found = true;
                    break;
            }
            if ($found)
            {
                $topic_id = intval($val);
            }
        endwhile;
    }

    return $topic_id;
}

Responsible rules

  • IntvalToTypeCastRector

  • LongArrayToShortArrayRector

  • TernaryToNullCoalescingRector

  • ListToArrayDestructRector

  • ReplaceEachAssignmentWithKeyCurrentRector

  • NullToStrictStringFuncCallArgRector

Expected Behavior

I should not get the following error after it modifies my code
syntax error, unexpected token ")", expecting "="

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions