Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • D digitec-wiki
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Digitec
  • digitec-wiki
  • Wiki
  • php coding standards

php coding standards · Changes

Page history
rcabral created page: dependency-management authored Mar 23, 2014 by Rene Cabral's avatar Rene Cabral
Hide whitespace changes
Inline Side-by-side
php-coding-standards.markdown
View page @ 0acdd9b7
...@@ -245,7 +245,7 @@ interpreted as described in [RFC 2119]. ...@@ -245,7 +245,7 @@ interpreted as described in [RFC 2119].
- Files MUST use only `<?php` ~~and `<?=`~~ tags. - Files MUST use only `<?php` ~~and `<?=`~~ tags.
> Digitec code will only use the `<?php` tag. > Digitec code MUST use only the `<?php` tags.
- Files MUST use only UTF-8 without BOM for PHP code. - Files MUST use only UTF-8 without BOM for PHP code.
...@@ -270,6 +270,8 @@ interpreted as described in [RFC 2119]. ...@@ -270,6 +270,8 @@ interpreted as described in [RFC 2119].
PHP code MUST use the long `<?php ?>` tags ~~or the short-echo `<?= ?>` tags~~ ; it PHP code MUST use the long `<?php ?>` tags ~~or the short-echo `<?= ?>` tags~~ ; it
MUST NOT use the other tag variations. MUST NOT use the other tag variations.
> Digitec code MUST use only the `<?php ?>` tags.
### 2.2. Character Encoding ### 2.2. Character Encoding
PHP code MUST use only UTF-8 without BOM. PHP code MUST use only UTF-8 without BOM.
...@@ -304,8 +306,7 @@ include "file.php"; ...@@ -304,8 +306,7 @@ include "file.php";
echo "<html>\n"; echo "<html>\n";
// declaration // declaration
function foo() function foo() {
{
// function body // function body
} }
``` ```
...@@ -316,8 +317,7 @@ effects; i.e., an example of what to emulate: ...@@ -316,8 +317,7 @@ effects; i.e., an example of what to emulate:
```php ```php
<?php <?php
// declaration // declaration
function foo() function foo() {
{
// function body // function body
} }
...@@ -350,8 +350,7 @@ For example: ...@@ -350,8 +350,7 @@ For example:
// PHP 5.3 and later: // PHP 5.3 and later:
namespace Vendor\Model; namespace Vendor\Model;
class Foo class Foo {
{
} }
``` ```
...@@ -361,8 +360,7 @@ of `Vendor_` prefixes on class names. ...@@ -361,8 +360,7 @@ of `Vendor_` prefixes on class names.
```php ```php
<?php <?php
// PHP 5.2.x and earlier: // PHP 5.2.x and earlier:
class Vendor_Model_Foo class Vendor_Model_Foo {
{
} }
``` ```
...@@ -380,8 +378,7 @@ For example: ...@@ -380,8 +378,7 @@ For example:
<?php <?php
namespace Vendor\Model; namespace Vendor\Model;
class Foo class Foo {
{
const VERSION = '1.0'; const VERSION = '1.0';
const DATE_APPROVED = '2012-06-01'; const DATE_APPROVED = '2012-06-01';
} }
...@@ -389,25 +386,23 @@ class Foo ...@@ -389,25 +386,23 @@ class Foo
### 4.2. Properties ### 4.2. Properties
This guide intentionally avoids any recommendation regarding the use of ~~This guide intentionally avoids any recommendation regarding the use of
`$StudlyCaps`, `$camelCase`, or `$under_score` property names. `$StudlyCaps`, `$camelCase`, or `$under_score` property names.~~
Whatever naming convention is used SHOULD be applied consistently within a ~~Whatever naming convention is used SHOULD be applied consistently within a
reasonable scope. That scope may be vendor-level, package-level, class-level, reasonable scope. That scope may be vendor-level, package-level, class-level,
or method-level. or method-level.~~
> Digitec code MUST follow the [Symfony Naming Conventions](php-coding-standards#naming-conventions).
### 4.3. Methods ### 4.3. Methods
Method names MUST be declared in `camelCase()`. Method names MUST be declared in `camelCase()`.
--- ---
[PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
...@@ -483,10 +478,8 @@ use FooInterface; ...@@ -483,10 +478,8 @@ use FooInterface;
use BarClass as Bar; use BarClass as Bar;
use OtherVendor\OtherPackage\BazClass; use OtherVendor\OtherPackage\BazClass;
class Foo extends Bar implements FooInterface class Foo extends Bar implements FooInterface {
{ public function sampleFunction($a, $b = null) {
public function sampleFunction($a, $b = null)
{
if ($a === $b) { if ($a === $b) {
bar(); bar();
} elseif ($a > $b) { } elseif ($a > $b) {
...@@ -496,8 +489,7 @@ class Foo extends Bar implements FooInterface ...@@ -496,8 +489,7 @@ class Foo extends Bar implements FooInterface
} }
} }
final public static function bar() final public static function bar() {
{
// method body // method body
} }
} }
...@@ -591,9 +583,11 @@ The term "class" refers to all classes, interfaces, and traits. ...@@ -591,9 +583,11 @@ The term "class" refers to all classes, interfaces, and traits.
The `extends` and `implements` keywords MUST be declared on the same line as The `extends` and `implements` keywords MUST be declared on the same line as
the class name. the class name.
The opening brace for the class MUST go on its own line; the closing brace The opening brace for the class MUST go on ~~its own~~ __the same__ line; the closing brace
for the class MUST go on the next line after the body. for the class MUST go on the next line after the body.
> In Digitec code, the opening brace for classes MUST go on the same line.
```php ```php
<?php <?php
namespace Vendor\Package; namespace Vendor\Package;
...@@ -602,8 +596,7 @@ use FooClass; ...@@ -602,8 +596,7 @@ use FooClass;
use BarClass as Bar; use BarClass as Bar;
use OtherVendor\OtherPackage\BazClass; use OtherVendor\OtherPackage\BazClass;
class ClassName extends ParentClass implements \ArrayAccess, \Countable class ClassName extends ParentClass implements \ArrayAccess, \Countable {
{
// constants, properties, methods // constants, properties, methods
} }
``` ```
...@@ -623,8 +616,7 @@ use OtherVendor\OtherPackage\BazClass; ...@@ -623,8 +616,7 @@ use OtherVendor\OtherPackage\BazClass;
class ClassName extends ParentClass implements class ClassName extends ParentClass implements
\ArrayAccess, \ArrayAccess,
\Countable, \Countable,
\Serializable \Serializable {
{
// constants, properties, methods // constants, properties, methods
} }
``` ```
...@@ -646,8 +638,7 @@ A property declaration looks like the following. ...@@ -646,8 +638,7 @@ A property declaration looks like the following.
<?php <?php
namespace Vendor\Package; namespace Vendor\Package;
class ClassName class ClassName {
{
public $foo = null; public $foo = null;
} }
``` ```
...@@ -660,10 +651,12 @@ Method names SHOULD NOT be prefixed with a single underscore to indicate ...@@ -660,10 +651,12 @@ Method names SHOULD NOT be prefixed with a single underscore to indicate
protected or private visibility. protected or private visibility.
Method names MUST NOT be declared with a space after the method name. The Method names MUST NOT be declared with a space after the method name. The
opening brace MUST go on its own line, and the closing brace MUST go on the opening brace MUST go on ~~its own~~ __the same line__, and the closing brace MUST go on the
next line following the body. There MUST NOT be a space after the opening next line following the body. There MUST NOT be a space after the opening
parenthesis, and there MUST NOT be a space before the closing parenthesis. parenthesis, and there MUST NOT be a space before the closing parenthesis.
> In Digitec code, the opening brace for methods MUST go on the same line.
A method declaration looks like the following. Note the placement of A method declaration looks like the following. Note the placement of
parentheses, commas, spaces, and braces: parentheses, commas, spaces, and braces:
...@@ -671,10 +664,8 @@ parentheses, commas, spaces, and braces: ...@@ -671,10 +664,8 @@ parentheses, commas, spaces, and braces:
<?php <?php
namespace Vendor\Package; namespace Vendor\Package;
class ClassName class ClassName {
{ public function fooBarBaz($arg1, &$arg2, $arg3 = []) {
public function fooBarBaz($arg1, &$arg2, $arg3 = [])
{
// method body // method body
} }
} }
...@@ -692,10 +683,8 @@ list. ...@@ -692,10 +683,8 @@ list.
<?php <?php
namespace Vendor\Package; namespace Vendor\Package;
class ClassName class ClassName {
{ public function foo($arg1, &$arg2, $arg3 = []) {
public function foo($arg1, &$arg2, $arg3 = [])
{
// method body // method body
} }
} }
...@@ -718,7 +707,7 @@ class ClassName ...@@ -718,7 +707,7 @@ class ClassName
public function aVeryLongMethodName( public function aVeryLongMethodName(
ClassTypeHint $arg1, ClassTypeHint $arg1,
&$arg2, &$arg2,
array $arg3 = [] array $arg3 = []
) { ) {
// method body // method body
} }
...@@ -737,14 +726,12 @@ declaration. ...@@ -737,14 +726,12 @@ declaration.
<?php <?php
namespace Vendor\Package; namespace Vendor\Package;
abstract class ClassName abstract class ClassName {
{
protected static $foo; protected static $foo;
abstract protected function zim(); abstract protected function zim();
final public static function bar() final public static function bar() {
{
// method body // method body
} }
} }
......
Clone repository
  • alpha beta testing
  • browser testing
  • camtasia licenses
  • code delivery processes
  • coding practices
  • css and sass coding standards
  • database schema standards
  • dependency management
  • development environments
  • digitec agile process
  • digitec gitlab styles
  • digitec software promises
  • digitec spec process
  • gitlab administration
  • gitlab issues tags
View All Pages