-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Fix mutation coverage #485
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,8 @@ | |
}, | ||
"DecrementInteger": { | ||
"ignore": [ | ||
"Psl\\DataStructure\\PriorityQueue::peek" | ||
"Psl\\DataStructure\\PriorityQueue::peek", | ||
"Psl\\DateTime\\TemporalConvenienceMethodsTrait::since" | ||
] | ||
}, | ||
"FunctionCallRemoval": { | ||
|
@@ -42,7 +43,8 @@ | |
}, | ||
"IncrementInteger": { | ||
"ignore": [ | ||
"Psl\\DataStructure\\PriorityQueue::peek" | ||
"Psl\\DataStructure\\PriorityQueue::peek", | ||
"Psl\\DateTime\\TemporalConvenienceMethodsTrait::since" | ||
] | ||
}, | ||
"LogicalNot": { | ||
|
@@ -58,6 +60,7 @@ | |
}, | ||
"Throw_": { | ||
"ignore": [ | ||
"Psl\\DateTime\\DateTime::__construct", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> It's impossible to test the InvalidArgumentExceptions that are being thrown. I'm wondering if it would make more sense to use the same checks from The constructor does a range check, the fromParts does a calendar (intl) check. Would it make sense to always go for the fromParts() checks instead? |
||
"Psl\\File\\ReadHandle::__construct", | ||
"Psl\\File\\WriteHandle::__construct", | ||
"Psl\\File\\ReadWriteHandle::__construct", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,15 +398,15 @@ public function plusMonths(int $months): static | |
return $this; | ||
} | ||
|
||
if (0 > $months) { | ||
if ($months < 1) { | ||
return $this->minusMonths(-$months); | ||
} | ||
|
||
$plus_years = Math\div($months, MONTHS_PER_YEAR); | ||
$months_left = $months - ($plus_years * MONTHS_PER_YEAR); | ||
$target_month = $this->getMonth() + $months_left; | ||
|
||
if ($target_month > 12) { | ||
if ($target_month > MONTHS_PER_YEAR) { | ||
$plus_years++; | ||
$target_month = $target_month - MONTHS_PER_YEAR; | ||
} | ||
|
@@ -438,7 +438,7 @@ public function minusMonths(int $months): static | |
return $this; | ||
} | ||
|
||
if (0 > $months) { | ||
if ($months < 1) { | ||
return $this->plusMonths(-$months); | ||
} | ||
|
||
|
@@ -616,10 +616,9 @@ public function toString(null|DateStyle $date_style = null, null|TimeStyle $time | |
$timestamp = $this->getTimestamp(); | ||
|
||
/** | ||
* @psalm-suppress InvalidOperand | ||
* @psalm-suppress ImpureMethodCall | ||
*/ | ||
return Internal\create_intl_date_formatter($date_style, $time_style, null, $timezone ?? $this->getTimezone(), $locale) | ||
->format($timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND)); | ||
->format($timestamp->getSeconds()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the default pattern does not represent nanoseconds. I did not find a case to cover this calculation |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,27 +674,24 @@ public function toString(int $max_decimals = 3): string | |
$sec_sign = $this->seconds < 0 || $this->nanoseconds < 0 ? '-' : ''; | ||
$sec = Math\abs($this->seconds); | ||
|
||
/** @var list<array{string, string}> $values */ | ||
$values = [ | ||
[((string) $this->hours), 'hour(s)'], | ||
[((string) $this->minutes), 'minute(s)'], | ||
[$sec_sign . ((string) $sec) . $decimal_part, 'second(s)'], | ||
]; | ||
|
||
// $end is the sizeof($values), use static value for better performance. | ||
$end = 3; | ||
while ($end > 0 && $values[$end - 1][0] === '0') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mutating the while's results in timeouts. I decided to go for a couple of simple if statements instead that results in the same behaviour. |
||
--$end; | ||
$containsHours = $this->hours !== 0; | ||
$containsMinutes = $this->minutes !== 0; | ||
$concatenatedSeconds = $sec_sign . ((string) $sec) . $decimal_part; | ||
$containsSeconds = $concatenatedSeconds !== '0'; | ||
|
||
/** @var list<string> $output */ | ||
$output = []; | ||
if ($containsHours) { | ||
$output[] = ((string) $this->hours) . ' hour(s)'; | ||
} | ||
|
||
$start = 0; | ||
while ($start < $end && $values[$start][0] === '0') { | ||
++$start; | ||
if ($containsMinutes || ($containsHours && $containsSeconds)) { | ||
$output[] = ((string) $this->minutes) . ' minute(s)'; | ||
} | ||
|
||
$output = []; | ||
for ($i = $start; $i < $end; ++$i) { | ||
$output[] = $values[$i][0] . ' ' . $values[$i][1]; | ||
if ($containsSeconds) { | ||
$output[] = $concatenatedSeconds . ' second(s)'; | ||
} | ||
|
||
return ([] === $output) ? '0 second(s)' : Str\join($output, ', '); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> Altering since() causes timeouts in the async component.