Naming

The naming section decides on the letter case of the names you write (classes, methods, functions, constants, enum cases, properties and variables), and on whether the name of an interface or an abstract class includes the word for its kind.

Each kind of name has its own key, and the value is the notation: PascalCase, camelCase, UPPER_CASE or snake_case. PSR-1 prescribes only classes, methods and class constants, so the psr12 and perCs standards set only those; Nette Coding Standard sets all of them and writes constants in PascalCase.

naming:
	class: PascalCase
	method: camelCase
	constant: UPPER_CASE
	variable: camelCase

A violation is only reported, never fixed: the name of a method or a property would also have to change everywhere it is used, and that cannot be seen from a single file. A name that must stay as it is, such as a method of a stream wrapper that PHP calls by the name stream_open, is excluded by a pattern in naming.except.

class Order
{
	public function get_total(): int  // The method `get_total` must be written in camelCase.
	{
		return 0;
	}
}

naming.abstractClassAffix

The word Abstract in front of the name of an abstract class, AbstractFoo, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · covers SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming

naming.interfaceAffix

The word Interface at the end of the name of an interface, FooInterface, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · covers SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming

naming.traitAffix

The word Trait at the end of the name of a trait, FooTrait, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · covers SlevomatCodingStandard.Classes.SuperfluousTraitNaming

naming.exceptionAffix

The word Exception at the end of the name of an exception, FooException, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette keep, symfony keep, laravel keep · covers SlevomatCodingStandard.Classes.SuperfluousExceptionNaming

naming.errorAffix

The word Error at the end of the name of a plain class, FooError, which is reported and never renamed.

  • forbidden: never there
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · covers SlevomatCodingStandard.Classes.SuperfluousErrorNaming

naming.class

The case of the name of a class, an interface, a trait and an enum, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs PascalCase, psr12 PascalCase, nette PascalCase, symfony PascalCase, laravel keep · covers Squiz.Classes.ValidClassName

naming.method

The case of the name of a method, those beginning with __ being PHP's, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs camelCase, psr12 camelCase, nette camelCase, symfony camelCase, laravel keep · covers Generic.NamingConventions.CamelCapsFunctionName, PSR1.Methods.CamelCapsMethodName, Squiz.NamingConventions.ValidFunctionName

naming.function

The case of the name of a function, those beginning with __ being PHP's, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · covers Generic.NamingConventions.CamelCapsFunctionName, Squiz.NamingConventions.ValidFunctionName

naming.constant

The case of the name of a class constant and a const outside a class, a constant of an enum passing in this case or in that of enumCase, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs UPPER_CASE, psr12 UPPER_CASE, nette PascalCase, symfony UPPER_CASE, laravel keep · covers Generic.NamingConventions.UpperCaseConstantName

naming.enumCase

The case of the name of a case of an enum, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs PascalCase, psr12 keep, nette PascalCase, symfony PascalCase, laravel keep

naming.property

The case of the name of a property, a promoted constructor parameter included, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · covers Squiz.NamingConventions.ValidVariableName

naming.variable

The case of the name of a variable and a parameter, $this, the superglobals and a placeholder such as $_ excepted, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nothing is enforced, the code stays as it is

Default keep · standards: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · covers Squiz.NamingConventions.ValidVariableName

naming.except

The patterns of names never reported, whatever their kind, as the methods of a stream wrapper or a replacement for a native function.

  • a list of regular expressions

Default [] · standards: perCs [], psr12 [], nette [], symfony [], laravel []

naming:
	method: camelCase
	except:
		- '~^stream_~'
class MemoryStream
{
	public function stream_open(string $path, string $mode): bool
	{
		return true;
	}
}