From b20e4ebfa5d6d23890ed59ac1eb3f67761b7ca18 Mon Sep 17 00:00:00 2001 From: Denis Smet Date: Mon, 11 Mar 2024 01:40:55 +0400 Subject: [PATCH] PHPStan fixed! --- src/Csv/CsvFile.php | 8 ++++---- src/Validators/Rules/IsDomain.php | 2 +- src/Validators/Rules/IsFloat.php | 2 +- src/Validators/Rules/IsInt.php | 2 +- src/Validators/Rules/IsLatitude.php | 2 +- src/Validators/Rules/IsLongitude.php | 2 +- src/Validators/Rules/IsUuid4.php | 2 +- src/Validators/Rules/Max.php | 2 +- src/Validators/Rules/Min.php | 2 +- src/Validators/Rules/Regex.php | 3 ++- src/Validators/Rules/UsaMarketName.php | 2 +- tests/Blueprint/ValidatorTest.php | 2 +- 12 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Csv/CsvFile.php b/src/Csv/CsvFile.php index 10571795..473a485e 100644 --- a/src/Csv/CsvFile.php +++ b/src/Csv/CsvFile.php @@ -71,10 +71,10 @@ public function getRecords(): iterable return $this->reader->getRecords($this->getHeader()); } - // public function getRecordsChunk(int $offset = 0, int $limit = -1): \League\Csv\ResultSet - // { - // return Statement::create(null, $offset, $limit)->process($this->reader, $this->getHeader()); - // } + public function getRecordsChunk(int $offset = 0, int $limit = -1): \League\Csv\TabularDataReader + { + return Statement::create(null, $offset, $limit)->process($this->reader, $this->getHeader()); + } public function validate(bool $quickStop = false): ErrorSuite { diff --git a/src/Validators/Rules/IsDomain.php b/src/Validators/Rules/IsDomain.php index 0acb122b..88bea459 100644 --- a/src/Validators/Rules/IsDomain.php +++ b/src/Validators/Rules/IsDomain.php @@ -26,7 +26,7 @@ public function validateRule(?string $cellValue): ?string $domainPattern = '/^(?!-)[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})$/'; - if (\preg_match($domainPattern, (string)$cellValue) === false) { + if (\preg_match($domainPattern, (string)$cellValue) === 0) { return "Value \"{$cellValue}\" is not a valid domain"; } diff --git a/src/Validators/Rules/IsFloat.php b/src/Validators/Rules/IsFloat.php index a5d3c33a..74b61dea 100644 --- a/src/Validators/Rules/IsFloat.php +++ b/src/Validators/Rules/IsFloat.php @@ -24,7 +24,7 @@ public function validateRule(?string $cellValue): ?string return null; } - if (\preg_match('/^-?\d+(\.\d+)?$/', (string)$cellValue) === false) { + if (\preg_match('/^-?\d+(\.\d+)?$/', (string)$cellValue) === 0) { return "Value \"{$cellValue}\" is not a float number"; } diff --git a/src/Validators/Rules/IsInt.php b/src/Validators/Rules/IsInt.php index 2fe16a97..069fca8f 100644 --- a/src/Validators/Rules/IsInt.php +++ b/src/Validators/Rules/IsInt.php @@ -24,7 +24,7 @@ public function validateRule(?string $cellValue): ?string return null; } - if (\preg_match('/^-?\d+$/', (string)$cellValue) === false) { + if (\preg_match('/^-?\d+$/', (string)$cellValue) === 0) { return "Value \"{$cellValue}\" is not an integer"; } diff --git a/src/Validators/Rules/IsLatitude.php b/src/Validators/Rules/IsLatitude.php index 2fb40715..f3fc3db5 100644 --- a/src/Validators/Rules/IsLatitude.php +++ b/src/Validators/Rules/IsLatitude.php @@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string } $result = parent::validateRule($cellValue); - if ($result !== '') { + if ($result !== null) { return $result; } diff --git a/src/Validators/Rules/IsLongitude.php b/src/Validators/Rules/IsLongitude.php index aa785ca1..f9198c47 100644 --- a/src/Validators/Rules/IsLongitude.php +++ b/src/Validators/Rules/IsLongitude.php @@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string } $result = parent::validateRule($cellValue); - if ($result !== '') { + if ($result !== null) { return $result; } diff --git a/src/Validators/Rules/IsUuid4.php b/src/Validators/Rules/IsUuid4.php index fa755f4a..86a5b55b 100644 --- a/src/Validators/Rules/IsUuid4.php +++ b/src/Validators/Rules/IsUuid4.php @@ -26,7 +26,7 @@ public function validateRule(?string $cellValue): ?string $uuid4 = '/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89ABab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/'; - if (\preg_match($uuid4, (string)$cellValue) === false) { + if (\preg_match($uuid4, (string)$cellValue) === 0) { return 'Value is not a valid UUID v4'; } diff --git a/src/Validators/Rules/Max.php b/src/Validators/Rules/Max.php index 65349ce5..9ce9b0a8 100644 --- a/src/Validators/Rules/Max.php +++ b/src/Validators/Rules/Max.php @@ -21,7 +21,7 @@ final class Max extends IsFloat public function validateRule(?string $cellValue): ?string { $result = parent::validateRule($cellValue); - if ($result !== '') { + if ($result !== null) { return $result; } diff --git a/src/Validators/Rules/Min.php b/src/Validators/Rules/Min.php index 2285f964..06ec2e21 100644 --- a/src/Validators/Rules/Min.php +++ b/src/Validators/Rules/Min.php @@ -21,7 +21,7 @@ final class Min extends IsFloat public function validateRule(?string $cellValue): ?string { $result = parent::validateRule($cellValue); - if ($result !== '') { + if ($result !== null) { return $result; } diff --git a/src/Validators/Rules/Regex.php b/src/Validators/Rules/Regex.php index 563025c5..057abde1 100644 --- a/src/Validators/Rules/Regex.php +++ b/src/Validators/Rules/Regex.php @@ -23,7 +23,8 @@ final class Regex extends AbstarctRule public function validateRule(?string $cellValue): ?string { $regex = Utils::prepareRegex($this->getOptionAsString()); - if (\preg_match((string)$regex, (string)$cellValue) === false) { + + if (\preg_match((string)$regex, (string)$cellValue) === 0) { return "Value \"{$cellValue}\" does not match the pattern \"{$regex}\""; } diff --git a/src/Validators/Rules/UsaMarketName.php b/src/Validators/Rules/UsaMarketName.php index 206ec70b..d570cfcc 100644 --- a/src/Validators/Rules/UsaMarketName.php +++ b/src/Validators/Rules/UsaMarketName.php @@ -24,7 +24,7 @@ public function validateRule(?string $cellValue): ?string return null; } - if (\preg_match('/^[A-Za-z0-9\s-]+, [A-Z]{2}$/u', (string)$cellValue) === false) { + if (\preg_match('/^[A-Za-z0-9\s-]+, [A-Z]{2}$/u', (string)$cellValue) === 0) { return 'Invalid market name format for value "' . $cellValue . '". ' . 'Market name must have format "New York, NY"'; } diff --git a/tests/Blueprint/ValidatorTest.php b/tests/Blueprint/ValidatorTest.php index 74fecdbe..8846c892 100644 --- a/tests/Blueprint/ValidatorTest.php +++ b/tests/Blueprint/ValidatorTest.php @@ -38,7 +38,7 @@ protected function setUp(): void public function testUndefinedRule(): void { $this->expectExceptionMessage( - 'Rule "undefined_rule" not found. Expected class: JBZoo\CsvBlueprint\Validators\Rules\UndefinedRule', + 'Rule "undefined_rule" not found. Expected class: "JBZoo\CsvBlueprint\Validators\Rules\UndefinedRule"', ); $csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'undefined_rule', true)); $csv->validate();