Increase PHPStan strictness (#908)

* Enable color

* Increase PHPStan strictness

* Fix static analysis error

------ --------------------------------------------------
Line   src/Curl/MultiCurl.php
------ --------------------------------------------------
593    Variable $interval_seconds might not be defined.
        🪪  variable.undefined
------ --------------------------------------------------

* Increase PHPStan strictness

* Fix static analysis errors

------ -----------------------------------------------------------------
Line   scripts/bump_major_version.php
------ -----------------------------------------------------------------
8      Binary operation "+=" between string and 1 results in an error.
        🪪  assignOp.invalid
------ -----------------------------------------------------------------

------ -----------------------------------------------------------------
Line   scripts/bump_minor_version.php
------ -----------------------------------------------------------------
8      Binary operation "+=" between string and 1 results in an error.
        🪪  assignOp.invalid
------ -----------------------------------------------------------------

------ -----------------------------------------------------------------
Line   scripts/bump_patch_version.php
------ -----------------------------------------------------------------
8      Binary operation "+=" between string and 1 results in an error.
        🪪  assignOp.invalid
------ -----------------------------------------------------------------

* Fix static analysis errors

------ --------------------------------------------------------------------------------------------------------------------
Line   src/Curl/CaseInsensitiveArray.php
------ --------------------------------------------------------------------------------------------------------------------
132    PHPDoc tag @param has invalid value (void): Unexpected token "\n     * ", expected variable at offset 42 on line 4
        🪪  phpDoc.parseError
145    PHPDoc tag @param has invalid value (void): Unexpected token "\n     * ", expected variable at offset 44 on line 4
        🪪  phpDoc.parseError
158    PHPDoc tag @param has invalid value (void): Unexpected token "\n     * ", expected variable at offset 41 on line 4
        🪪  phpDoc.parseError
171    PHPDoc tag @param has invalid value (void): Unexpected token "\n     * ", expected variable at offset 40 on line 4
        🪪  phpDoc.parseError
197    PHPDoc tag @param has invalid value (void): Unexpected token "\n     * ", expected variable at offset 43 on line 4
        🪪  phpDoc.parseError
------ --------------------------------------------------------------------------------------------------------------------

* Fix static analysis errors

------ -----------------------------------------------------------------------------------
Line   src/Curl/MultiCurl.php
------ -----------------------------------------------------------------------------------
937    Comparison operation "<" between float and (array|float|int) results in an error.
        🪪  smaller.invalid
941    Comparison operation "<" between float and (array|float|int) results in an error.
        🪪  smaller.invalid
------ -----------------------------------------------------------------------------------

* Increase PHPStan strictness

* Fix static analysis errors

------ -------------------------------------------
Line   src/Curl/Decoder.php
------ -------------------------------------------
22     Offset '0' does not exist on list<mixed>.
        🪪  offsetAccess.notFound
41     Offset '0' does not exist on list<mixed>.
        🪪  offsetAccess.notFound
------ -------------------------------------------
This commit is contained in:
Zach Borboa
2025-01-11 21:51:30 -05:00
committed by GitHub
parent 87fc9b3796
commit 634ee48552
8 changed files with 9 additions and 13 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ parameters:
reportUnmatchedIgnoredErrors: false
# TODO: Increase rule level to be more strict.
level: 0
level: 3
# TODO: Remove all exclusions except vendor/ and fix related errors.
excludePaths:
+1 -1
View File
@@ -5,7 +5,7 @@ require __DIR__ . '/../src/Curl/Curl.php';
$current_version = Curl\Curl::VERSION;
list($major, $_, $__) = explode('.', $current_version);
$new_version = implode('.', [(string)((int)$major += 1), '0', '0']);
$new_version = implode('.', [(string)((int)$major + 1), '0', '0']);
foreach (
[
+1 -1
View File
@@ -5,7 +5,7 @@ require __DIR__ . '/../src/Curl/Curl.php';
$current_version = Curl\Curl::VERSION;
list($major, $minor, $_) = explode('.', $current_version);
$new_version = implode('.', [$major, (string)((int)$minor += 1), '0']);
$new_version = implode('.', [$major, (string)((int)$minor + 1), '0']);
foreach (
[
+1 -1
View File
@@ -5,7 +5,7 @@ require __DIR__ . '/../src/Curl/Curl.php';
$current_version = Curl\Curl::VERSION;
list($major, $minor, $patch) = explode('.', $current_version);
$new_version = implode('.', [$major, $minor, (string)((int)$patch += 1)]);
$new_version = implode('.', [$major, $minor, (string)((int)$patch + 1)]);
foreach (
[
-5
View File
@@ -129,7 +129,6 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
/**
* Count
*
* @param void
* @return int The number of elements stored in the array.
* @see https://secure.php.net/manual/en/countable.count.php
*/
@@ -142,7 +141,6 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
/**
* Current
*
* @param void
* @return mixed Data at the current position.
* @see https://secure.php.net/manual/en/iterator.current.php
*/
@@ -155,7 +153,6 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
/**
* Next
*
* @param void
* @return void
* @see https://secure.php.net/manual/en/iterator.next.php
*/
@@ -168,7 +165,6 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
/**
* Key
*
* @param void
* @return mixed Case-sensitive key at current position.
* @see https://secure.php.net/manual/en/iterator.key.php
*/
@@ -194,7 +190,6 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
/**
* Rewind
*
* @param void
* @return void
* @see https://secure.php.net/manual/en/iterator.rewind.php
*/
+2 -2
View File
@@ -18,7 +18,7 @@ class Decoder
{
$args = func_get_args();
$response = call_user_func_array('json_decode', $args);
if ($response === null) {
if ($response === null && isset($args['0'])) {
$response = $args['0'];
}
return $response;
@@ -37,7 +37,7 @@ class Decoder
{
$args = func_get_args();
$response = @call_user_func_array('simplexml_load_string', $args);
if ($response === false) {
if ($response === false && array_key_exists('0', $args)) {
$response = $args['0'];
}
return $response;
+2 -1
View File
@@ -578,6 +578,7 @@ class MultiCurl extends BaseCurl
$unit = strtolower($matches['3']);
// Convert interval to seconds based on unit.
$interval_seconds = '';
if ($unit === 's') {
$interval_seconds = $interval * 1;
} elseif ($unit === 'm') {
@@ -925,7 +926,7 @@ class MultiCurl extends BaseCurl
*/
private function waitUntilRequestQuotaAvailable()
{
$sleep_until = $this->currentStartTime + $this->intervalSeconds;
$sleep_until = (float)($this->currentStartTime + $this->intervalSeconds);
$sleep_seconds = $sleep_until - microtime(true);
// Avoid using time_sleep_until() as it appears to be less precise and not sleep long enough.
+1 -1
View File
@@ -11,7 +11,7 @@ pushd ..
set -x
if [[ $(echo "${CI_PHP_VERSION} >= 7.4" | bc -l) -eq 1 ]]; then
vendor/bin/phpstan analyse --configuration="phpstan.neon" .
vendor/bin/phpstan analyse --ansi --configuration="phpstan.neon" .
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpstan static analysis check failed"
errors+=("phpstan static analysis check failed")