ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CodeIgniter for PHP_CodeSniffer (coding convention coding standard coding guidelines)

February 03, 2011 8:35am

Subscribe [11]
  • #1 / Feb 03, 2011 8:35am

    thomas.ernest

    19 posts

    Hey,

    I would like to share my implementation of CodeIgniter coding guidelines for PHP_CodeSniffer with you, member of the CodeIgniter’s community.
    I put my work on GitHub [1] few days ago.

    CodeIgniter’s style guide [2] is not fully implemented yet, but it may save some time to start from this partial implementation.

    Feel free to share your ideas and criticisms 😊

    Hope that helps.
    Thomas.

    [1] https://github.com/thomas-ernest/CodeIgniter-for-PHP_CodeSniffer
    [2] http://ellislab.com/codeigniter/user-guide/general/styleguide.html

  • #2 / Feb 03, 2011 9:38am

    Eric Barnes's avatar

    Eric Barnes

    487 posts

    I haven’t looked at implementing this yet but this is awesome. I was searching for just this a few weeks back and thought I was going to have to modify Kohanas 😊

    Thanks for sharing!

  • #3 / Feb 25, 2011 12:53pm

    shatter

    1 posts

    Thank you for your work, that’s what I was looking for !

  • #4 / Feb 26, 2011 9:05am

    thomas.ernest

    19 posts

    You’re welcome.

    I released the code a few days before CodeIgniter 2.0.0 was released. However, CodeIgniter 2.0.0 came with a new Guide Style. I haven’t had time to improve code to erase the few slightly differences brought with the new coding convention. The current implementation is based on CodeIgniter 1.7.3 Guide Style. I hope having time to work on it soon and make it compatible with CodeIgniter 2.0.0 coding standard.

    Cheers,
    Thomas.

  • #5 / Mar 16, 2011 7:38am

    elwis

    1 posts

    Hi there,
    I’m quite new to both php/eclipse-pdt and codeigniter. We just started a project with these tools though, and since our policy recommends using tools like this, I would love to get a guide for how to use it?
    Is codesniffer a plugin of its own or part of eclipse-pdt?

    Regards
    Stefan

  • #6 / Mar 16, 2011 11:43am

    thomas.ernest

    19 posts

    Hello Stefan,

    PHP_CodeSniffer is available as a pear package http://pear.php.net/package/PHP_CodeSniffer/redirected .

    I’m not used developing with Eclipse-PDT. However, I know that there is a Eclipse plug-in for PHP_CodeSniffer : http://www.phpsrc.org/projects/pti-php-codesniffer/wiki/ . I don’t know, if this plugin is integrated in Eclipse-PDT.

    To setup the CI coding standard in PHP_CodeSniffer, you will have to duplicate the file in the right place along PHP_CodeSniffer sources. Something like <my path to PHP_CS>/Standards/

    If you’re new to (most of) all these things, the better would be for you to get in touch with somebody or to be prepared to spend a loooot of time (to find documentation, tutorials or how-tos). Nonetheless, if you find something interesting, please write it down here, on this thread.

    Good luck.

  • #7 / Sep 04, 2011 12:12pm

    victorlenus

    3 posts

    Hi thomas.ernest,
    Your conribution is awesome.
    Did you make any changes to make your stuff compatible with latest codeigniter coding standards. Can I offer any help in this?


    Regards,

  • #8 / Sep 06, 2011 4:42am

    thomas.ernest

    19 posts

    Hi victorienus,

    CI Coding standards is quiet stable. I had a look to the new style guide and it doesn’t seem to have changed at a first glance.
    Though the code is dedicated to CI 1.7.3, you shouldn’t have lot of trouble in checking code based on CI 2.0.3. I mean, the errors existing for CI 1.7.3 will remain for CI 2.0.3 😉

    If you wanna help, don’t bother. Do whatever you want to do. If you don’t know how to start, there are a few parts of the coding convention that aren’t done:
    A/ The Allman style indenting is not fully supported [allman]. All I did is to reuse sniffs from phpcs built-in standards in the ruleset.xml.
    B/ Likewise, we can use existing sniffs from built-in standards to manage bracket spacing [bracket-spacing].
    C/ Support for prefix in class and file names [prefix-classes-files]. I check file and class names, but only cases, underscores and stuff like that. Based on /Sniffs/NamingConventions/ValidFileNameSniff.php and /Sniffs/NamingConventions/ValidClassNameSniff.php, add a common abstract class (be careful with abstract classes, because phpcs doesn’t support php “abstract class”, but there is a workaround) to manage a company or user prefix (that could manage prefix ‘MY’ for instance).
    D/ Finally, a few other ideas that look harder to implement [php-errors] [strings-sql-queries] [strings-localized-text].

    [allman] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#code_indenting
    [bracket-spacing] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#bracket_spacing
    [prefix-classes-files] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#class_and_file_names_using_common_words
    [php-errors] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#php_errors
    [strings-sql-queries] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#sql_queries
    [strings-localized-text] http://ellislab.com/codeigniter/user-guide/general/styleguide.html#localized_text

  • #9 / Sep 06, 2011 4:52am

    victorlenus

    3 posts

    Thanks, let me try, you would have noticed that I have already created a fork of your project. If I make any changes to sniffs, I will commit and send PULL requests to you.

  • #10 / Sep 06, 2011 4:59am

    thomas.ernest

    19 posts

    Oupsy. I haven’t noticed, sorry 😊
    I know that I’ve a pull request pending. I’ll try to manage that in this week. I just came back from holiday yesterday 😊

    Thank you for helping.

  • #11 / Dec 15, 2011 8:45am

    vertmonkee

    22 posts

    Thanks for making the sniff.

    Can anyone post a sample file that passes all tests?

    I tried on the default welcome controller but that fails.

    Thanks

  • #12 / Jun 02, 2012 1:52am

    Lars Germ's avatar

    Lars Germ

    3 posts

    Is the codesniffer standard for CodeIgniter still in development? I send you a pull request on github, because you forgot to define a default target in the build.xml. I added the line in the xml.

    And to change the “phpcs.dir” you can pass it as argument in the CL.
    just type:

    ant -Dphpcs.dir="path/to/Codesniffer/"
  • #13 / Nov 23, 2012 10:30am

    eriktorsner

    1 posts

    I’ve made some changes to the sniffs provided by Thomas. I got a bunch of errors on most CI files that I really wanted to get rid of:

    1. PEAR’s check for a file doc comment didn’t allow any non white space between the PHP opening tag and the file doc comment. I’ve changed that so that code on the same line as the PHP opening tag is ignored. This means that the “if ( ! defined(‘BASEPATH’)) ...” statement can sit right after the PHP opening tag without causing a warning.

    2. Thomas’ rules would forbid using multi line comments (/* ... */) anywhere unless they are doc block style comments. While this is correct according to the CI style guide, the guide also suggests that the end of file comments should use the multi line style comments for the end of file comments. My changes allows comments beginning with “/* Location:” or “/* End of file ” specifically.

    I’ve forked Thomas project on Github to this URL https://github.com/eriktorsner/CodeIgniter-for-PHP_CodeSniffer-ETO

    Hopefully, I can convince Thomas to include my changes in his repo, but until then, I need to have it on github for my own purposes (build automaton). Feel free to use it and/or fork it.

    /Erik

  • #14 / Oct 29, 2014 10:45pm

    Lk

    1 posts

    Would be nicer if you use phing instead of ant. Especially to avoid installing the jdk.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases