Skip to content

Commit

Permalink
throw ValueError instead on InvalidArgumentException
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Jan 16, 2024
1 parent b8b3a80 commit 8f9b88e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* `stubbles\input\broker\param\ParamBroker::procureParam()`
* `stubbles\input\broker\param\CustomDatespanParamBroker::procureParam()`
* `stubbles\input\broker\param\ultipleSourceParamBroker::procureParam()`
* `stubbles\input\filter\range\StringLength::truncate()` now throws an `\ValueError` instead of an `\InvalidArgumentException`

## 8.0.2 (2019-12-16)

Expand Down
10 changes: 5 additions & 5 deletions src/main/php/filter/range/StringLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
namespace stubbles\input\filter\range;

use InvalidArgumentException;
use LogicException;
use stubbles\values\Secret;
use ValueError;

/**
* String length limitation.
*
Expand All @@ -30,13 +30,13 @@ public function __construct(
* create instance which treats above max border not as error, but will lead
* to a truncated value only
*
* @throws InvalidArgumentException
* @throws ValueError when $maxLength smaller than 1
* @since 2.3.1
*/
public static function truncate(?int $minLength, ?int $maxLength = null)
public static function truncate(?int $minLength, int $maxLength)
{
if (0 >= $maxLength) {
throw new InvalidArgumentException(
throw new ValueError(
'Max length must be greater than 0, otherwise truncation doesn\'t make sense'
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/filter/range/StringLengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use ValueError;

use function bovigo\assert\assertThat;
use function bovigo\assert\assertEmptyArray;
Expand Down Expand Up @@ -182,7 +183,7 @@ public function createWithTruncateAndZeroMaxLengthThrowsIllegalArgumentException
int $maxLength
): void {
expect(fn() => StringLength::truncate(50, $maxLength))
->throws(InvalidArgumentException::class);
->throws(ValueError::class);
}

/**
Expand Down

0 comments on commit 8f9b88e

Please sign in to comment.