Explicitly cast int to string when expected by PHP functions
Summary: Avoid `Parameter $foo of function bar expects string, int[|string] given` output in static code analysis by explicitly casting to string when a return value is an int, or by passing a string by encapsulating an int with apostrophes. Test Plan: Run static code analysis. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Differential Revision: https://we.phorge.it/D26074
This commit is contained in:
parent
6e43f89668
commit
6bcc10fbf1
|
@ -33,7 +33,7 @@ abstract class AphrontHTTPSink extends Phobject {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function writeHTTPStatus($code, $message = '') {
|
final public function writeHTTPStatus($code, $message = '') {
|
||||||
if (!preg_match('/^\d{3}$/', $code)) {
|
if (!preg_match('/^\d{3}$/', (string)$code)) {
|
||||||
throw new Exception(pht("Malformed HTTP status code '%s'!", $code));
|
throw new Exception(pht("Malformed HTTP status code '%s'!", $code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -392,7 +392,7 @@ abstract class PhabricatorAphlictManagementWorkflow
|
||||||
"%s\n",
|
"%s\n",
|
||||||
pht('Starting Aphlict server in foreground...'));
|
pht('Starting Aphlict server in foreground...'));
|
||||||
} else {
|
} else {
|
||||||
Filesystem::writeFile($this->getPIDPath(), getmypid());
|
Filesystem::writeFile($this->getPIDPath(), (string)getmypid());
|
||||||
}
|
}
|
||||||
|
|
||||||
$command = $this->getStartCommand($this->getServerArgv());
|
$command = $this->getStartCommand($this->getServerArgv());
|
||||||
|
|
|
@ -403,7 +403,7 @@ final class PhabricatorTOTPAuthFactor extends PhabricatorAuthFactor {
|
||||||
((ord($hash[$offset + 3]) ) );
|
((ord($hash[$offset + 3]) ) );
|
||||||
|
|
||||||
$code = ($code % 1000000);
|
$code = ($code % 1000000);
|
||||||
$code = str_pad($code, 6, '0', STR_PAD_LEFT);
|
$code = str_pad((string)$code, 6, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ final class PhabricatorWebServerSetupCheck extends PhabricatorSetupCheck {
|
||||||
->replaceQueryParam($expect_key, $expect_value);
|
->replaceQueryParam($expect_key, $expect_value);
|
||||||
|
|
||||||
$self_future = id(new HTTPSFuture($base_uri))
|
$self_future = id(new HTTPSFuture($base_uri))
|
||||||
->addHeader('X-Setup-SelfCheck', 1)
|
->addHeader('X-Setup-SelfCheck', '1')
|
||||||
->addHeader('Accept-Encoding', 'gzip')
|
->addHeader('Accept-Encoding', 'gzip')
|
||||||
->setDisableContentDecoding(true)
|
->setDisableContentDecoding(true)
|
||||||
->setHTTPBasicAuthCredentials(
|
->setHTTPBasicAuthCredentials(
|
||||||
|
@ -56,7 +56,7 @@ final class PhabricatorWebServerSetupCheck extends PhabricatorSetupCheck {
|
||||||
$gzip_compressed = gzencode($gzip_uncompressed);
|
$gzip_compressed = gzencode($gzip_uncompressed);
|
||||||
|
|
||||||
$gzip_future = id(new HTTPSFuture($base_uri))
|
$gzip_future = id(new HTTPSFuture($base_uri))
|
||||||
->addHeader('X-Setup-SelfCheck', 1)
|
->addHeader('X-Setup-SelfCheck', '1')
|
||||||
->addHeader('Content-Encoding', 'gzip')
|
->addHeader('Content-Encoding', 'gzip')
|
||||||
->setMethod('POST')
|
->setMethod('POST')
|
||||||
->setTimeout(5)
|
->setTimeout(5)
|
||||||
|
|
|
@ -87,7 +87,7 @@ final class DifferentialRevisionAffectedPathsController
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort rows by path name.
|
// Sort rows by path name.
|
||||||
$rows = isort($rows, 3);
|
$rows = isort($rows, '3');
|
||||||
|
|
||||||
$table_view = id(new AphrontTableView($rows))
|
$table_view = id(new AphrontTableView($rows))
|
||||||
->setNoDataString(pht('This revision has no indexed affected paths.'))
|
->setNoDataString(pht('This revision has no indexed affected paths.'))
|
||||||
|
|
|
@ -321,7 +321,7 @@ final class PhabricatorFeedStoryPublisher extends Phobject {
|
||||||
// We're on a 32-bit machine.
|
// We're on a 32-bit machine.
|
||||||
if (function_exists('bcadd')) {
|
if (function_exists('bcadd')) {
|
||||||
// Try to use the 'bc' extension.
|
// Try to use the 'bc' extension.
|
||||||
return bcadd(bcmul($time, bcpow(2, 32)), $rand);
|
return bcadd(bcmul($time, bcpow('2', '32')), $rand);
|
||||||
} else {
|
} else {
|
||||||
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
||||||
// rid of this.
|
// rid of this.
|
||||||
|
|
|
@ -45,7 +45,7 @@ final class PhabricatorFeedStoryData
|
||||||
// We're on a 32-bit machine.
|
// We're on a 32-bit machine.
|
||||||
if (function_exists('bcadd')) {
|
if (function_exists('bcadd')) {
|
||||||
// Try to use the 'bc' extension.
|
// Try to use the 'bc' extension.
|
||||||
return bcdiv($this->chronologicalKey, bcpow(2, 32));
|
return bcdiv($this->chronologicalKey, bcpow('2', '32'));
|
||||||
} else {
|
} else {
|
||||||
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
|
||||||
// rid of this.
|
// rid of this.
|
||||||
|
|
|
@ -47,7 +47,7 @@ final class PhabricatorLocalDiskFileStorageEngine
|
||||||
// have one directory with a zillion files in it, since this is generally
|
// have one directory with a zillion files in it, since this is generally
|
||||||
// bad news.
|
// bad news.
|
||||||
do {
|
do {
|
||||||
$name = md5(mt_rand());
|
$name = md5((string)mt_rand());
|
||||||
$name = preg_replace('/^(..)(..)(.*)$/', '\\1/\\2/\\3', $name);
|
$name = preg_replace('/^(..)(..)(.*)$/', '\\1/\\2/\\3', $name);
|
||||||
if (!Filesystem::pathExists($root.'/'.$name)) {
|
if (!Filesystem::pathExists($root.'/'.$name)) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -194,7 +194,7 @@ final class PhabricatorMetaMTAMailViewController
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort headers by name.
|
// Sort headers by name.
|
||||||
$headers = isort($headers, 0);
|
$headers = isort($headers, '0');
|
||||||
|
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
list($key, $value) = $header;
|
list($key, $value) = $header;
|
||||||
|
|
|
@ -259,7 +259,7 @@ final class PhrequentTimeBlock extends Phobject {
|
||||||
* @return list<pair<int, int>> Nonoverlapping time ranges.
|
* @return list<pair<int, int>> Nonoverlapping time ranges.
|
||||||
*/
|
*/
|
||||||
public static function mergeTimeRanges(array $ranges) {
|
public static function mergeTimeRanges(array $ranges) {
|
||||||
$ranges = isort($ranges, 0);
|
$ranges = isort($ranges, '0');
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ final class PhabricatorSearchNgramEngine
|
||||||
|
|
||||||
$ngrams = array();
|
$ngrams = array();
|
||||||
foreach ($unique_tokens as $token => $ignored) {
|
foreach ($unique_tokens as $token => $ignored) {
|
||||||
|
$token = (string)$token;
|
||||||
$token_v = phutil_utf8v($token);
|
$token_v = phutil_utf8v($token);
|
||||||
$length = count($token_v);
|
$length = count($token_v);
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ final class PhabricatorEmailPreferencesSettingsPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort them, then put "Common" at the top.
|
// Sort them, then put "Common" at the top.
|
||||||
$tag_groups = isort($tag_groups, 0);
|
$tag_groups = isort($tag_groups, '0');
|
||||||
if ($common_tags) {
|
if ($common_tags) {
|
||||||
array_unshift($tag_groups, array(pht('Common'), $common_tags));
|
array_unshift($tag_groups, array(pht('Common'), $common_tags));
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ final class PhabricatorXHProfProfileSymbolView
|
||||||
$data[$key]['wt'] / $flat[$symbol]['wt'],
|
$data[$key]['wt'] / $flat[$symbol]['wt'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$child_rows = isort($child_rows, 2);
|
$child_rows = isort($child_rows, '2');
|
||||||
$child_rows = array_reverse($child_rows);
|
$child_rows = array_reverse($child_rows);
|
||||||
$rows = array_merge(
|
$rows = array_merge(
|
||||||
$rows,
|
$rows,
|
||||||
|
|
|
@ -122,7 +122,7 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
||||||
* use case.
|
* use case.
|
||||||
*
|
*
|
||||||
* @param string $src_phid Source PHID.
|
* @param string $src_phid Source PHID.
|
||||||
* @param string $edge_type Edge type constant.
|
* @param string $edge_type Edge type constant.
|
||||||
* @return list<string> List of destination PHIDs.
|
* @return list<string> List of destination PHIDs.
|
||||||
*/
|
*/
|
||||||
public static function loadDestinationPHIDs($src_phid, $edge_type) {
|
public static function loadDestinationPHIDs($src_phid, $edge_type) {
|
||||||
|
|
Loading…
Reference in a new issue