Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception messages #447

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{
$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));

Check warning on line 939 in src/Chronos.php

View check run for this annotation

Codecov / codecov/patch

src/Chronos.php#L939

Added line #L939 was not covered by tests
}

return $new;
Expand Down Expand Up @@ -2665,15 +2665,15 @@
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 @@
$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));

Check warning on line 359 in src/ChronosDate.php

View check run for this annotation

Codecov / codecov/patch

src/ChronosDate.php#L359

Added line #L359 was not covered by tests
}

if ($new->format('H:i:s') !== '00:00:00') {
Expand Down Expand Up @@ -1647,15 +1647,15 @@
return $this->month <= 6 ? 1 : 2;

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

Check warning on line 1650 in src/ChronosDate.php

View check run for this annotation

Codecov / codecov/patch

src/ChronosDate.php#L1650

Added line #L1650 was not covered by tests
}
}

/**
* 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