Use PascalCase for class names
Class names must be written in PascalCase.
Example
Bad
class mySUPERclass { ... }
Good
class MySuperClass { ... }
Reference: PEAR.NamingConventions.ValidClassName
Do not use final statements inside final classes
Final classes cannot be extended, so it doesn't make sense to add the final keyword to class members.
Example
Bad
final class MyClass {
final public function MyFunction() {
}
}
Good (remove the final keyword from class members)
final class MyClass {
public function MyFunction() {
}
}
Reference: Generic.CodeAnalysis.UnnecessaryFinalModifier
Do not override methods to call their parent
It doesn't make sense to override a method only to call their parent. When overriding methods, make sure to add some functionality to it.
Example
Bad
class MyClass extends BaseClass {
public function BaseFunction() {
parent::BaseFunction();
}
}
Good (don't override the function)
class MyClass extends BaseClass {
}
Reference: Generic.CodeAnalysis.UselessOverridingMethod
abstract and final declarations MUST precede the visibility declaration
When declaring abstract
and final
functions, the visibility (scope) must follow after abstract
or final
.
Example
Bad
class MyClass extends BaseClass {
public abstract function AbstractFunction() { }
public final function FinalFunction() { }
}
Good (abstract
and final
before public
)
class MyClass extends BaseClass {
abstract public function AbstractFunction() { }
final public function FinalFunction() { }
}
Reference: PSR2.Methods.MethodDeclaration
static declaration MUST come after the visibility declaration
The static
keyword must come after the visibility (scope) parameter.
Example
Bad
class MyClass extends BaseClass {
static public function StaticFunction() { }
}
Good (static
after public
)
class MyClass extends BaseClass {
public static function StaticFunction() { }
}
Reference: PSR2.Methods.MethodDeclaration
RSS-Bridge · Reconnecting the Web ·