Velikost písmen

Sekce casing rozhoduje o velikosti písmen tam, kde ji PHP nerozlišuje: v klíčových slovech, v true, false a null, v magických konstantách jako __DIR__, ve vestavěných typech a ve jménech tříd, funkcí a metod.

PHP velikost písmen v klíčových slovech a jménech funkcí a tříd nerozlišuje, takže NULL, StrLen() i new datetime fungují. Čtou se ale hůř a každý projekt je píše trochu jinak. Klíče sekce sjednotí zápis na ten, který má deklarace: strlen, DateTime, stdClass. Bez analýzy typů DressCode zná jen deklarace PHP a rozšíření, která s ním přicházejí, a jména vašeho projektu a balíčků si nechají zápis, jaký mají. S typeAnalysis: phpstan se ptá PHPStanu, a tak srovná i new orderitem na new OrderItem podle deklarace v projektu a volání $order->gettotal() na $order->getTotal() a metodu, která přepisuje metodu předka, na zápis předka; metody bez typů nejdou, protože jen typy řeknou, kterou metodu volání volá.

casing:
	keyword: lowercase
	trueFalseNull: lowercase
	class: declared
	function: declared
$items = Array();  // The keyword `Array` must be written `array`.
if ($value === NULL) {  // The literal `NULL` must be written `null`.
	$date = new datetime();  // The class name `datetime` must be written `DateTime`.
	$length = StrLen($name);  // The function `StrLen()` must be written `strlen()`.
}
$items = array();
if ($value === null) {
	$date = new DateTime();
	$length = strlen($name);
}

casing.method

The case of the name of a method called, as its declaration writes it, and of a method overriding another, as the overridden one writes it.

  • declared: $order->getTotal(), never $order->gettotal()
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · jen s typy · standardy: perCs keep, psr12 keep, nette declared, symfony keep

casing.keyword

The case of keywords, self and parent included.

  • lowercase: if, function, self, parent
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs lowercase, psr12 lowercase, nette lowercase, symfony lowercase · pokrývá lowercase_keywords, lowercase_static_reference, Generic.PHP.LowerCaseKeyword, Generic.PHP.LowerCaseType, PSR2.ControlStructures.SwitchDeclaration, Squiz.ControlStructures.ForEachLoopDeclaration, Squiz.ControlStructures.LowercaseDeclaration, Squiz.Functions.LowercaseFunctionKeywords

casing.trueFalseNull

The case of true, false and null, a leading backslash staying.

  • lowercase: true, false, null
  • uppercase: TRUE, FALSE, NULL
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs lowercase, psr12 lowercase, nette lowercase, symfony lowercase · pokrývá constant_case, Generic.PHP.LowerCaseConstant

casing.magicConstant

The case of the magic constants such as __DIR__.

  • uppercase: __DIR__, __CLASS__
  • lowercase: __dir__, __class__
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette uppercase, symfony uppercase · pokrývá magic_constant_casing

casing.class

The case of a class, an interface, a trait or an enum as its declaration writes it, of one PHP declares only where the configuration sets no typeAnalysis.

  • declared: stdClass, DateTime, never datetime
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette declared, symfony declared · pokrývá class_reference_name_casing

casing.function

The case of a function as its declaration writes it, of one PHP declares only where the configuration sets no typeAnalysis.

  • declared: strlen, never StrLen
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette declared, symfony declared · pokrývá native_function_casing, Squiz.PHP.LowercasePHPFunctions

casing.type

The case of the built-in types of a declaration; array, callable, static, self and parent are keywords.

  • lowercase: int, string, void
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs lowercase, psr12 lowercase, nette lowercase, symfony lowercase · pokrývá native_type_declaration_casing, Generic.PHP.LowerCaseType