Skip to content

Commit

Permalink
remove unused function call suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed Mar 24, 2021
1 parent 2f65c9f commit 47ad2b2
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 73 deletions.
83 changes: 32 additions & 51 deletions psalm.xml
@@ -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>
7 changes: 6 additions & 1 deletion src/Psl/Hash/Context.php
Expand Up @@ -84,11 +84,16 @@ public static function hmac(string $algorithm, string $key): 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);

if (!hash_update($internal_context, $data)) {
throw new Exception\RuntimeException('Unable to pump data into the active hashing context.');
}

return new self($internal_context);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Psl/Hash/Exception/ExceptionInterface.php
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Psl\Hash\Exception;

use Psl\Exception;

interface ExceptionInterface extends Exception\ExceptionInterface
{
}
11 changes: 11 additions & 0 deletions src/Psl/Hash/Exception/RuntimeException.php
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Psl\Hash\Exception;

use Psl\Exception;

class RuntimeException extends Exception\RuntimeException implements ExceptionInterface
{
}
2 changes: 2 additions & 0 deletions src/Psl/Internal/Loader.php
Expand Up @@ -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',
Expand Down
12 changes: 9 additions & 3 deletions src/Psl/Internal/validate_offset.php
Expand Up @@ -15,10 +15,12 @@
* @codeCoverageIgnore
*
* @throws Psl\Exception\InvariantViolationException If the offset is out-of-bounds.
*
*
* @internal
*
* @psalm-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;

Expand All @@ -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;
}
4 changes: 1 addition & 3 deletions src/Psl/Str/Byte/contains.php
Expand Up @@ -21,9 +21,7 @@
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);
Expand Down
5 changes: 2 additions & 3 deletions src/Psl/Str/Byte/contains_ci.php
Expand Up @@ -20,10 +20,9 @@
*/
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);
Expand Down
4 changes: 1 addition & 3 deletions src/Psl/Str/Grapheme/contains.php
Expand Up @@ -21,9 +21,7 @@
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);
Expand Down
4 changes: 1 addition & 3 deletions src/Psl/Str/Grapheme/contains_ci.php
Expand Up @@ -21,9 +21,7 @@
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);
Expand Down
4 changes: 1 addition & 3 deletions src/Psl/Str/contains.php
Expand Up @@ -42,9 +42,7 @@
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);
Expand Down
4 changes: 1 addition & 3 deletions src/Psl/Str/contains_ci.php
Expand Up @@ -42,9 +42,7 @@
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);
Expand Down

0 comments on commit 47ad2b2

Please sign in to comment.