Jména

Sekce naming rozhoduje o velikosti písmen ve jménech, která píšete vy: tříd, metod, funkcí, konstant, případů výčtu, vlastností a proměnných, a o tom, jestli jméno rozhraní nebo abstraktní třídy nese slovo svého druhu.

Každý druh jména má vlastní klíč a hodnotou je zápis: PascalCase, camelCase, UPPER_CASE nebo snake_case. PSR-1 předepisuje jen třídy, metody a konstanty tříd, a tak standardy psr12 a perCs nastavují jen ty; Nette Coding Standard jmenuje všechno a konstanty píše v PascalCase.

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

Porušení se jen hlásí, nikdy neopraví: jméno metody nebo vlastnosti by se muselo změnit i všude, kde se používá, a to z jednoho souboru vidět není. Jméno, které má zůstat, jak je, třeba metoda stream wrapperu, kterou PHP volá jménem stream_open, se vyjme vzorem v naming.ignore.

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

naming.classKindInName

The word of its kind in the name of an interface, a trait or an abstract class, FooInterface, FooTrait, AbstractFoo, and Error at the end of the name of a plain class, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs keep, psr12 keep, nette forbidden, symfony keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming, SlevomatCodingStandard.Classes.SuperfluousErrorNaming, SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming, SlevomatCodingStandard.Classes.SuperfluousTraitNaming

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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs PascalCase, psr12 PascalCase, nette PascalCase, symfony PascalCase · pokrývá 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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs camelCase, psr12 camelCase, nette camelCase, symfony camelCase · pokrývá 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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep · pokrývá 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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs UPPER_CASE, psr12 UPPER_CASE, nette PascalCase, symfony UPPER_CASE · pokrývá 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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs PascalCase, psr12 keep, nette PascalCase, symfony PascalCase

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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep · pokrývá 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
  • keep: nic se nevynucuje, kód zůstane, jak je

Požadavek · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep · pokrývá Squiz.NamingConventions.ValidVariableName

naming.ignore

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

  • seznam regulárních výrazů

Parametr, výchozí [] · standardy: perCs [], psr12 [], nette [], symfony []

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