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"
on: ["pull_request", "push"]
on:
pull_request: ~
push: ~
jobs:
code-coverage:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,71 +1,52 @@
<?xml version="1.0"?>
<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"
>
<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">
<projectFiles>
<directory name="src" />
<directory name="integration" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/bootstrap.php"/>
<file name="src/preload.php"/>
<file name="src/Psl/Internal/Loader.php"/>
<file name="src/bootstrap.php" />
<file name="src/preload.php" />
<file name="src/Psl/Internal/Loader.php" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<DuplicateFunction errorLevel="suppress" />
<LessSpecificReturnType errorLevel="error"/>
<DeprecatedMethod errorLevel="error"/>
<DeprecatedProperty errorLevel="error"/>
<DeprecatedClass errorLevel="error"/>
<DeprecatedConstant errorLevel="error"/>
<DeprecatedInterface errorLevel="error"/>
<DeprecatedTrait errorLevel="error"/>
<ForbiddenCode errorLevel="error"/>
<InternalMethod errorLevel="error"/>
<InternalProperty errorLevel="error"/>
<InternalClass errorLevel="error"/>
<MissingClosureReturnType errorLevel="error"/>
<MissingReturnType errorLevel="error"/>
<MissingPropertyType errorLevel="error"/>
<InvalidDocblock errorLevel="error"/>
<PropertyNotSetInConstructor errorLevel="error"/>
<MissingConstructor errorLevel="error"/>
<MissingClosureParamType errorLevel="error"/>
<MissingParamType errorLevel="error"/>
<DocblockTypeContradiction errorLevel="error"/>
<RawObjectIteration errorLevel="error"/>
<InvalidStringClass errorLevel="error"/>
<UnresolvableInclude errorLevel="error"/>
<LessSpecificReturnType errorLevel="error" />
<DeprecatedMethod errorLevel="error" />
<DeprecatedProperty errorLevel="error" />
<DeprecatedClass errorLevel="error" />
<DeprecatedConstant errorLevel="error" />
<DeprecatedInterface errorLevel="error" />
<DeprecatedTrait errorLevel="error" />
<ForbiddenCode errorLevel="error" />
<InternalMethod errorLevel="error" />
<InternalProperty errorLevel="error" />
<InternalClass errorLevel="error" />
<MissingClosureReturnType errorLevel="error" />
<MissingReturnType errorLevel="error" />
<MissingPropertyType errorLevel="error" />
<InvalidDocblock errorLevel="error" />
<PropertyNotSetInConstructor errorLevel="error" />
<MissingConstructor errorLevel="error" />
<MissingClosureParamType errorLevel="error" />
<MissingParamType errorLevel="error" />
<DocblockTypeContradiction errorLevel="error" />
<RawObjectIteration errorLevel="error" />
<InvalidStringClass errorLevel="error" />
<UnresolvableInclude errorLevel="error" />
<!-- Redundant expressions should not be considered errors. -->
<!-- Sometimes we want to enforce things at runtime, as well using static analysis -->
<RedundantConditionGivenDocblockType errorLevel="suppress"/>
<RedundantCondition errorLevel="suppress"/>
<RedundantCast 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" />
<RedundantConditionGivenDocblockType errorLevel="suppress" />
<RedundantCondition errorLevel="suppress" />
<RedundantCast errorLevel="suppress" />
<RedundantCastGivenDocblockType errorLevel="suppress" />
</issueHandlers>
<plugins>
<pluginClass class="Psl\Integration\Psalm\Plugin"/>
<pluginClass class="Psl\Integration\Psalm\Plugin" />
</plugins>
</psalm>

View File

@ -84,11 +84,18 @@ final class Context
* Pump data into an active hashing context.
*
* @psalm-mutation-free
*
* @throws Exception\RuntimeException If unable to pump data into the active hashing context.
*/
public function update(string $data): Context
{
$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);
}

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.
*
* @throws Psl\Exception\InvariantViolationException If the given algorithm is unsupported.
* @throws Hash\Exception\RuntimeException If unable to pump data into the hashing context.
*
* @pure
*/

View File

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

View File

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

View File

@ -17,8 +17,10 @@ use Psl;
* @throws Psl\Exception\InvariantViolationException If the offset is out-of-bounds.
*
* @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;
@ -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);
return $offset;
if (!$assert) {
return $offset;
}
return true;
}

View File

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