Úklid
Sekce cleanup rozhoduje o kódu, který jde napsat jednodušeji a se stejným významem: alias
místo funkce, is_null() a intval() místo jazykové konstrukce, dirname(__FILE__) místo
__DIR__, get_class() místo ::class, call_user_func() místo přímého
volání a argument, který PHP ignoruje.
Jazyková konstrukce je rychlá vždy a nezáleží u ní na jmenném prostoru. Ve jmenném prostoru jsou opravy rizikové
(risky fixes): nekvalifikované is_null() může být funkce App\is_null(), kterou deklaruje váš
projekt. Dokud konfigurace neřekne nameResolution: certain, čekají na svolení.
cleanup:
aliasFunctions: [internal]
conversionFunctions: forbidden
is_null: forbidden
dirnameOfFile: forbidden
get_class: forbidden
call_user_func: forbidden
$count = sizeof($items); // The alias `sizeof()` must be written `count()`.
$id = intval($row['id']); // The `intval()` call must be written as the `(int)` cast.
if (is_null($user)) { // The `is_null()` call must be written as a comparison with `null`.
$dir = dirname(__FILE__); // The `dirname(__FILE__)` call must be written `__DIR__`.
}
$type = get_class($order); // The class name must be obtained with `$order::class`.
$result = call_user_func($callback, $id); // The callable must be called directly, not through `call_user_func()`.
$count = count($items);
$id = (int) $row['id'];
if ($user === null) {
$dir = __DIR__;
}
$type = $order::class;
$result = $callback($id);
Sekce se jmenuje stejně jako sada
cleanup, ale nejsou totéž: sada rozhoduje i v jiných sekcích, o nepoužitých importech nebo prázdných
komentářích, a z téhle sekce bere jen část. Kde se jméno píše do --only, fixRisky nebo
warnOnly, holé cleanup by mohlo znamenat obojí, a tak ho DressCode odmítne: sekci napíšete
cleanup.*, sadu dresscode/cleanup. Stejně je to se sekcemi a sadami correctness a
types.
cleanup.classNameNotation
The name of the current class, of the one the method runs through and of the parent; the class of an object is
cleanup.get_class.
classKeywordnebo'self::class':self::class,static::classandparent::class, neverget_class(),get_called_class(),get_parent_class()or__CLASS__keep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette
classKeyword, symfony keep ·
pokrývá SlevomatCodingStandard.Classes.ModernClassNameReference
cleanup.get_class
The class of an object obtained by get_class($object), which is $object::class; the name of the
current class is cleanup.classNameNotation.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá SlevomatCodingStandard.Classes.ModernClassNameReference
cleanup.aliasFunctions
The sets of functions whose aliases are written by their canonical names.
- seznam z těchto slov:
all: every set belowinternal: the core functions,sizeof()iscount(),join()isimplode()imap:imap_*ldap:ldap_*mysqli:mysqli_*pg:pg_exec()ispg_query()oci:oci_*odbc:odbc_*openssl:openssl_*sodium:sodium_*ftp:ftp_quit()isftp_close()posix:posix_errno()isposix_get_last_error()pcntl:pcntl_errno()ispcntl_get_last_error()time:mktime()andgmmktime()without arguments aretime()
keep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette
[internal, imap, pg], symfony keep · pokrývá no_alias_functions
cleanup.call_user_func
call_user_func($f, $x) is $f($x), call_user_func_array($f, $a) is
$f(...$a).
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · PHP 7.0 · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep · pokrývá regular_callable_call
cleanup.conversionFunctions
intval($x) is (int) $x; intval($x, 16) is no cast.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá modernize_types_casting
cleanup.__invoke
$f->__invoke($x) is $f($x).
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall
cleanup.dirnameOfFile
dirname(__FILE__) is __DIR__; nested dirname() by the levels argument.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá PhpCsFixerCustomFixers/no_useless_dirname_call,
combine_nested_dirname, dir_constant
cleanup.is_null
is_null($x) is $x === null.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá is_null
cleanup.strlenEmptyTest
strlen($s) === 0 is $s === ''.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · jen s typy · standardy: perCs keep, psr12 keep, nette
forbidden, symfony keep · pokrývá
PhpCsFixerCustomFixers/no_useless_strlen, string_length_to_empty
cleanup.settype
settype($x, 'int') as a statement is $x = (int) $x.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep · pokrývá set_type_to_cast
cleanup.redundantArguments
An argument PHP ignores or that repeats the default.
forbidden: never therekeep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette forbidden,
symfony keep