remove unused function call suppression (#165)

* remove unused function call suppression

* run static analysis every 3 hours ( with latest psalm version )
This commit is contained in:
Saif Eddin Gmati 2021-03-24 09:23:04 +01:00 committed by GitHub
parent 2f65c9f878
commit 887324a0c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 102 additions and 79 deletions

View File

@ -1,6 +1,8 @@
name: "code coverage" name: "code coverage"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
jobs: jobs:
code-coverage: code-coverage:

View File

@ -1,6 +1,8 @@
name: "coding standards" name: "coding standards"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
jobs: jobs:
coding-standards: coding-standards:

View File

@ -1,6 +1,8 @@
name: "documentation check" name: "documentation check"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
jobs: jobs:
doc-check: doc-check:

View File

@ -1,6 +1,8 @@
name: "security analysis" name: "security analysis"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
jobs: jobs:
security-analysis: security-analysis:

View File

@ -1,6 +1,10 @@
name: "static analysis" name: "static analysis"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
schedule:
- cron: '0 */3 * * *'
jobs: jobs:
static-analysis: static-analysis:

View File

@ -1,6 +1,8 @@
name: "unit tests" name: "unit tests"
on: ["pull_request", "push"] on:
pull_request: ~
push: ~
jobs: jobs:
unit-tests: unit-tests:

View File

@ -14,7 +14,7 @@
- [algorithms](./../../src/Psl/Hash/algorithms.php#L16) - [algorithms](./../../src/Psl/Hash/algorithms.php#L16)
- [equals](./../../src/Psl/Hash/equals.php#L14) - [equals](./../../src/Psl/Hash/equals.php#L14)
- [hash](./../../src/Psl/Hash/hash.php#L16) - [hash](./../../src/Psl/Hash/hash.php#L17)
#### `Classes` #### `Classes`

View File

@ -1,20 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<psalm <psalm totallyTyped="true" resolveFromConfigFile="true" forbidEcho="true" strictBinaryOperands="true" phpVersion="7.4" allowPhpStormGenerics="true" allowStringToStandInForClass="true" rememberPropertyAssignmentsAfterCall="false" skipChecksOnUnresolvableIncludes="false" checkForThrowsDocblock="true" checkForThrowsInGlobalScope="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
totallyTyped="true"
resolveFromConfigFile="true"
forbidEcho="true"
strictBinaryOperands="true"
phpVersion="7.4"
allowPhpStormGenerics="true"
allowStringToStandInForClass="true"
rememberPropertyAssignmentsAfterCall="false"
skipChecksOnUnresolvableIncludes="false"
checkForThrowsDocblock="true"
checkForThrowsInGlobalScope="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles> <projectFiles>
<directory name="src" /> <directory name="src" />
<directory name="integration" /> <directory name="integration" />
@ -59,10 +44,6 @@
<RedundantCondition errorLevel="suppress" /> <RedundantCondition errorLevel="suppress" />
<RedundantCast errorLevel="suppress" /> <RedundantCast errorLevel="suppress" />
<RedundantCastGivenDocblockType errorLevel="suppress" /> <RedundantCastGivenDocblockType errorLevel="suppress" />
<!-- Not using the result of pure functions is common within PSL -->
<!-- e.g: with and Psl\invariant_violations() -->
<UnusedFunctionCall errorLevel="suppress" />
</issueHandlers> </issueHandlers>
<plugins> <plugins>

View File

@ -84,11 +84,18 @@ final class Context
* Pump data into an active hashing context. * Pump data into an active hashing context.
* *
* @psalm-mutation-free * @psalm-mutation-free
*
* @throws Exception\RuntimeException If unable to pump data into the active hashing context.
*/ */
public function update(string $data): Context public function update(string $data): Context
{ {
$internal_context = hash_copy($this->internalContext); $internal_context = hash_copy($this->internalContext);
hash_update($internal_context, $data);
// @codeCoverageIgnoreStart
if (!hash_update($internal_context, $data)) {
throw new Exception\RuntimeException('Unable to pump data into the active hashing context.');
}
// @codeCoverageIgnoreEnd
return new self($internal_context); return new self($internal_context);
} }

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Psl\Hash\Exception;
use Psl\Exception;
interface ExceptionInterface extends Exception\ExceptionInterface
{
}

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Psl\Hash\Exception;
use Psl\Exception;
class RuntimeException extends Exception\RuntimeException implements ExceptionInterface
{
}

View File

@ -11,6 +11,7 @@ use Psl\Hash;
* Generate a keyed hash value using the HMAC method. * Generate a keyed hash value using the HMAC method.
* *
* @throws Psl\Exception\InvariantViolationException If the given algorithm is unsupported. * @throws Psl\Exception\InvariantViolationException If the given algorithm is unsupported.
* @throws Hash\Exception\RuntimeException If unable to pump data into the hashing context.
* *
* @pure * @pure
*/ */

View File

@ -10,6 +10,7 @@ use Psl;
* Generate a hash value (message digest). * Generate a hash value (message digest).
* *
* @throws Psl\Exception\InvariantViolationException If the given algorithm is unsupported. * @throws Psl\Exception\InvariantViolationException If the given algorithm is unsupported.
* @throws Exception\RuntimeException If unable to pump data into the hashing context.
* *
* @pure * @pure
*/ */

View File

@ -612,6 +612,8 @@ final class Loader
'Psl\Type\Type', 'Psl\Type\Type',
'Psl\Json\Exception\DecodeException', 'Psl\Json\Exception\DecodeException',
'Psl\Json\Exception\EncodeException', 'Psl\Json\Exception\EncodeException',
'Psl\Hash\Exception\ExceptionInterface',
'Psl\Hash\Exception\RuntimeException',
'Psl\Hash\Context', 'Psl\Hash\Context',
'Psl\Encoding\Exception\IncorrectPaddingException', 'Psl\Encoding\Exception\IncorrectPaddingException',
'Psl\Encoding\Exception\RangeException', 'Psl\Encoding\Exception\RangeException',

View File

@ -17,8 +17,10 @@ use Psl;
* @throws Psl\Exception\InvariantViolationException If the offset is out-of-bounds. * @throws Psl\Exception\InvariantViolationException If the offset is out-of-bounds.
* *
* @internal * @internal
*
* @return ($assert is true ? bool : int)
*/ */
function validate_offset(int $offset, int $length): int function validate_offset(int $offset, int $length, bool $assert = false)
{ {
$original_offset = $offset; $original_offset = $offset;
@ -28,5 +30,9 @@ function validate_offset(int $offset, int $length): int
Psl\invariant($offset >= 0 && $offset <= $length, 'Offset (%d) was out-of-bounds.', $original_offset); Psl\invariant($offset >= 0 && $offset <= $length, 'Offset (%d) was out-of-bounds.', $original_offset);
if (!$assert) {
return $offset; return $offset;
} }
return true;
}

View File

@ -21,9 +21,7 @@ use Psl;
function contains(string $haystack, string $needle, int $offset = 0): bool function contains(string $haystack, string $needle, int $offset = 0): bool
{ {
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack)); return Psl\Internal\validate_offset($offset, length($haystack), true);
return true;
} }
return null !== search($haystack, $needle, $offset); return null !== search($haystack, $needle, $offset);

View File

@ -20,10 +20,9 @@ use Psl;
*/ */
function contains_ci(string $haystack, string $needle, int $offset = 0): bool function contains_ci(string $haystack, string $needle, int $offset = 0): bool
{ {
$length = length($haystack);
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack)); return Psl\Internal\validate_offset($offset, $length, true);
return true;
} }
return null !== search_ci($haystack, $needle, $offset); return null !== search_ci($haystack, $needle, $offset);

View File

@ -21,9 +21,7 @@ use Psl;
function contains(string $haystack, string $needle, int $offset = 0): bool function contains(string $haystack, string $needle, int $offset = 0): bool
{ {
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack)); return Psl\Internal\validate_offset($offset, length($haystack), true);
return true;
} }
return null !== search($haystack, $needle, $offset); return null !== search($haystack, $needle, $offset);

View File

@ -21,9 +21,7 @@ use Psl;
function contains_ci(string $haystack, string $needle, int $offset = 0): bool function contains_ci(string $haystack, string $needle, int $offset = 0): bool
{ {
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack)); return Psl\Internal\validate_offset($offset, length($haystack), true);
return true;
} }
return null !== search_ci($haystack, $needle, $offset); return null !== search_ci($haystack, $needle, $offset);

View File

@ -42,9 +42,7 @@ use Psl;
function contains(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): bool function contains(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): bool
{ {
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack, $encoding)); return Psl\Internal\validate_offset($offset, length($haystack, $encoding), true);
return true;
} }
return null !== search($haystack, $needle, $offset, $encoding); return null !== search($haystack, $needle, $offset, $encoding);

View File

@ -42,9 +42,7 @@ use Psl;
function contains_ci(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): bool function contains_ci(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): bool
{ {
if ('' === $needle) { if ('' === $needle) {
Psl\Internal\validate_offset($offset, length($haystack, $encoding)); return Psl\Internal\validate_offset($offset, length($haystack, $encoding), true);
return true;
} }
return null !== search_ci($haystack, $needle, $offset, $encoding); return null !== search_ci($haystack, $needle, $offset, $encoding);