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

Potential false-positive [] operator not supported for strings #1938

Open
Simbiat opened this issue Apr 8, 2024 · 0 comments
Open

Potential false-positive [] operator not supported for strings #1938

Simbiat opened this issue Apr 8, 2024 · 0 comments

Comments

@Simbiat
Copy link

Simbiat commented Apr 8, 2024

Subject Details
Plugin Php Inspections (EA Extended)
Language level PHP 8.3

Current behaviour

In below function

protected function items(): array
    {
        if (!$this->regexfail(preg_match_all(Regex::CHARACTER_GEAR, $this->html, $tempresults, PREG_SET_ORDER), preg_last_error(), 'CHARACTER_GEAR')) {
            return [];
        }
        #Remove non-named groups
        foreach ($tempresults as $key=>$tempresult) {
            foreach ($tempresult as $key2=>$details) {
                if (is_numeric($key2) || empty($details)) {
                    unset($tempresults[$key][$key2]);
                }
            }
            $tempresults[$key]['armoireable'] = $this->converters->imageToBool($tempresult['armoireable']);
            $tempresults[$key]['hq'] = !empty($tempresult['hq']);
            $tempresults[$key]['unique'] = !empty($tempresult['unique']);
            #Requirements
            $tempresults[$key]['requirements'] = [
                'level'=>$tempresult['level'],
                'classes'=>(in_array($tempresult['classes'], ['Disciple of the Land', 'Disciple of the Hand', 'Disciple of Magic', 'Disciple of War', 'Disciples of War or Magic', 'All Classes', 'ギャザラー', 'Sammler', 'Récolteurs', 'Handwerker', 'Artisans', 'クラフター', 'Magier', 'Mages', 'ソーサラー', 'Krieger', 'Combattants', 'ファイター', 'Krieger, Magier', 'Combattants et mages', 'ファイター ソーサラー', 'Alle Klassen', 'Toutes les classes', '全クラス']) ? $tempresult['classes'] : explode(' ', $tempresult['classes'])),
            ];
            #Attributes
            for ($i = 1; $i <= 15; $i++) {
                if (!empty($tempresult['attrname'.$i])) {
                    $tempresults[$key]['attributes'][$tempresult['attrname'.$i]] = $tempresult['attrvalue'.$i];
                    unset($tempresults[$key]['attrname'.$i], $tempresults[$key]['attrvalue'.$i]);
                }
            }
            #Materia
            for ($i = 1; $i <= 5; $i++) {
                if (!empty($tempresult['materianame'.$i])) {
                    $tempresults[$key]['materia'][] = [
                        'name'=>$tempresult['materianame'.$i],
                        'attribute'=>$tempresult['materiaattr'.$i],
                        'bonus'=>$tempresult['materiaval'.$i],
                    ];
                    unset($tempresults[$key]['materianame'.$i], $tempresults[$key]['materiaattr'.$i], $tempresults[$key]['materiaval'.$i]);
                }
            }
            #Crafting
            if (!empty($tempresult['repair'])) {
                $tempresults[$key]['crafting']['class'] = $tempresult['repair'];
                $tempresults[$key]['crafting']['materials'] = $tempresult['materials'];
                if (empty($tempresult['desynthesizable'])) {
                    $tempresults[$key]['crafting']['desynth'] = false;
                } else {
                    $tempresults[$key]['crafting']['desynth'] = $tempresult['desynthesizable'];
                }
                if (empty($tempresult['melding'])) {
                    $tempresults[$key]['crafting']['melding'] = false;
                } else {
                    $tempresults[$key]['crafting']['melding'] = $tempresult['melding'];
                    $tempresults[$key]['crafting']['advancedmelding'] = empty($tempresult['advancedmelding']);
                }
                $tempresults[$key]['crafting']['convertible'] = $this->converters->imageToBool($tempresult['convertible']);
            }
            #Trading
            if (empty($tempresult['price'])) {
                $tempresults[$key]['trading']['price'] = NULL;
            } else {
                $tempresults[$key]['trading']['price'] = $tempresult['price'];
            }
            $tempresults[$key]['trading']['sellable'] = empty($tempresult['unsellable']);
            $tempresults[$key]['trading']['marketable'] = empty($tempresult['marketprohibited']);
            $tempresults[$key]['trading']['tradeable'] = empty($tempresult['untradeable']);
            #Link to shop, if present
            if (empty($tempresult['shop'])) {
                    $tempresults[$key]['trading']['shop'] = NULL;
                } else {
                    $tempresults[$key]['trading']['shop'] = sprintf(Routes::LODESTONE_URL_BASE, $this->language).$tempresult['shop'];
            }
            #Customization
            $tempresults[$key]['customization'] = [
                'crestable'=>$this->converters->imageToBool($tempresult['crestable']),
                'glamourable'=>$this->converters->imageToBool($tempresult['glamourable']),
                'projectable'=>$this->converters->imageToBool($tempresult['projectable']),
                'dyeable'=>$this->converters->imageToBool($tempresult['dyeable']),
            ];
            #Glamour
            if (!empty($tempresult['glamourname'])) {
                $tempresults[$key]['customization']['glamour'] = [
                    'id'=>$tempresult['glamourid'],
                    'name'=>$tempresult['glamourname'],
                    'icon'=>$tempresult['glamouricon'],
                ];
            }
            unset($tempresults[$key]['level'], $tempresults[$key]['classes'], $tempresults[$key]['price'], $tempresults[$key]['unsellable'], $tempresults[$key]['marketprohibited'], $tempresults[$key]['repair'], $tempresults[$key]['materials'], $tempresults[$key]['desynthesizable'], $tempresults[$key]['melding'], $tempresults[$key]['advancedmelding'], $tempresults[$key]['convertible'], $tempresults[$key]['glamourname'], $tempresults[$key]['glamourid'], $tempresults[$key]['glamouricon'], $tempresults[$key]['crestable'], $tempresults[$key]['glamourable'], $tempresults[$key]['projectable'], $tempresults[$key]['dyeable'], $tempresults[$key]['untradeable'], $tempresults[$key]['shop']);
        }
        return $tempresults;
    }

Line with $tempresults[$key]['materia'][] is marked with [EA] Could provoke a PHP Fatal error ([] operator not supported for strings). for no apparent reason. At least if I move this particular assignment to an empty PHP file - such error is not indicated. Adding logic that checks for existence of $tempresults[$key]['materia'] and sets it to [] does not help. Adding Is_array check does not help either.
For reference whole file is here.

Expected behaviour
No error is shown at all, or at least it goes away after adding appropriate check or explicit assignment

Environment details

PhpStorm 2024.1
Build #PS-241.14494.237, built on March 27, 2024
Licensed to simbiat.ru / Dmitry Kustov
Subscription is active until May 11, 2024.
For non-commercial open source development only.
Runtime version: 17.0.10+8-b1207.12 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 5120M
Cores: 16
Registry:
  debugger.new.tool.window.layout=true
  run.processes.with.pty=TRUE
  ide.experimental.ui=true
Non-Bundled Plugins:
  com.jetbrains.space (241.14494.150)
  com.intellij.ml.llm (241.14494.240)
  com.kalessil.phpStorm.phpInspectionsEA (5.0.0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant