Volání funkcí
Sekce calls rozhoduje o voláních funkcí, která jdou napsat jinak a lépe: alias místo funkce,
is_null() a intval() místo jazykové konstrukce, dirname(__FILE__) místo
__DIR__, call_user_func() místo přímého volání, argument, který PHP ignoruje, a zapomenutý
ladicí výpis.
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í.
calls:
aliasFunctions: [internal]
conversionFunctions: forbidden
is_null: forbidden
dirnameOfFile: forbidden
debugOutput: commentedOut
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__`.
}
var_dump($items); // The call of `var_dump()` must be commented out.
$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__;
}
// var_dump($items);
$result = $callback($id);
calls.debugOutput
A statement calling a debugging function to print, a call that may return its output instead, print_r($a, true),
staying.
commentedOut: the statement changed into a comment,// var_dump($a);keep: nic se nevynucuje, kód zůstane, jak je
Požadavek · standardy: perCs keep, psr12 keep, nette keep,
symfony keep · pokrývá PhpCsFixerCustomFixers/commented_out_function
calls.debugFunctions
The debugging functions whose calls print.
- seznam jmen
Parametr, výchozí [print_r, var_dump, var_export] · standardy: perCs
[print_r, var_dump, var_export], psr12 [print_r, var_dump, var_export], nette
[print_r, var_dump, var_export], symfony [print_r, var_dump, var_export] ·
pokrývá PhpCsFixerCustomFixers/commented_out_function
calls.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
calls.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
calls.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
calls.explicitInvokeCalls
$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
calls.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
calls.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
calls.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
calls.uselessArguments
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