Skip to content

Commit

Permalink
Merge pull request #447 from cakephp/fix-exception-messages
Browse files Browse the repository at this point in the history
Improve exception messages
  • Loading branch information
markstory authored Nov 3, 2023
2 parents 9cb035a + 1b0ec6d commit 7dbd05d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public function modify(string $modifier): static
{
$new = parent::modify($modifier);
if ($new === false) {
throw new InvalidArgumentException('Unable to modify date using: ' . $modifier);
throw new InvalidArgumentException(sprintf('Unable to modify date using `%s`', $modifier));
}

return $new;
Expand Down Expand Up @@ -2665,15 +2665,15 @@ public function __get(string $name): string|float|int|bool|DateTimeZone
return $this->getTimezone()->getName();

default:
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name));
}
}

/**
* Check if an attribute exists on the object
*
* @param string $name The property name to check.
* @return bool Whether or not the property exists.
* @return bool Whether the property exists.
*/
public function __isset(string $name): bool
{
Expand Down
6 changes: 3 additions & 3 deletions src/ChronosDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function modify(string $modifier): static
$new = clone $this;
$new->native = $new->native->modify($modifier);
if ($new->native === false) {
throw new InvalidArgumentException('Unable to modify date using: ' . $modifier);
throw new InvalidArgumentException(sprintf('Unable to modify date using `%s`', $modifier));
}

if ($new->format('H:i:s') !== '00:00:00') {
Expand Down Expand Up @@ -1647,15 +1647,15 @@ public function __get(string $name): string|float|int|bool
return $this->month <= 6 ? 1 : 2;

default:
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name));
}
}

/**
* Check if an attribute exists on the object
*
* @param string $name The property name to check.
* @return bool Whether or not the property exists.
* @return bool Whether the property exists.
*/
public function __isset(string $name): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/ChronosTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected static function parseString(string $time): int
{
if (!preg_match('/^\s*(\d{1,2})[:.](\d{1,2})(?|[:.](\d{1,2})[.](\d+)|[:.](\d{1,2}))?\s*$/', $time, $matches)) {
throw new InvalidArgumentException(
'Time string is not in expected format: "HH[:.]mm" or "HH[:.]mm[:.]ss.u".'
sprintf('Time string `%s` is not in expected format `HH[:.]mm` or `HH[:.]mm[:.]ss.u`.', $time)
);
}

Expand All @@ -130,7 +130,7 @@ protected static function parseString(string $time): int
$microseconds = (int)substr($matches[4] ?? '', 0, 6);

if ($hours > 24 || $minutes > 59 || $seconds > 59 || $microseconds > 999_999) {
throw new InvalidArgumentException('Time string contains invalid values.');
throw new InvalidArgumentException(sprintf('Time string `%s` contains invalid values.', $time));
}

$ticks = $hours * self::TICKS_PER_HOUR;
Expand Down
2 changes: 1 addition & 1 deletion src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Translator
* Check if a translation key exists.
*
* @param string $key The key to check.
* @return bool Whether or not the key exists.
* @return bool Whether the key exists.
*/
public function exists(string $key): bool
{
Expand Down

0 comments on commit 7dbd05d

Please sign in to comment.