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

invalid php generated #1

Open
cabbey opened this issue May 12, 2022 · 1 comment
Open

invalid php generated #1

cabbey opened this issue May 12, 2022 · 1 comment

Comments

@cabbey
Copy link

cabbey commented May 12, 2022

I'm not going to claim the source PHP the tool was asked to deal with was good. Far from it, it was horrible. But the tool's output was worse in so far as it was invalid php.

Input: ($arr[$opt] ? '1' : null) ?: '0'
Output: ($arr[$opt] ? '1' : null ?? '0'

The context around it: that line is an argument to a function being called.... something like this:

<?php

class test {
    function weird(string $variable) {
        $array = [
            'a' => 'apple',
            'b' => 'bananana',
        ];
     
        $this->target(
            'Alpha',
            'Bravo',
            ($array[$variable] ? 'Charlie' : null) ?: 'Delta'
        );
            
    }

    function target(string $one, string $two, string $three) {
        echo "$one $two $three" . PHP_EOL;
    }
}

$thing = new test();
$thing->weird('a');
$thing->weird('z');

(once the resulting php syntax error brought my attention to this bit of code, it was thoroughly re-written and no longer resembles... whatever you want to call the above. I'm filing this just in the hopes you can see an obvious fix and save others from bit of panic that sets in when a commit that was 100% automated tooling fails on a pre-commit hook as simple as a syntax check.)

@orklah
Copy link
Owner

orklah commented May 14, 2022

Hey! Thanks for the feedback. Don't worry, no judgment there, the project for which I made this plugin initially was probably worse!

I'll try to take a look at it soon!

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

2 participants