Skip to content

Commit

Permalink
chore: Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshomoh committed Oct 27, 2023
1 parent edc022c commit 3026b20
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
8 changes: 2 additions & 6 deletions src/Helpers/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ protected function ruleToLower(string $rule): ?string

$lowerRule = strtolower($lowerRule);

$lowerRule = ltrim($lowerRule, '_');

return $lowerRule;
return ltrim($lowerRule, '_');
}

/**
Expand Down Expand Up @@ -90,9 +88,7 @@ protected function makeReplacements(

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

$message = $this->replaceErrorLinePlaceholder($message, $lineNumber);

return $message;
return $this->replaceErrorLinePlaceholder($message, $lineNumber);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/AsciiOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AsciiOnly implements ValidationRuleInterface
*/
public function passes($value, array $parameters): bool
{
return (mb_detect_encoding($value, 'ASCII', true)) ? true : false;
return (bool)mb_detect_encoding($value, 'ASCII', true);
}

/**
Expand Down
14 changes: 11 additions & 3 deletions src/Rules/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ public function allowedParameters(): array
*/
public function passes($value, array $parameters): bool
{
$size = (int) $value;

list($min, $max) = $parameters;

return $size >= (int) $min && $size <= (int) $max;
if (is_numeric($value)) {
$convertedValue = +$value;
return $convertedValue >= +$min && $convertedValue <= +$max;
}

if (is_string($value)) {
$valueLength = strlen($value);
return $valueLength >= +$min && $valueLength <= +$max;
}

return false;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Rules/ClosureValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public function __construct(\Closure $callback)
*/
public function passes($value, array $parameters): bool
{
$this->failed = false;

$this->callback->__invoke($value, function ($message) {
$this->failed = true;

Expand Down
3 changes: 2 additions & 1 deletion src/Validator/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Oshomo\CsvUtils\Validator;

use Closure;
use Oshomo\CsvUtils\Contracts\ValidationRuleInterface;
use Oshomo\CsvUtils\Contracts\ValidationRuleInterface as ValidationRule;
use Oshomo\CsvUtils\Rules\ClosureValidationRule;

Expand All @@ -13,7 +14,7 @@ class ValidationRuleParser
/**
* Extract the rule name and parameters from a rule.
*
* @param string $rule|ValidationRuleInterface
* @param string|ValidationRuleInterface $rule
*/
public static function parse($rule): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CsvValidatorParserTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Oshomo\CsvUtils\Validator;
namespace Oshomo\CsvUtils\Tests\src;

use Oshomo\CsvUtils\Tests\src\UppercaseRule;
use Oshomo\CsvUtils\Validator\ValidationRuleParser;
use PHPUnit\Framework\TestCase;

class CsvValidatorParserTest extends TestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CsvValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Oshomo\CsvUtils\Validator;
namespace Oshomo\CsvUtils\Tests\src;

use Oshomo\CsvUtils\Converter\JsonConverter;
use Oshomo\CsvUtils\Converter\XmlConverter;
use Oshomo\CsvUtils\Tests\src\UppercaseRule;
use Oshomo\CsvUtils\Validator\Validator;
use PHPUnit\Framework\TestCase;

class CsvValidatorTest extends TestCase
Expand Down

0 comments on commit 3026b20

Please sign in to comment.