Skip to content

Commit 3026b20

Browse files
committed
chore: Fixed failing tests
1 parent edc022c commit 3026b20

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

src/Helpers/FormatsMessages.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ protected function ruleToLower(string $rule): ?string
6060

6161
$lowerRule = strtolower($lowerRule);
6262

63-
$lowerRule = ltrim($lowerRule, '_');
64-
65-
return $lowerRule;
63+
return ltrim($lowerRule, '_');
6664
}
6765

6866
/**
@@ -90,9 +88,7 @@ protected function makeReplacements(
9088

9189
$message = $this->replaceValuePlaceholder($message, $value);
9290

93-
$message = $this->replaceErrorLinePlaceholder($message, $lineNumber);
94-
95-
return $message;
91+
return $this->replaceErrorLinePlaceholder($message, $lineNumber);
9692
}
9793

9894
/**

src/Rules/AsciiOnly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AsciiOnly implements ValidationRuleInterface
1515
*/
1616
public function passes($value, array $parameters): bool
1717
{
18-
return (mb_detect_encoding($value, 'ASCII', true)) ? true : false;
18+
return (bool)mb_detect_encoding($value, 'ASCII', true);
1919
}
2020

2121
/**

src/Rules/Between.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ public function allowedParameters(): array
2121
*/
2222
public function passes($value, array $parameters): bool
2323
{
24-
$size = (int) $value;
25-
2624
list($min, $max) = $parameters;
2725

28-
return $size >= (int) $min && $size <= (int) $max;
26+
if (is_numeric($value)) {
27+
$convertedValue = +$value;
28+
return $convertedValue >= +$min && $convertedValue <= +$max;
29+
}
30+
31+
if (is_string($value)) {
32+
$valueLength = strlen($value);
33+
return $valueLength >= +$min && $valueLength <= +$max;
34+
}
35+
36+
return false;
2937
}
3038

3139
/**

src/Rules/ClosureValidationRule.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public function __construct(\Closure $callback)
4444
*/
4545
public function passes($value, array $parameters): bool
4646
{
47-
$this->failed = false;
48-
4947
$this->callback->__invoke($value, function ($message) {
5048
$this->failed = true;
5149

src/Validator/ValidationRuleParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Oshomo\CsvUtils\Validator;
66

77
use Closure;
8+
use Oshomo\CsvUtils\Contracts\ValidationRuleInterface;
89
use Oshomo\CsvUtils\Contracts\ValidationRuleInterface as ValidationRule;
910
use Oshomo\CsvUtils\Rules\ClosureValidationRule;
1011

@@ -13,7 +14,7 @@ class ValidationRuleParser
1314
/**
1415
* Extract the rule name and parameters from a rule.
1516
*
16-
* @param string $rule|ValidationRuleInterface
17+
* @param string|ValidationRuleInterface $rule
1718
*/
1819
public static function parse($rule): array
1920
{

tests/src/CsvValidatorParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Oshomo\CsvUtils\Validator;
3+
namespace Oshomo\CsvUtils\Tests\src;
44

5-
use Oshomo\CsvUtils\Tests\src\UppercaseRule;
5+
use Oshomo\CsvUtils\Validator\ValidationRuleParser;
66
use PHPUnit\Framework\TestCase;
77

88
class CsvValidatorParserTest extends TestCase

tests/src/CsvValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Oshomo\CsvUtils\Validator;
3+
namespace Oshomo\CsvUtils\Tests\src;
44

55
use Oshomo\CsvUtils\Converter\JsonConverter;
66
use Oshomo\CsvUtils\Converter\XmlConverter;
7-
use Oshomo\CsvUtils\Tests\src\UppercaseRule;
7+
use Oshomo\CsvUtils\Validator\Validator;
88
use PHPUnit\Framework\TestCase;
99

1010
class CsvValidatorTest extends TestCase

0 commit comments

Comments
 (0)