- Bugs
- Reporting a Bug
- Fixing a Bug
- Features
- Security Vulnerabilities
- Coding Style
- PHPDoc
- Naming Conventions
- Variables
- Functions/Methods
- Constants
- Namespaces
- Classes
- Abstract Classes
- Interfaces
- Traits
Opulence strives to not create any unnecessary library dependencies. This even includes having dependencies on other Opulence libraries. If your change will introduce a new dependency to a library, create an issue and ask about it before implementing it. If your feature is a useful combination of multiple Opulence libraries, it's possible it'll be recommended to go into the Opulence\Framework
library.
class Book
{
/** @var string The title of the book */
private $title;
/**
* @param string $title The title of the book
*/
public function __construct(string $title)
{
$this->setTitle($title);
}
/**
* Gets the title of the book
*
* @return string The title of the book
*/
public function getTitle() : string
{
return $this->title;
}
/**
* Sets the title of the book
*
* @param string $title The title of the book
* @return $this For object chaining
*/
public function setTitle(string $title) : self
{
$this->title = $title;
return $this;
}
}
- Must be lower camel case, eg
$emailAddress
- Must NOT use Hungarian Notation
- Must be succinct
- Your method name should describe exactly what it does, nothing more, and nothing less
- If you are having trouble naming a method, that's probably a sign that it is doing too much and should be refactored
- Must be lower camel case, eg
compileList()
- Acronyms in function/method names ≤ 2 characters long, capitalize each character, eg
startIO()
- "Id" is an abbreviation (not an acronym) for "Identifier", so it should be capitalized
Id
- Acronyms in function/method names ≤ 2 characters long, capitalize each character, eg
- Must answer a question if returning a boolean variable, eg
hasAccess()
oruserIsValid()
- Always think about how your function/method will be read aloud in an
if
statement.if (userIsValid())
reads better thanif (isUserValid())
.
- Always think about how your function/method will be read aloud in an
- Must use
getXXX()
andsetXXX()
for functions/methods that get and set properties, respectively- Don't name a method that returns a username
username()
. Name itgetUsername()
so that its purpose is unambiguous.
- Don't name a method that returns a username
- Must be upper snake case, eg
TYPE_SUBSCRIBER
- Must be Pascal case, eg
Opulence\QueryBuilders
- For namespace acronyms ≤ 2 characters long, capitalize each character, eg
IO
- For namespace acronyms ≤ 2 characters long, capitalize each character, eg
- Must be succinct
- Your class name should describe exactly what it does, nothing more, and nothing less
- If you are having trouble naming a class, that's probably a sign that it is doing too much and should be refactored
- Must be Pascal case, eg
ListCompiler
- For class name acronyms ≤ 2 characters long, capitalize each character, eg
IO
- Class filenames should simply be the class name with
.php
appended, egListCompiler.php
- For class name acronyms ≤ 2 characters long, capitalize each character, eg
Class properties should appear before any methods. The following is the preferred ordering of class properties and methods:
- Constants
- Public static properties
- Public properties
- Protected static properties
- Protected properties
- Private static properties
- Private properties
- Magic methods
- Public static methods
- Public abstract methods
- Public methods
- Protected static methods
- Protected abstract methods
- Protected methods
- Private static methods
- Private methods
All abstract class names:Note: Methods of the same visibility should be ordered alphabetically.
- Must be Pascal case, eg
ConnectionPool
- Must NOT use
Abstract
,Base
, or any other word in the name that implies it is an abstract class
- Must be preceded by an
I
, egIUser
- Must be preceded by a
T
, egTListValidator