[Phpmyadmin-devel] New PHPCS rule

Hugues Peccatte hugues.peccatte at gmail.com
Mon Dec 16 19:12:37 CET 2013


2013/12/16 Marc Delisle <marc at infomarc.info>

> Le 2013-12-15 14:36, Hugues Peccatte a écrit :
> > Hi,
> >
> > What would you think about using the "nesting level" sniff please?
> > This sniff permits to detect when there are too much nested levels like:
> > if (...) {
> >     if (...) {
> >         if (...) {
> >             if (...) {
> >                 if (...) {
> >                     ....
> >                 }
> >             }
> >         }
> >     }
> > }
> >
> > This kind of syntax often means that a refactoring is needed or a
> rewrite.
> >
> > I can add it myself if you agree.
> >
>
> Good idea but how many levels is considered "too many"?  Can you give an
> example of nesting levels you found?
>
>
> --
> Marc Delisle
> http://infomarc.info | http://phpmyadmin.net
>
>
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT
> organizations don't have a clear picture of how application performance
> affects their revenue. With AppDynamics, you get 100% visibility into your
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics
> Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> _______________________________________________
> Phpmyadmin-devel mailing list
> Phpmyadmin-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/phpmyadmin-devel
>


Hi,

To add this new rule won't add to many PHPCS errors. I already test this
rule and there are currently not so much this errors in the sources. (I
don't have an exact count. I would say around 20-30.)

See:
http://www.squizlabs.com/php-codesniffer/php_codesniffer-ruleset.xml-support-in-svn
See:
http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php

The rule could be:
  <rule ref="Generic.Metrics.NestingLevel">
    <properties>
      <property name="nestingLevel" value="2" />
      <property name="absoluteNestingLevel" value="5" />
    </properties>
  </rule>

We don't need to define both properties.
"nestingLevel" is the number of nested level which throw a warning.
(default = 5)
"absoluteNestingLevel" is the maximum of allowed nested levels. (default =
10)

I think that the default values don't need to be overridden, so the rule
would be:
<rule ref="Generic.Metrics.NestingLevel" />

Hugues.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20131216/71e81d53/attachment.html>


More information about the Developers mailing list