Working on PHPCS Deprecated Sniffs: testers / input needed

438 views
Skip to first unread message

Ruud van Lent

unread,
Nov 30, 2017, 9:23:45 AM11/30/17
to Joomla! General Development
Hi,

I am working a a new set of Joomla Coding Standards Sniffs: check for and report deprecated Joomla! classes and deprecated Joomla! functions.

What this will enable you to do is 'extend' every code editor that is capable of doing PHPCS with deprecated Joomla functions and classes. (phpstorm and eclipe have this functionality build in, but a lot of other IDE's or code editors do not have that).

This solution will make the check editor / ide independent!

I am using Geany (geany,org) myself (switched from Eclipse, never looked back).
When running a PHPCS from within Geany on my project I get the following (example) output where every line is linked to the actual line in the code:

-------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND
17 ERRORS AFFECTING 17 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------
 
107 | ERROR | The use of class JFactory is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Factory instead.
 
109 | ERROR | The use of function isSite is deprecated in Joomla version 3.2 and removed in Joomla version 5.0; Use isClient('site') instead.
 
246 | ERROR | The use of class JFactory is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Factory instead.
 
250 | ERROR | The use of class JURI is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Uri\Uri instead.
 
253 | ERROR | The use of class JURI is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Uri\Uri instead.
 
263 | ERROR | The use of class JRoute is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Router\Route instead.

If you interested and want to help test and figure some stuff out, please feel free to contact me here: I will provide you with a link and instructions of what I have cooked up until now :)

Thanks in advance!
regards,
Ruud.
 



rolandd

unread,
Dec 28, 2017, 2:53:29 AM12/28/17
to Joomla! General Development
Hello Ruud,

I am interested in testing this and I use PhpStorm so I can see how it works there. If you can provide me with the details I can take a look.

Regards,

Roland

Ruud van Lent

unread,
Dec 28, 2017, 4:23:33 AM12/28/17
to Joomla! General Development
Hoi Roland,

Cool :) here you can find the needed files and some basic instructions. There are two things that need testing / adjusting / thinking: 1. the mechanism > does it work in your IDE (report deprecated functions) and 2. what should be reported (I now have a bunch of deprecated functions in there that need tuning / adjusting / etc.)

Would love to get some feedback on 1. and 2. :)

https://github.com/Ruud68/coding-standards/tree/master/Joomla/Sniffs/Deprecated

rolandd

unread,
Dec 28, 2017, 9:45:52 AM12/28/17
to Joomla! General Development
Hello Ruud,

I have been able to install the deprecated Codesniffs and they work fine from the command line. In PhpStorm it is not possible to pass arguments to phpcs so I created 2 external tools in PhpStorm, one for checking the active file and the other for the active folder. Now I just added your 2 sniffs to the existing Joomla sniffs I have and the output looks like this:

-----------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 5 LINES
-----------------------------------------------------------------------------------------------------------------------------------------------------
   58 | ERROR | [ ] The use of class JFactory is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Factory instead.
 108 | ERROR | [x] Expected 0 spaces before closing bracket; 1 found
 111 | ERROR | [x] No blank line found after control structure
 112 | ERROR | [x] Please consider an empty line before the if statement;
 112 | ERROR | [x] Expected 0 spaces before closing bracket; 1 found
 123 | ERROR | [x] Missing space between the // and the start of the comment text.
-----------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------------------------------

So the mechanism works with some workaround.

As for your second point as to what should be reported, they are the same as to what is currently reported from the docblocks. This is fine if you ask me. What would be cool is if this could be about fixed. I haven't played yet with autofixers but doing this manual task is becoming a bit of a nuisance :)

Have you tried the autofixers as the message reports?

Regards,

Roland

rolandd

unread,
Dec 28, 2017, 10:31:29 AM12/28/17
to Joomla! General Development
Hey Ruud,

One more finding, when I have a class like this:

class FooModelBar extends JModelAdmin

your sniff doesn't find the JModelAdmin as deprecated and should be \Joomla\CMS\MVC\Model\AdminModel

Regards,

Roland

Anibal

unread,
Jan 4, 2018, 10:22:36 AM1/4/18
to Joomla! General Development
Hi,

I'm testing the sniffs... but they are not detecting the deprecated classes. They are being loaded.... but not detecting the issues. They should detect the presence of JUri or JPlugin.

The testing command:

phpcs -e --standard=...../Joomla /home/.../mytest.php

Output:

Joomla (15 sniffs)
------------------
  Joomla.Classes.InstantiateNewClasses
  Joomla.Commenting.ClassComment
  Joomla.Commenting.FileComment
  Joomla.Commenting.FunctionComment
  Joomla.Commenting.SingleComment
  Joomla.ControlStructures.ControlSignature
  Joomla.ControlStructures.ControlStructuresBrackets
  Joomla.ControlStructures.WhiteSpaceBefore
  Joomla.Deprecated.DeprecatedClasses
  Joomla.Deprecated.DeprecatedFunctions
  Joomla.Functions.StatementNotFunction
  Joomla.NamingConventions.ValidFunctionName
  Joomla.NamingConventions.ValidVariableName
  Joomla.Operators.ValidLogicalOperators
  Joomla.WhiteSpace.MemberVarSpacing

The default command only generates these errors:

----------------------------------------------------------------------
FOUND 12 ERRORS AND 2 WARNINGS AFFECTING 9 LINES
----------------------------------------------------------------------
 24 | ERROR   | Private member variable "_alias" must not contain a
    |         | leading underscore
 24 | ERROR   | Missing member variable doc comment
 26 | ERROR   | Private member variable "_title" must not contain a
    |         | leading underscore
 26 | ERROR   | Missing member variable doc comment
 28 | ERROR   | Private member variable "_init" must not contain a
    |         | leading underscore
 28 | ERROR   | Missing member variable doc comment
 30 | ERROR   | Private member variable "_helper" must not contain a
    |         | leading underscore
 30 | ERROR   | Missing member variable doc comment
 69 | WARNING | Line exceeds 150 characters; contains 207 characters
 78 | ERROR   | Variable "detection_class" is not in valid camel caps
    |         | format
 79 | ERROR   | Variable "detection_class" is not in valid camel caps
    |         | format
 79 | ERROR   | Variable "detection_class" is not in valid camel caps
    |         | format
 80 | ERROR   | Variable "detection_class" is not in valid camel caps
    |         | format
 91 | WARNING | Line exceeds 150 characters; contains 191 characters
----------------------------------------------------------------------


This test is in PHP 7.0.22 and PHPCS 2.9.1.

Thank you in advance!
Anibal

Ruud van Lent

unread,
Jan 5, 2018, 7:52:52 AM1/5/18
to Joomla! General Development
Hi Anibal,

the sniffs are always loaded but need to be enabled via a parameter to be able to detect (that was one of the requirements).
the instructions are here: https://github.com/Ruud68/coding-standards/tree/master/Joomla/Sniffs/Deprecated

the parameter is: --runtime-set enable_deprecated_joomla_sniff 1

note that pending feedback this is POC only: does it the sniffing work. Next step is to fill the sniffs with deprecated functions: that is a lot of work, so want to make sure that it works firs :)

Anibal

unread,
Jan 5, 2018, 10:31:19 AM1/5/18
to Joomla! General Development
Hi,

It is working great! I'm going to use it in the next week.

PS. I've forced the setting with <config name="enable_deprecated_joomla_sniff" value="1"/> in the rule set.

Thank you,
Anibal

Ruud van Lent

unread,
Jan 14, 2018, 11:27:07 AM1/14/18
to Joomla! General Development
Just added the functionality to check the deprecated classes and functions against a specific Joomla version.
So you can now configure to only report the deprecated functions for the Joomla version you are developing for.

The Joomla version number is set as the 'enable' parameter either in the ruleset or as CL parameter

https://github.com/Ruud68/coding-standards/commit/f46e0af8d3a661e1afc7084031d26df5d4e162bd

Ruud van Lent

unread,
Jan 16, 2018, 10:03:08 AM1/16/18
to Joomla! General Development


On Thursday, December 28, 2017 at 4:31:29 PM UTC+1, rolandd wrote:

Anibal

unread,
Jan 17, 2018, 7:17:51 AM1/17/18
to Joomla! General Development
Hi,

I've tested the new ruletset, but I have been unable to enable it from the command line or adding the declaration in the ruleset.... or If it's enabled... then it's not detecting the sniffs.



Ruud van Lent

unread,
Jan 17, 2018, 7:37:43 AM1/17/18
to Joomla! General Development
Hi Anibal,
method of enabling is still the same, either via parameter or via rulset entry.
What did change was that perviously you would set thevalue for enabling to 1, that value now is the Joomla version to check against.
so setting:
--runtime-set enable_deprecated_joomla_sniff 4.0

will only display deprecated classes / functions that are deprecated starting from version 4.0

could you give that a try?

Anibal

unread,
Jan 17, 2018, 10:12:08 AM1/17/18
to Joomla! General Development

OK. Yes, it works with 4.0.

I've tested with 4.0.0. Mainly because the example has 3.8.3... so I thought that the param followed the 9.9.9.

Great work! Are you planning to submit it to the master repo soon?

A

Ruud van Lent

unread,
Jan 17, 2018, 11:22:01 AM1/17/18
to Joomla! General Development
Cool,
there was some interaction with the maintainer(s) of the joomla code style, but that 'dried up'. could do with some review of concept, code and what it reports.
maybe when somebody reads this :)

Niels Braczek

unread,
Jan 17, 2018, 11:52:08 AM1/17/18
to joomla-de...@googlegroups.com
Am 17.01.2018 um 17:22 schrieb Ruud van Lent:

> there was some interaction with the maintainer(s) of the joomla code style,
> but that 'dried up'. could do with some review of concept, code and what it
> reports.
> maybe when somebody reads this :)

I'd say, add some documentation to the manual section and send a Pull
Request. Finding deprecated calls during CI is a great achievement, JED
will love it ;)

Regards,
Niels

--
| New Stars on the Horizon: GreenCape · nibralab · laJoom |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------

Anibal

unread,
Jan 17, 2018, 12:23:38 PM1/17/18
to Joomla! General Development
Hi Niels,

Today, JED doesn't have a CI infrastructure. There is a process that runs the current JED Checker code, but it's poorly implemented and we manually check every extension (...).

In our plans for JED4, we have the crazy idea of implementing the JED Checker CI. A process to check the extension quality and validate certain rules on the uploaded ZIP files

A

Ruud van Lent

unread,
Jan 18, 2018, 8:01:50 AM1/18/18
to Joomla! General Development

Niels Braczek

unread,
Jan 18, 2018, 9:04:18 AM1/18/18
to joomla-de...@googlegroups.com
Am 18.01.2018 um 14:01 schrieb Ruud van Lent:

> here it starts (or ends :)) :
> https://github.com/joomla/coding-standards/pull/221

Thank you! I'm sure the RfC 19395 will make it. Actually, your
contribution has triggered its existence ;)

Ruud van Lent

unread,
Feb 27, 2018, 5:52:45 AM2/27/18
to Joomla! General Development
Good News :)

Just added Code Fixing for Name Spaced Classes,
so now it will not only report:

  9 | ERROR | [x] The use of class JFactory is deprecated in Joomla version 4.0 and removed in Joomla version 5.0; Use \Joomla\CMS\Factory instead.


But you are also able to automagically fix JFactory with \Joomla\CMS\Factory (in the above example).

read the readme.txt in the deprecated folder for instructions

rolandd

unread,
Apr 2, 2018, 8:14:25 AM4/2/18
to Joomla! General Development
Hello Ruud,

It has been a while but I am back on this subject. I was wondering if there is any progress on getting this into the main Joomla codesniffer repository. Do we need to send a Pull Request?

Regards,

Roland

rolandd

unread,
Apr 2, 2018, 8:17:11 AM4/2/18
to Joomla! General Development
Just to answer my own question, no there is no need for a Pull Request. We need this PR as mentioned earlier: https://github.com/joomla/joomla-cms/issues/19395

rolandd

unread,
Apr 3, 2018, 1:16:48 PM4/3/18
to Joomla! General Development
To follow up, there is now a dedicated repo for this so we can add the deprecated sniffs there as well:

https://github.com/joomla/cms-coding-standards
Reply all
Reply to author
Forward
0 new messages