XH 1.6: Coding Standards--Offending Identifiers

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

XH 1.6: Coding Standards--Offending Identifiers

Post by cmb » Wed Jun 05, 2013 9:07 pm

Hello Community,

we had decided to adopt the PEAR Codings Standards(PEARCS) for CMSimple_XH quite a while ago. Recently I found PHP_CodeSniffer (PHPCS), a tool which checks if code complies to these standards. I thought it would be a good idea to integrate PHPCS to our QA, so I integrated a rule "sniff" (might get a better name) to the Makefile, and checked and fixed all core PHP files[1] accordingly (r558-560). Besides DocBlock and formatting issues, which were easy (albeit time consuming) to solve, there are issues regarding the names of functions and methods. The PEARCS don't allow underscores in method names, and they regard underscores in function names as package name separators (the latter is particularly useful, as these package names can be changed to namespaces in the future, which are already available since PHP 5.3 which was released nearly 4 years ago).

Some of the offending identifiers may be simply renamed, as they are not used outside the core (e.g. admin_menu() -> XH_adminMenu()). But some of these functions/methods are already used by extensions (e.g. evaluate_scripting() and PL_Page_Data_Router::add_interest()), so we can't simply rename them. However, I would rather appreciate to deprecate them for XH 1.6 and remove them in the future. That's somewhat viable for the functions, as these can be defined as "aliases" for the core:

Code: Select all

function evaluate_scripting() {
    return XH_evaluateScripting();
}
And conditionally by plugins:

Code: Select all

if (!function_exists('XH_evaluateScripting')) {
    function XH_evaluateScripting() {
        return evaluate_scripting();
    }
}
Unfortunately that is not possible for the methods of PL_Page_Data_Router (which BTW may better be renamed to XH_PageDataRouter) -- at least not for PHP 4[2]. PHP 5 offers the "magic" __call() method, which can be defined to map any unknown method name to an equivalent counterpart.

And we have to consider another special case: the editor API. This currently uses the functions include_editor(), editor_replace() and init_editor() (resp. their counterparts for each editor, e.g. include_tinymce(), tinymce_replace() and init_tinymce()). We may consider renaming include_editor() to XH_includeEditor() and include_tinymce() to Tinymce_includeEditor() (and the other functions accordingly).

As this would have quite some impact on plugin developers and CMSimple 4, I don't want to propose any particular change--let alone put that on the roadmap for voting. Instead I'm hoping on the opinions of the affected parties--perhaps we can find a good solution.

[1] I have not yet given up the hope, that there will be found active maintainers for the standard plugins, which currently have none (i.e. filebrowser, meta_tags and page_params).

Christoph

PS: [2] IMO we should stick with PHP 4 compatibility for CMSimple_XH 1.6, but I strongly recommend to drop PHP 4 support for the following version (be it 1.7 or 2.0). PHP 4 reached its EOL more than 5 (!) years ago, and its definitely not up to support state-of-the-art programming.
Last edited by cmb on Wed Jun 05, 2013 9:27 pm, edited 1 time in total.
Reason: added PS
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.6: Coding Standards--Offending Identifiers

Post by cmb » Mon Jul 08, 2013 9:33 pm

Hello Community,

I have renamed all "private" CS offending idenifiers (r707). To not forget about this thread, I've put this issue on the 1.7 roadmap.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: XH 1.6: Coding Standards--Offending Identifiers

Post by cmb » Wed Mar 25, 2015 4:06 pm

In the meantime I've found a way to suppress PHP_CS warnings for CS violations, and this is already used since r1405. Furthermore it appears to me that some of the respective APIs should be changed in the long run, so renaming them now would cause unnecessary work. Therefore I withdraw the suggestion to rename the offending identifiers.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply