From 887324a0c341795e772b5d96e9eb27b41b057f2e Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati <29315886+azjezz@users.noreply.github.com> Date: Wed, 24 Mar 2021 09:23:04 +0100 Subject: [PATCH] remove unused function call suppression (#165) * remove unused function call suppression * run static analysis every 3 hours ( with latest psalm version ) --- .github/workflows/code-coverage.yml | 4 +- .github/workflows/coding-standards.yml | 4 +- .github/workflows/documentation-check.yml | 4 +- .github/workflows/security-analysis.yml | 4 +- .github/workflows/static-analysis.yml | 6 +- .github/workflows/unit-tests.yml | 4 +- docs/component/hash.md | 2 +- psalm.xml | 83 +++++++------------ src/Psl/Hash/Context.php | 9 +- src/Psl/Hash/Exception/ExceptionInterface.php | 11 +++ src/Psl/Hash/Exception/RuntimeException.php | 11 +++ src/Psl/Hash/Hmac/hash.php | 1 + src/Psl/Hash/hash.php | 1 + src/Psl/Internal/Loader.php | 2 + src/Psl/Internal/validate_offset.php | 10 ++- src/Psl/Str/Byte/contains.php | 4 +- src/Psl/Str/Byte/contains_ci.php | 5 +- src/Psl/Str/Grapheme/contains.php | 4 +- src/Psl/Str/Grapheme/contains_ci.php | 4 +- src/Psl/Str/contains.php | 4 +- src/Psl/Str/contains_ci.php | 4 +- 21 files changed, 102 insertions(+), 79 deletions(-) create mode 100644 src/Psl/Hash/Exception/ExceptionInterface.php create mode 100644 src/Psl/Hash/Exception/RuntimeException.php diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index c86b51c..4a692a2 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -1,6 +1,8 @@ name: "code coverage" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ jobs: code-coverage: diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 1a6ec26..90d9ef3 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -1,6 +1,8 @@ name: "coding standards" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ jobs: coding-standards: diff --git a/.github/workflows/documentation-check.yml b/.github/workflows/documentation-check.yml index 10b43ea..ef2fbd0 100644 --- a/.github/workflows/documentation-check.yml +++ b/.github/workflows/documentation-check.yml @@ -1,6 +1,8 @@ name: "documentation check" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ jobs: doc-check: diff --git a/.github/workflows/security-analysis.yml b/.github/workflows/security-analysis.yml index 3e4a23d..6f716fd 100644 --- a/.github/workflows/security-analysis.yml +++ b/.github/workflows/security-analysis.yml @@ -1,6 +1,8 @@ name: "security analysis" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ jobs: security-analysis: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index dc23072..8ba6e07 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,6 +1,10 @@ name: "static analysis" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ + schedule: + - cron: '0 */3 * * *' jobs: static-analysis: diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 53b9cc4..d75d4c6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,6 +1,8 @@ name: "unit tests" -on: ["pull_request", "push"] +on: + pull_request: ~ + push: ~ jobs: unit-tests: diff --git a/docs/component/hash.md b/docs/component/hash.md index 2e9cf01..1368287 100644 --- a/docs/component/hash.md +++ b/docs/component/hash.md @@ -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` diff --git a/psalm.xml b/psalm.xml index cb7d623..fb143f8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,71 +1,52 @@ - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + - + diff --git a/src/Psl/Hash/Context.php b/src/Psl/Hash/Context.php index 5612fc7..e3c39c1 100644 --- a/src/Psl/Hash/Context.php +++ b/src/Psl/Hash/Context.php @@ -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); } diff --git a/src/Psl/Hash/Exception/ExceptionInterface.php b/src/Psl/Hash/Exception/ExceptionInterface.php new file mode 100644 index 0000000..bc5601a --- /dev/null +++ b/src/Psl/Hash/Exception/ExceptionInterface.php @@ -0,0 +1,11 @@ += 0 && $offset <= $length, 'Offset (%d) was out-of-bounds.', $original_offset); - return $offset; + if (!$assert) { + return $offset; + } + + return true; } diff --git a/src/Psl/Str/Byte/contains.php b/src/Psl/Str/Byte/contains.php index ba1227f..5663cc2 100644 --- a/src/Psl/Str/Byte/contains.php +++ b/src/Psl/Str/Byte/contains.php @@ -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); diff --git a/src/Psl/Str/Byte/contains_ci.php b/src/Psl/Str/Byte/contains_ci.php index a2c75d4..4b1f22e 100644 --- a/src/Psl/Str/Byte/contains_ci.php +++ b/src/Psl/Str/Byte/contains_ci.php @@ -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); diff --git a/src/Psl/Str/Grapheme/contains.php b/src/Psl/Str/Grapheme/contains.php index 2c81b57..7c817e5 100644 --- a/src/Psl/Str/Grapheme/contains.php +++ b/src/Psl/Str/Grapheme/contains.php @@ -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); diff --git a/src/Psl/Str/Grapheme/contains_ci.php b/src/Psl/Str/Grapheme/contains_ci.php index 68b765b..4ddbd85 100644 --- a/src/Psl/Str/Grapheme/contains_ci.php +++ b/src/Psl/Str/Grapheme/contains_ci.php @@ -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); diff --git a/src/Psl/Str/contains.php b/src/Psl/Str/contains.php index de01a5b..ef9cc03 100644 --- a/src/Psl/Str/contains.php +++ b/src/Psl/Str/contains.php @@ -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); diff --git a/src/Psl/Str/contains_ci.php b/src/Psl/Str/contains_ci.php index 6833dfb..8fb2b61 100644 --- a/src/Psl/Str/contains_ci.php +++ b/src/Psl/Str/contains_ci.php @@ -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);