generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61a4f7d
commit b389732
Showing
19 changed files
with
474 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Duration | ||
{ | ||
private function __construct( | ||
private readonly int $seconds, | ||
private readonly int $nanoseconds, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidNanoseconds | ||
* @throws Exception\InvalidSeconds | ||
*/ | ||
public static function fromSecondsAndNanoseconds( | ||
int $seconds, | ||
int $nanoseconds, | ||
): self { | ||
if (0 > $seconds) { | ||
throw Exception\InvalidSeconds::notGreaterThanZero($seconds); | ||
} | ||
|
||
if (0 > $nanoseconds) { | ||
throw Exception\InvalidNanoseconds::notGreaterThanZero($nanoseconds); | ||
} | ||
|
||
$maxNanoseconds = 999_999_999; | ||
|
||
if ($nanoseconds > $maxNanoseconds) { | ||
throw Exception\InvalidNanoseconds::notLessThanOrEqualTo999999999($nanoseconds); | ||
} | ||
|
||
return new self( | ||
$seconds, | ||
$nanoseconds, | ||
); | ||
} | ||
|
||
public function seconds(): int | ||
{ | ||
return $this->seconds; | ||
} | ||
|
||
public function nanoseconds(): int | ||
{ | ||
return $this->nanoseconds; | ||
} | ||
|
||
public function isLessThan(self $other): bool | ||
{ | ||
if ($this->seconds < $other->seconds) { | ||
return true; | ||
} | ||
|
||
if ($this->seconds > $other->seconds) { | ||
return false; | ||
} | ||
|
||
return $this->nanoseconds < $other->nanoseconds; | ||
} | ||
|
||
public function isGreaterThan(self $other): bool | ||
{ | ||
if ($this->seconds > $other->seconds) { | ||
return true; | ||
} | ||
|
||
if ($this->seconds < $other->seconds) { | ||
return false; | ||
} | ||
|
||
return $this->nanoseconds > $other->nanoseconds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidNanoseconds extends \InvalidArgumentException | ||
{ | ||
public static function notGreaterThanZero(int $value): self | ||
{ | ||
return new self(\sprintf( | ||
'Value should be greater than 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
public static function notLessThanOrEqualTo999999999(int $value): self | ||
{ | ||
return new self(\sprintf( | ||
'Value should be less than or equal to 999999999, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidSeconds extends \InvalidArgumentException | ||
{ | ||
public static function notGreaterThanZero(int $value): self | ||
{ | ||
return new self(\sprintf( | ||
'Value should be greater than 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.