Skip to content

Instantly share code, notes, and snippets.

@adityamenon
Forked from kapv89/coding standards.md
Created March 30, 2014 19:05
Show Gist options
  • Save adityamenon/9877937 to your computer and use it in GitHub Desktop.
Save adityamenon/9877937 to your computer and use it in GitHub Desktop.

We are gonna be using php5.5 , so upgrade your systems to that.

  1. http://laravel.com/docs/contributing#coding-guidelines , we follow these, along with PSR-0 and PSR-1.

  2. use Foo (aliasing) etc statements should start from the 3rd line. Each class that needs to be used in a namespace has to be aliased in a separate line.

  3. Aliasing is important. You shouldn't be using more than two Namespace Separators (\) in the code that you right in your classes. Try to restrict the count of those namespace separators to one.

  4. No accessing global namespace (ie, \Foo is not allowed, you need to alias the class Foo via use Foo). The only exception for this is php spl exception classes.

  5. Tabs of size 4 are to be used for indentation, spaces can be used to align things that span multiple lines properly.

  6. Do not make global helper functions.

  7. Do not use && and || for boolean operations, use and and or.

  8. Maintain type coherence of methods. Always look at returned values as filled-up or empty. So if a method returns an object, it should always return an object or a null. If it returns an array, boolean, string or number, it should always return an array, boolean, string, or number correspondingly (no null allowed). If you wan't to handle edge cases, or break flow of the method, use exceptions. But do not break type coherence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment