I eventually figured out that I could use a code sniffer in Sublime Text, load up a CodeIgniter rule set (not a Craft project, obviously), and see in real time where my formatting, spacing and naming conventions could be improved for consistency.

Is there an equivalent standard for Craft/Yii? I'd like to start forming good habits, and the Sublime Text part is a bonus but not required—I'm most interested in whatever standards there are to reference.

4 Answers 4


I would strongly suggest that you follow PSR-2 since that is what most of the craft source code adheres to and it is a pretty good standard for general PHP development. Just be aware that craft itself won't pass PSR-2 linting because there are places where it deviates from the standard, two of which are namespacing (craft has a global namespace) and indentation (tabs over spaces) but that is totally fine in my opinion.

Writing clean, readable, intuitive, and testable code should be the end goal of any developer and if that means you have to violate a standards rule here or there, go for it: )


We plan on adding official "Craft Plugin Code Guidelines" recommendations once the plugin store is out of the gate.

In the meantime, Selvin is correct. We aren't 100% PSR-2 compliant, but it's easy enough to look in the craft/app folder and see what our coding style is.

The Yii 1.0 coding style is, IMO, quite awful, so I wouldn't recommend following that. Yii 2.0, on the other hand is PSR-2 compliant and we'll re-address Craft's guidelines when we're ready to integration Yii 2.0 into Craft.

Update: We now have official "P&T Coding Standards" which we recommend you to use, when writing Craft plugins.

  • Cool, thanks Brad. I've been generally trying to mimic what I see in the land of /app, it's just nice to have the extra reinforcement from an automated tool like phpcs.
    – Matt Stein
    Jun 20, 2014 at 22:05

I don't know about any Craft specific-guide, but there are is a guide and code-sniffer for Yii 1:

  • 3
    Thanks @VictorIn. You just reminded me that Ben Parizek's Craft-Twig Sublime bundle exists, too.
    – Matt Stein
    Jun 20, 2014 at 17:41
  • 2
    For what it's worth, Yii2 is adopting PSR-2 coding standards (for the most part). Yii2 is a ways down the road as far as Craft implementation is concerned, but it's worth keeping in the back of your mind. github.com/yiisoft/yii2-coding-standards
    – Wes Rice
    Jun 20, 2014 at 18:20

Another option: Use http://editorconfig.org/

If you're using Sublime Text, you can use https://github.com/sindresorhus/editorconfig-sublime to enforce those rules.

  • Cool, I had no idea about editorconfig. Thanks @Tim!
    – Matt Stein
    Jun 20, 2014 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.