-
-
Save grEvenX/1816998 to your computer and use it in GitHub Desktop.
Oyatel PHP Code Style Guideline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use PHPDoc notation when creating documentation for classes and functions | |
* Code indentation is TAB, do not use spaces! | |
* | |
* @param ObjectClassName $object This object does something | |
* @param int $options This integer can count by one | |
* @return echos json This function returns something | |
*/ | |
// Namespaces must match folder structure | |
namespace hpbx\utils; | |
// Bootstrap Oyatel classloader and core classes if your file is a new endpoint (not included by another endpoint) | |
require_once('PhoniaxCore.class.php'); | |
PhoniaxCore::init(); | |
// Class names are camel case | |
class ClassName extends BaseController { | |
// All variables names are camel case | |
private $variableName = 'All Variable Names Are Camel Case.'; | |
// Function names are camel case | |
public static function doSomeThing(MyObj $param, $otherParam = '') { | |
// Always declare variables used (don't give me E_NOTICEs in here!) | |
$someArray = array(); | |
$foo = false; | |
// All comments are singe line // style and should begin with a space followed by a capital letter | |
// TODO: Should being with a capital letter | |
// START HACK: TITLE SHOULD BE IN UPPER CASE | |
// Followed by a description of the reason behind the hack following normal comment style | |
$this->variableName = 'Something really strange'; | |
// END HACK | |
// Array acessors use single quotes | |
$someArray['foo_bar']; | |
// Strings use single quotes | |
$someString = 'Strings use single quotes'; | |
// Strings concatenation | |
// Put spaces between the values | |
$someString = 'Hello ' . $text . ' World'; // Correct | |
$someString = 'Hello '.$text.' World'; // Incorrect | |
$someString = "Hello $text World"; // Incorrect | |
// or use sprintf | |
$someString = sprintf("Hello %s World", $text); | |
// Simple If | |
if ($oneThing > $anotherThing) { | |
// Do things | |
} | |
// Complex If | |
if ( | |
($twoThings > $threeThings) && | |
($oneThing < $fiveThings) | |
) { | |
// Do more things | |
} | |
// Switch style | |
switch ($foobar) { | |
case 'One': | |
// One | |
break; | |
case 'two': | |
// Two | |
break; | |
default: | |
// The end | |
} | |
// For style | |
for ($x = 0; $x < 10; $x++) { | |
$y += $x; | |
} | |
// For each style | |
foreach ($collection as $item) { | |
/* @var $item ClassNameOfItemIfObject */ | |
// using the above comment-block hints the Eclipse PDT about how to do auto-complete | |
// ->name should here then be autocompleted | |
echo $item->name . ' is really nifty!'; | |
} | |
// Don't build code like this: | |
if ($foo) { | |
/* .... 50 lines of code ... */ | |
} else { | |
$result = 0; | |
return; | |
} | |
// Instead, try to minimize the number of lines of code that need to be | |
// indented, by only indenting the shortest case of the 'if' | |
// statement, like so: | |
if (!$foo) { | |
$result = 0; | |
return; | |
} | |
/* .... 50 lines of code ... */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment