GithubHelp home page GithubHelp logo

Comments (9)

photodude avatar photodude commented on August 17, 2024

Is this a short array definition issue?

I assume the source should look something like this, if it was including php5.3 support.

echo (new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts'))->render(
            array(
                     'results' => $results,
                     'enabled' => $enabled,
            )
        )

The sniffs are currently (and in the phpcs2 draft) rejecting short array use as to maintain compatibility with Joomla projects still supporting php5.3 (Oh the things we could do if php5.3 was truly dead and not supported by Joomla projects)

from coding-standards.

mbabker avatar mbabker commented on August 17, 2024

Changed it to run with full array syntax and the same error.

https://github.com/joomla/coding-standards/blob/master/Sniffs/Functions/StatementNotFunctionSniff.php

That sniff looks for the next token after one of the registered tokens and if it's an open parenthesis it raises an error. So it won't accept PHP 5.4 syntax in this context.

from coding-standards.

photodude avatar photodude commented on August 17, 2024

Looking at the source pear sniff, we added the tokens T_CLONE, and T_ECHO
on echo is where I think it's throwing the error
Since echo is not actually a function (it is a language construct) the brackets are not required. but I'm not sure about echo 's behavior when followed immediately by new...

If I follow the Brackets right I think there is a misplaced one before the render call that should be at the end

echo (new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts')->render(
            array(
                     'results' => $results,
                     'enabled' => $enabled,
            )
        ))

Which would follow the format

$layout = new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts');
echo $layout->render(array('results' => $results, 'enabled' => $enabled,));

or the format

$layout = new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts');
$data = array('results' => $results, 'enabled' => $enabled,);
echo $layout->render($data);

from coding-standards.

mbabker avatar mbabker commented on August 17, 2024

That looks about right at a quick glance. Basically, a sequence of T_ECHO T_OPEN_PARENTHESIS T_NEW should be allowed but right now the sniffer is groaning because of the T_OPEN_PARENTHESIS being present.

from coding-standards.

photodude avatar photodude commented on August 17, 2024

So we need to decide if echo can be allowed to use parenthesis. if yes, then that token should be removed from the sniff.

from coding-standards.

mbabker avatar mbabker commented on August 17, 2024

I personally don't care either way as long as it allows PHP 5.4 syntax. I get Joomla still supports 5.3 code but that shouldn't force us who aren't to write code resembling it. If that means echo in general allows echo (T_WHATEVER); statements as a side effect I guess we'll have to accept it.

from coding-standards.

photodude avatar photodude commented on August 17, 2024

Looking deeper at the sniff, Short array is a separate question enforced by other sniffs. (sorry, I shot off the cuff with my first response assuming the short array was the cause).
I think in the phpcs2 draft it's a question of Generic.Arrays.DisallowShortArraySyntax as an included or excluded sniff.

For this error it's the specific to the T_ECHO token in the sniff. We remove that token we then get echo (T_WHATEVER); statements being allowed.

from coding-standards.

mbabker avatar mbabker commented on August 17, 2024

Honestly, we're probably better off removing it. Between the T_ECHO T_OPEN_PARENTHESIS T_NEW sequence and echoing a typecast object (echo (int) $object->getCount();) it might be more trouble than it's worth to enforce it.

from coding-standards.

photodude avatar photodude commented on August 17, 2024

Fixed in the PHPCS2 draft branch as well.

from coding-standards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.