@@ -22,37 +22,37 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | final class CommandRegistry |
| 24 | 24 | { |
| 25 | - private Application $application; |
|
| 26 | - |
|
| 27 | - public function __construct(Application $application) |
|
| 28 | - { |
|
| 29 | - $this->application = $application; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Returns a registered command by name or alias. |
|
| 34 | - * |
|
| 35 | - * @throws CommandNotFoundException When given command name does not exist |
|
| 36 | - */ |
|
| 37 | - public function getCommand(string $name): Command |
|
| 38 | - { |
|
| 39 | - return new ReversedSymfonyCommand( |
|
| 40 | - $this->application->get($name), |
|
| 41 | - ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Finds a command by name or alias. |
|
| 46 | - * |
|
| 47 | - * Contrary to get, this command tries to find the best |
|
| 48 | - * match if you give it an abbreviation of a name or alias. |
|
| 49 | - * |
|
| 50 | - * @throws CommandNotFoundException When command name is incorrect or ambiguous |
|
| 51 | - */ |
|
| 52 | - public function findCommand(string $name): Command |
|
| 53 | - { |
|
| 54 | - return new ReversedSymfonyCommand( |
|
| 55 | - $this->application->find($name), |
|
| 56 | - ); |
|
| 57 | - } |
|
| 25 | + private Application $application; |
|
| 26 | + |
|
| 27 | + public function __construct(Application $application) |
|
| 28 | + { |
|
| 29 | + $this->application = $application; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Returns a registered command by name or alias. |
|
| 34 | + * |
|
| 35 | + * @throws CommandNotFoundException When given command name does not exist |
|
| 36 | + */ |
|
| 37 | + public function getCommand(string $name): Command |
|
| 38 | + { |
|
| 39 | + return new ReversedSymfonyCommand( |
|
| 40 | + $this->application->get($name), |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Finds a command by name or alias. |
|
| 46 | + * |
|
| 47 | + * Contrary to get, this command tries to find the best |
|
| 48 | + * match if you give it an abbreviation of a name or alias. |
|
| 49 | + * |
|
| 50 | + * @throws CommandNotFoundException When command name is incorrect or ambiguous |
|
| 51 | + */ |
|
| 52 | + public function findCommand(string $name): Command |
|
| 53 | + { |
|
| 54 | + return new ReversedSymfonyCommand( |
|
| 55 | + $this->application->find($name), |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | * Utility class which allows to easily access to the known commands of a given |
| 21 | 21 | * application. |
| 22 | 22 | */ |
| 23 | -final class CommandRegistry |
|
| 24 | -{ |
|
| 23 | +final class CommandRegistry { |
|
| 25 | 24 | private Application $application; |
| 26 | 25 | |
| 27 | 26 | public function __construct(Application $application) |
@@ -9,28 +9,28 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface ContainerInterface |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Finds an entry of the container by its identifier and returns it. |
|
| 14 | - * |
|
| 15 | - * @param string $id Identifier of the entry to look for. |
|
| 16 | - * |
|
| 17 | - * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
|
| 18 | - * @throws ContainerExceptionInterface Error while retrieving the entry. |
|
| 19 | - * |
|
| 20 | - * @return mixed Entry. |
|
| 21 | - */ |
|
| 22 | - public function get(string $id); |
|
| 12 | + /** |
|
| 13 | + * Finds an entry of the container by its identifier and returns it. |
|
| 14 | + * |
|
| 15 | + * @param string $id Identifier of the entry to look for. |
|
| 16 | + * |
|
| 17 | + * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
|
| 18 | + * @throws ContainerExceptionInterface Error while retrieving the entry. |
|
| 19 | + * |
|
| 20 | + * @return mixed Entry. |
|
| 21 | + */ |
|
| 22 | + public function get(string $id); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Returns true if the container can return an entry for the given identifier. |
|
| 26 | - * Returns false otherwise. |
|
| 27 | - * |
|
| 28 | - * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
|
| 29 | - * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
|
| 30 | - * |
|
| 31 | - * @param string $id Identifier of the entry to look for. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function has(string $id); |
|
| 24 | + /** |
|
| 25 | + * Returns true if the container can return an entry for the given identifier. |
|
| 26 | + * Returns false otherwise. |
|
| 27 | + * |
|
| 28 | + * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
|
| 29 | + * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
|
| 30 | + * |
|
| 31 | + * @param string $id Identifier of the entry to look for. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function has(string $id); |
|
| 36 | 36 | } |
@@ -6,8 +6,7 @@ |
||
| 6 | 6 | /** |
| 7 | 7 | * Describes the interface of a container that exposes methods to read its entries. |
| 8 | 8 | */ |
| 9 | -interface ContainerInterface |
|
| 10 | -{ |
|
| 9 | +interface ContainerInterface { |
|
| 11 | 10 | /** |
| 12 | 11 | * Finds an entry of the container by its identifier and returns it. |
| 13 | 12 | * |
@@ -10,72 +10,72 @@ |
||
| 10 | 10 | /** this class implements a safe version of the Datetime class */ |
| 11 | 11 | class DateTime extends \DateTime |
| 12 | 12 | { |
| 13 | - //switch from regular datetime to safe version |
|
| 14 | - private static function createFromRegular(\DateTime $datetime): self |
|
| 15 | - { |
|
| 16 | - return new self($datetime->format('Y-m-d H:i:s.u'), $datetime->getTimezone()); |
|
| 17 | - } |
|
| 13 | + //switch from regular datetime to safe version |
|
| 14 | + private static function createFromRegular(\DateTime $datetime): self |
|
| 15 | + { |
|
| 16 | + return new self($datetime->format('Y-m-d H:i:s.u'), $datetime->getTimezone()); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $format |
|
| 21 | - * @param string $time |
|
| 22 | - * @param DateTimeZone|null $timezone |
|
| 23 | - * @throws DatetimeException |
|
| 24 | - */ |
|
| 25 | - public static function createFromFormat($format, $time, $timezone = null): self |
|
| 26 | - { |
|
| 27 | - $datetime = parent::createFromFormat($format, $time, $timezone); |
|
| 28 | - if ($datetime === false) { |
|
| 29 | - throw DatetimeException::createFromPhpError(); |
|
| 30 | - } |
|
| 31 | - return self::createFromRegular($datetime); |
|
| 32 | - } |
|
| 19 | + /** |
|
| 20 | + * @param string $format |
|
| 21 | + * @param string $time |
|
| 22 | + * @param DateTimeZone|null $timezone |
|
| 23 | + * @throws DatetimeException |
|
| 24 | + */ |
|
| 25 | + public static function createFromFormat($format, $time, $timezone = null): self |
|
| 26 | + { |
|
| 27 | + $datetime = parent::createFromFormat($format, $time, $timezone); |
|
| 28 | + if ($datetime === false) { |
|
| 29 | + throw DatetimeException::createFromPhpError(); |
|
| 30 | + } |
|
| 31 | + return self::createFromRegular($datetime); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param DateTimeInterface $datetime2 The date to compare to. |
|
| 36 | - * @param boolean $absolute [optional] Whether to return absolute difference. |
|
| 37 | - * @return DateInterval The DateInterval object representing the difference between the two dates. |
|
| 38 | - * @throws DatetimeException |
|
| 39 | - */ |
|
| 40 | - public function diff($datetime2, $absolute = false): DateInterval |
|
| 41 | - { |
|
| 42 | - /** @var \DateInterval|false $result */ |
|
| 43 | - $result = parent::diff($datetime2, $absolute); |
|
| 44 | - if ($result === false) { |
|
| 45 | - throw DatetimeException::createFromPhpError(); |
|
| 46 | - } |
|
| 47 | - return $result; |
|
| 48 | - } |
|
| 34 | + /** |
|
| 35 | + * @param DateTimeInterface $datetime2 The date to compare to. |
|
| 36 | + * @param boolean $absolute [optional] Whether to return absolute difference. |
|
| 37 | + * @return DateInterval The DateInterval object representing the difference between the two dates. |
|
| 38 | + * @throws DatetimeException |
|
| 39 | + */ |
|
| 40 | + public function diff($datetime2, $absolute = false): DateInterval |
|
| 41 | + { |
|
| 42 | + /** @var \DateInterval|false $result */ |
|
| 43 | + $result = parent::diff($datetime2, $absolute); |
|
| 44 | + if ($result === false) { |
|
| 45 | + throw DatetimeException::createFromPhpError(); |
|
| 46 | + } |
|
| 47 | + return $result; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $modify A date/time string. Valid formats are explained in <a href="https://secure.php.net/manual/en/datetime.formats.php">Date and Time Formats</a>. |
|
| 52 | - * @return DateTime Returns the DateTime object for method chaining. |
|
| 53 | - * @throws DatetimeException |
|
| 54 | - */ |
|
| 55 | - public function modify($modify): self |
|
| 56 | - { |
|
| 57 | - /** @var DateTime|false $result */ |
|
| 58 | - $result = parent::modify($modify); |
|
| 59 | - if ($result === false) { |
|
| 60 | - throw DatetimeException::createFromPhpError(); |
|
| 61 | - } |
|
| 62 | - return $result; |
|
| 63 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $modify A date/time string. Valid formats are explained in <a href="https://secure.php.net/manual/en/datetime.formats.php">Date and Time Formats</a>. |
|
| 52 | + * @return DateTime Returns the DateTime object for method chaining. |
|
| 53 | + * @throws DatetimeException |
|
| 54 | + */ |
|
| 55 | + public function modify($modify): self |
|
| 56 | + { |
|
| 57 | + /** @var DateTime|false $result */ |
|
| 58 | + $result = parent::modify($modify); |
|
| 59 | + if ($result === false) { |
|
| 60 | + throw DatetimeException::createFromPhpError(); |
|
| 61 | + } |
|
| 62 | + return $result; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param int $year |
|
| 67 | - * @param int $month |
|
| 68 | - * @param int $day |
|
| 69 | - * @return DateTime |
|
| 70 | - * @throws DatetimeException |
|
| 71 | - */ |
|
| 72 | - public function setDate($year, $month, $day): self |
|
| 73 | - { |
|
| 74 | - /** @var DateTime|false $result */ |
|
| 75 | - $result = parent::setDate($year, $month, $day); |
|
| 76 | - if ($result === false) { |
|
| 77 | - throw DatetimeException::createFromPhpError(); |
|
| 78 | - } |
|
| 79 | - return $result; |
|
| 80 | - } |
|
| 65 | + /** |
|
| 66 | + * @param int $year |
|
| 67 | + * @param int $month |
|
| 68 | + * @param int $day |
|
| 69 | + * @return DateTime |
|
| 70 | + * @throws DatetimeException |
|
| 71 | + */ |
|
| 72 | + public function setDate($year, $month, $day): self |
|
| 73 | + { |
|
| 74 | + /** @var DateTime|false $result */ |
|
| 75 | + $result = parent::setDate($year, $month, $day); |
|
| 76 | + if ($result === false) { |
|
| 77 | + throw DatetimeException::createFromPhpError(); |
|
| 78 | + } |
|
| 79 | + return $result; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -15,248 +15,248 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class DateTimeImmutable extends \DateTimeImmutable |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var \DateTimeImmutable |
|
| 20 | - */ |
|
| 21 | - private $innerDateTime; |
|
| 18 | + /** |
|
| 19 | + * @var \DateTimeImmutable |
|
| 20 | + */ |
|
| 21 | + private $innerDateTime; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * DateTimeImmutable constructor. |
|
| 25 | - * @param string $time |
|
| 26 | - * @param DateTimeZone|null $timezone |
|
| 27 | - * @throws \Exception |
|
| 28 | - */ |
|
| 29 | - public function __construct($time = 'now', $timezone = null) |
|
| 30 | - { |
|
| 31 | - parent::__construct($time, $timezone); |
|
| 32 | - $this->innerDateTime = new parent($time, $timezone); |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * DateTimeImmutable constructor. |
|
| 25 | + * @param string $time |
|
| 26 | + * @param DateTimeZone|null $timezone |
|
| 27 | + * @throws \Exception |
|
| 28 | + */ |
|
| 29 | + public function __construct($time = 'now', $timezone = null) |
|
| 30 | + { |
|
| 31 | + parent::__construct($time, $timezone); |
|
| 32 | + $this->innerDateTime = new parent($time, $timezone); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - //switch between regular datetime and safe version |
|
| 36 | - public static function createFromRegular(\DateTimeImmutable $datetime): self |
|
| 37 | - { |
|
| 38 | - $safeDatetime = new self($datetime->format('Y-m-d H:i:s.u'), $datetime->getTimezone()); //we need to also update the wrapper to not break the operators '<' and '>' |
|
| 39 | - $safeDatetime->innerDateTime = $datetime; //to make sure we don't lose information because of the format(). |
|
| 40 | - return $safeDatetime; |
|
| 41 | - } |
|
| 35 | + //switch between regular datetime and safe version |
|
| 36 | + public static function createFromRegular(\DateTimeImmutable $datetime): self |
|
| 37 | + { |
|
| 38 | + $safeDatetime = new self($datetime->format('Y-m-d H:i:s.u'), $datetime->getTimezone()); //we need to also update the wrapper to not break the operators '<' and '>' |
|
| 39 | + $safeDatetime->innerDateTime = $datetime; //to make sure we don't lose information because of the format(). |
|
| 40 | + return $safeDatetime; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - //usefull if you need to switch back to regular DateTimeImmutable (for example when using DatePeriod) |
|
| 44 | - public function getInnerDateTime(): \DateTimeImmutable |
|
| 45 | - { |
|
| 46 | - return $this->innerDateTime; |
|
| 47 | - } |
|
| 43 | + //usefull if you need to switch back to regular DateTimeImmutable (for example when using DatePeriod) |
|
| 44 | + public function getInnerDateTime(): \DateTimeImmutable |
|
| 45 | + { |
|
| 46 | + return $this->innerDateTime; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - ///////////////////////////////////////////////////////////////////////////// |
|
| 50 | - // overload functions with false errors |
|
| 49 | + ///////////////////////////////////////////////////////////////////////////// |
|
| 50 | + // overload functions with false errors |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $format |
|
| 54 | - * @param string $time |
|
| 55 | - * @param DateTimeZone|null $timezone |
|
| 56 | - * @throws DatetimeException |
|
| 57 | - */ |
|
| 58 | - public static function createFromFormat($format, $time, $timezone = null): self |
|
| 59 | - { |
|
| 60 | - $datetime = parent::createFromFormat($format, $time, $timezone); |
|
| 61 | - if ($datetime === false) { |
|
| 62 | - throw DatetimeException::createFromPhpError(); |
|
| 63 | - } |
|
| 64 | - return self::createFromRegular($datetime); |
|
| 65 | - } |
|
| 52 | + /** |
|
| 53 | + * @param string $format |
|
| 54 | + * @param string $time |
|
| 55 | + * @param DateTimeZone|null $timezone |
|
| 56 | + * @throws DatetimeException |
|
| 57 | + */ |
|
| 58 | + public static function createFromFormat($format, $time, $timezone = null): self |
|
| 59 | + { |
|
| 60 | + $datetime = parent::createFromFormat($format, $time, $timezone); |
|
| 61 | + if ($datetime === false) { |
|
| 62 | + throw DatetimeException::createFromPhpError(); |
|
| 63 | + } |
|
| 64 | + return self::createFromRegular($datetime); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param string $format |
|
| 69 | - * @return string |
|
| 70 | - * @throws DatetimeException |
|
| 71 | - */ |
|
| 72 | - public function format($format): string |
|
| 73 | - { |
|
| 74 | - /** @var string|false $result */ |
|
| 75 | - $result = $this->innerDateTime->format($format); |
|
| 76 | - if ($result === false) { |
|
| 77 | - throw DatetimeException::createFromPhpError(); |
|
| 78 | - } |
|
| 79 | - return $result; |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * @param string $format |
|
| 69 | + * @return string |
|
| 70 | + * @throws DatetimeException |
|
| 71 | + */ |
|
| 72 | + public function format($format): string |
|
| 73 | + { |
|
| 74 | + /** @var string|false $result */ |
|
| 75 | + $result = $this->innerDateTime->format($format); |
|
| 76 | + if ($result === false) { |
|
| 77 | + throw DatetimeException::createFromPhpError(); |
|
| 78 | + } |
|
| 79 | + return $result; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @param DateTimeInterface $datetime2 |
|
| 84 | - * @param bool $absolute |
|
| 85 | - * @return DateInterval |
|
| 86 | - * @throws DatetimeException |
|
| 87 | - */ |
|
| 88 | - public function diff($datetime2, $absolute = false): DateInterval |
|
| 89 | - { |
|
| 90 | - /** @var \DateInterval|false $result */ |
|
| 91 | - $result = $this->innerDateTime->diff($datetime2, $absolute); |
|
| 92 | - if ($result === false) { |
|
| 93 | - throw DatetimeException::createFromPhpError(); |
|
| 94 | - } |
|
| 95 | - return $result; |
|
| 96 | - } |
|
| 82 | + /** |
|
| 83 | + * @param DateTimeInterface $datetime2 |
|
| 84 | + * @param bool $absolute |
|
| 85 | + * @return DateInterval |
|
| 86 | + * @throws DatetimeException |
|
| 87 | + */ |
|
| 88 | + public function diff($datetime2, $absolute = false): DateInterval |
|
| 89 | + { |
|
| 90 | + /** @var \DateInterval|false $result */ |
|
| 91 | + $result = $this->innerDateTime->diff($datetime2, $absolute); |
|
| 92 | + if ($result === false) { |
|
| 93 | + throw DatetimeException::createFromPhpError(); |
|
| 94 | + } |
|
| 95 | + return $result; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @param string $modify |
|
| 100 | - * @return DateTimeImmutable |
|
| 101 | - * @throws DatetimeException |
|
| 102 | - */ |
|
| 103 | - public function modify($modify): self |
|
| 104 | - { |
|
| 105 | - /** @var \DateTimeImmutable|false $result */ |
|
| 106 | - $result = $this->innerDateTime->modify($modify); |
|
| 107 | - if ($result === false) { |
|
| 108 | - throw DatetimeException::createFromPhpError(); |
|
| 109 | - } |
|
| 110 | - return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 111 | - } |
|
| 98 | + /** |
|
| 99 | + * @param string $modify |
|
| 100 | + * @return DateTimeImmutable |
|
| 101 | + * @throws DatetimeException |
|
| 102 | + */ |
|
| 103 | + public function modify($modify): self |
|
| 104 | + { |
|
| 105 | + /** @var \DateTimeImmutable|false $result */ |
|
| 106 | + $result = $this->innerDateTime->modify($modify); |
|
| 107 | + if ($result === false) { |
|
| 108 | + throw DatetimeException::createFromPhpError(); |
|
| 109 | + } |
|
| 110 | + return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * @param int $year |
|
| 115 | - * @param int $month |
|
| 116 | - * @param int $day |
|
| 117 | - * @return DateTimeImmutable |
|
| 118 | - * @throws DatetimeException |
|
| 119 | - */ |
|
| 120 | - public function setDate($year, $month, $day): self |
|
| 121 | - { |
|
| 122 | - /** @var \DateTimeImmutable|false $result */ |
|
| 123 | - $result = $this->innerDateTime->setDate($year, $month, $day); |
|
| 124 | - if ($result === false) { |
|
| 125 | - throw DatetimeException::createFromPhpError(); |
|
| 126 | - } |
|
| 127 | - return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 128 | - } |
|
| 113 | + /** |
|
| 114 | + * @param int $year |
|
| 115 | + * @param int $month |
|
| 116 | + * @param int $day |
|
| 117 | + * @return DateTimeImmutable |
|
| 118 | + * @throws DatetimeException |
|
| 119 | + */ |
|
| 120 | + public function setDate($year, $month, $day): self |
|
| 121 | + { |
|
| 122 | + /** @var \DateTimeImmutable|false $result */ |
|
| 123 | + $result = $this->innerDateTime->setDate($year, $month, $day); |
|
| 124 | + if ($result === false) { |
|
| 125 | + throw DatetimeException::createFromPhpError(); |
|
| 126 | + } |
|
| 127 | + return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param int $year |
|
| 132 | - * @param int $week |
|
| 133 | - * @param int $day |
|
| 134 | - * @return DateTimeImmutable |
|
| 135 | - * @throws DatetimeException |
|
| 136 | - */ |
|
| 137 | - public function setISODate($year, $week, $day = 1): self |
|
| 138 | - { |
|
| 139 | - /** @var \DateTimeImmutable|false $result */ |
|
| 140 | - $result = $this->innerDateTime->setISODate($year, $week, $day); |
|
| 141 | - if ($result === false) { |
|
| 142 | - throw DatetimeException::createFromPhpError(); |
|
| 143 | - } |
|
| 144 | - return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 145 | - } |
|
| 130 | + /** |
|
| 131 | + * @param int $year |
|
| 132 | + * @param int $week |
|
| 133 | + * @param int $day |
|
| 134 | + * @return DateTimeImmutable |
|
| 135 | + * @throws DatetimeException |
|
| 136 | + */ |
|
| 137 | + public function setISODate($year, $week, $day = 1): self |
|
| 138 | + { |
|
| 139 | + /** @var \DateTimeImmutable|false $result */ |
|
| 140 | + $result = $this->innerDateTime->setISODate($year, $week, $day); |
|
| 141 | + if ($result === false) { |
|
| 142 | + throw DatetimeException::createFromPhpError(); |
|
| 143 | + } |
|
| 144 | + return self::createFromRegular($result); //we have to recreate a safe datetime because modify create a new instance of \DateTimeImmutable |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * @param int $hour |
|
| 149 | - * @param int $minute |
|
| 150 | - * @param int $second |
|
| 151 | - * @param int $microseconds |
|
| 152 | - * @return DateTimeImmutable |
|
| 153 | - * @throws DatetimeException |
|
| 154 | - */ |
|
| 155 | - public function setTime($hour, $minute, $second = 0, $microseconds = 0): self |
|
| 156 | - { |
|
| 157 | - /** @var \DateTimeImmutable|false $result */ |
|
| 158 | - $result = $this->innerDateTime->setTime($hour, $minute, $second, $microseconds); |
|
| 159 | - if ($result === false) { |
|
| 160 | - throw DatetimeException::createFromPhpError(); |
|
| 161 | - } |
|
| 162 | - return self::createFromRegular($result); |
|
| 163 | - } |
|
| 147 | + /** |
|
| 148 | + * @param int $hour |
|
| 149 | + * @param int $minute |
|
| 150 | + * @param int $second |
|
| 151 | + * @param int $microseconds |
|
| 152 | + * @return DateTimeImmutable |
|
| 153 | + * @throws DatetimeException |
|
| 154 | + */ |
|
| 155 | + public function setTime($hour, $minute, $second = 0, $microseconds = 0): self |
|
| 156 | + { |
|
| 157 | + /** @var \DateTimeImmutable|false $result */ |
|
| 158 | + $result = $this->innerDateTime->setTime($hour, $minute, $second, $microseconds); |
|
| 159 | + if ($result === false) { |
|
| 160 | + throw DatetimeException::createFromPhpError(); |
|
| 161 | + } |
|
| 162 | + return self::createFromRegular($result); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * @param int $unixtimestamp |
|
| 167 | - * @return DateTimeImmutable |
|
| 168 | - * @throws DatetimeException |
|
| 169 | - */ |
|
| 170 | - public function setTimestamp($unixtimestamp): self |
|
| 171 | - { |
|
| 172 | - /** @var \DateTimeImmutable|false $result */ |
|
| 173 | - $result = $this->innerDateTime->setTimestamp($unixtimestamp); |
|
| 174 | - if ($result === false) { |
|
| 175 | - throw DatetimeException::createFromPhpError(); |
|
| 176 | - } |
|
| 177 | - return self::createFromRegular($result); |
|
| 178 | - } |
|
| 165 | + /** |
|
| 166 | + * @param int $unixtimestamp |
|
| 167 | + * @return DateTimeImmutable |
|
| 168 | + * @throws DatetimeException |
|
| 169 | + */ |
|
| 170 | + public function setTimestamp($unixtimestamp): self |
|
| 171 | + { |
|
| 172 | + /** @var \DateTimeImmutable|false $result */ |
|
| 173 | + $result = $this->innerDateTime->setTimestamp($unixtimestamp); |
|
| 174 | + if ($result === false) { |
|
| 175 | + throw DatetimeException::createFromPhpError(); |
|
| 176 | + } |
|
| 177 | + return self::createFromRegular($result); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * @param DateTimeZone $timezone |
|
| 182 | - * @return DateTimeImmutable |
|
| 183 | - * @throws DatetimeException |
|
| 184 | - */ |
|
| 185 | - public function setTimezone($timezone): self |
|
| 186 | - { |
|
| 187 | - /** @var \DateTimeImmutable|false $result */ |
|
| 188 | - $result = $this->innerDateTime->setTimezone($timezone); |
|
| 189 | - if ($result === false) { |
|
| 190 | - throw DatetimeException::createFromPhpError(); |
|
| 191 | - } |
|
| 192 | - return self::createFromRegular($result); |
|
| 193 | - } |
|
| 180 | + /** |
|
| 181 | + * @param DateTimeZone $timezone |
|
| 182 | + * @return DateTimeImmutable |
|
| 183 | + * @throws DatetimeException |
|
| 184 | + */ |
|
| 185 | + public function setTimezone($timezone): self |
|
| 186 | + { |
|
| 187 | + /** @var \DateTimeImmutable|false $result */ |
|
| 188 | + $result = $this->innerDateTime->setTimezone($timezone); |
|
| 189 | + if ($result === false) { |
|
| 190 | + throw DatetimeException::createFromPhpError(); |
|
| 191 | + } |
|
| 192 | + return self::createFromRegular($result); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * @param DateInterval $interval |
|
| 197 | - * @return DateTimeImmutable |
|
| 198 | - * @throws DatetimeException |
|
| 199 | - */ |
|
| 200 | - public function sub($interval): self |
|
| 201 | - { |
|
| 202 | - /** @var \DateTimeImmutable|false $result */ |
|
| 203 | - $result = $this->innerDateTime->sub($interval); |
|
| 204 | - if ($result === false) { |
|
| 205 | - throw DatetimeException::createFromPhpError(); |
|
| 206 | - } |
|
| 207 | - return self::createFromRegular($result); |
|
| 208 | - } |
|
| 195 | + /** |
|
| 196 | + * @param DateInterval $interval |
|
| 197 | + * @return DateTimeImmutable |
|
| 198 | + * @throws DatetimeException |
|
| 199 | + */ |
|
| 200 | + public function sub($interval): self |
|
| 201 | + { |
|
| 202 | + /** @var \DateTimeImmutable|false $result */ |
|
| 203 | + $result = $this->innerDateTime->sub($interval); |
|
| 204 | + if ($result === false) { |
|
| 205 | + throw DatetimeException::createFromPhpError(); |
|
| 206 | + } |
|
| 207 | + return self::createFromRegular($result); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @throws DatetimeException |
|
| 212 | - */ |
|
| 213 | - public function getOffset(): int |
|
| 214 | - { |
|
| 215 | - /** @var int|false $result */ |
|
| 216 | - $result = $this->innerDateTime->getOffset(); |
|
| 217 | - if ($result === false) { |
|
| 218 | - throw DatetimeException::createFromPhpError(); |
|
| 219 | - } |
|
| 220 | - return $result; |
|
| 221 | - } |
|
| 210 | + /** |
|
| 211 | + * @throws DatetimeException |
|
| 212 | + */ |
|
| 213 | + public function getOffset(): int |
|
| 214 | + { |
|
| 215 | + /** @var int|false $result */ |
|
| 216 | + $result = $this->innerDateTime->getOffset(); |
|
| 217 | + if ($result === false) { |
|
| 218 | + throw DatetimeException::createFromPhpError(); |
|
| 219 | + } |
|
| 220 | + return $result; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - ////////////////////////////////////////////////////////////////////////////////////////// |
|
| 224 | - //overload getters to use the inner datetime immutable instead of itself |
|
| 223 | + ////////////////////////////////////////////////////////////////////////////////////////// |
|
| 224 | + //overload getters to use the inner datetime immutable instead of itself |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * @param DateInterval $interval |
|
| 228 | - * @return DateTimeImmutable |
|
| 229 | - */ |
|
| 230 | - public function add($interval): self |
|
| 231 | - { |
|
| 232 | - return self::createFromRegular($this->innerDateTime->add($interval)); |
|
| 233 | - } |
|
| 226 | + /** |
|
| 227 | + * @param DateInterval $interval |
|
| 228 | + * @return DateTimeImmutable |
|
| 229 | + */ |
|
| 230 | + public function add($interval): self |
|
| 231 | + { |
|
| 232 | + return self::createFromRegular($this->innerDateTime->add($interval)); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * @param DateTime $dateTime |
|
| 237 | - * @return DateTimeImmutable |
|
| 238 | - */ |
|
| 239 | - public static function createFromMutable($dateTime): self |
|
| 240 | - { |
|
| 241 | - return self::createFromRegular(parent::createFromMutable($dateTime)); |
|
| 242 | - } |
|
| 235 | + /** |
|
| 236 | + * @param DateTime $dateTime |
|
| 237 | + * @return DateTimeImmutable |
|
| 238 | + */ |
|
| 239 | + public static function createFromMutable($dateTime): self |
|
| 240 | + { |
|
| 241 | + return self::createFromRegular(parent::createFromMutable($dateTime)); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * @param mixed[] $array |
|
| 246 | - * @return DateTimeImmutable |
|
| 247 | - */ |
|
| 248 | - public static function __set_state($array): self |
|
| 249 | - { |
|
| 250 | - return self::createFromRegular(parent::__set_state($array)); |
|
| 251 | - } |
|
| 244 | + /** |
|
| 245 | + * @param mixed[] $array |
|
| 246 | + * @return DateTimeImmutable |
|
| 247 | + */ |
|
| 248 | + public static function __set_state($array): self |
|
| 249 | + { |
|
| 250 | + return self::createFromRegular(parent::__set_state($array)); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - public function getTimezone(): DateTimeZone |
|
| 254 | - { |
|
| 255 | - return $this->innerDateTime->getTimezone(); |
|
| 256 | - } |
|
| 253 | + public function getTimezone(): DateTimeZone |
|
| 254 | + { |
|
| 255 | + return $this->innerDateTime->getTimezone(); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - public function getTimestamp(): int |
|
| 259 | - { |
|
| 260 | - return $this->innerDateTime->getTimestamp(); |
|
| 261 | - } |
|
| 258 | + public function getTimestamp(): int |
|
| 259 | + { |
|
| 260 | + return $this->innerDateTime->getTimestamp(); |
|
| 261 | + } |
|
| 262 | 262 | } |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0) |
| 32 | 32 | { |
| 33 | - $data = \json_decode($json, $assoc, $depth, $options); |
|
| 34 | - if (JSON_ERROR_NONE !== json_last_error()) { |
|
| 35 | - throw JsonException::createFromPhpError(); |
|
| 36 | - } |
|
| 37 | - return $data; |
|
| 33 | + $data = \json_decode($json, $assoc, $depth, $options); |
|
| 34 | + if (JSON_ERROR_NONE !== json_last_error()) { |
|
| 35 | + throw JsonException::createFromPhpError(); |
|
| 36 | + } |
|
| 37 | + return $data; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function apc_fetch($key) |
| 52 | 52 | { |
| 53 | - error_clear_last(); |
|
| 54 | - $result = \apc_fetch($key, $success); |
|
| 55 | - if ($success === false) { |
|
| 56 | - throw ApcException::createFromPhpError(); |
|
| 57 | - } |
|
| 58 | - return $result; |
|
| 53 | + error_clear_last(); |
|
| 54 | + $result = \apc_fetch($key, $success); |
|
| 55 | + if ($success === false) { |
|
| 56 | + throw ApcException::createFromPhpError(); |
|
| 57 | + } |
|
| 58 | + return $result; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | function apcu_fetch($key) |
| 72 | 72 | { |
| 73 | - error_clear_last(); |
|
| 74 | - $result = \apcu_fetch($key, $success); |
|
| 75 | - if ($success === false) { |
|
| 76 | - throw ApcuException::createFromPhpError(); |
|
| 77 | - } |
|
| 78 | - return $result; |
|
| 73 | + error_clear_last(); |
|
| 74 | + $result = \apcu_fetch($key, $success); |
|
| 75 | + if ($success === false) { |
|
| 76 | + throw ApcuException::createFromPhpError(); |
|
| 77 | + } |
|
| 78 | + return $result; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function preg_replace($pattern, $replacement, $subject, int $limit = -1, int &$count = null) |
| 156 | 156 | { |
| 157 | - error_clear_last(); |
|
| 158 | - $result = \preg_replace($pattern, $replacement, $subject, $limit, $count); |
|
| 159 | - if (preg_last_error() !== PREG_NO_ERROR || $result === null) { |
|
| 160 | - throw PcreException::createFromPhpError(); |
|
| 161 | - } |
|
| 162 | - return $result; |
|
| 157 | + error_clear_last(); |
|
| 158 | + $result = \preg_replace($pattern, $replacement, $subject, $limit, $count); |
|
| 159 | + if (preg_last_error() !== PREG_NO_ERROR || $result === null) { |
|
| 160 | + throw PcreException::createFromPhpError(); |
|
| 161 | + } |
|
| 162 | + return $result; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function readdir($dir_handle = null) |
| 172 | 172 | { |
| 173 | - if ($dir_handle !== null) { |
|
| 174 | - $result = \readdir($dir_handle); |
|
| 175 | - } else { |
|
| 176 | - $result = \readdir(); |
|
| 177 | - } |
|
| 178 | - return $result; |
|
| 173 | + if ($dir_handle !== null) { |
|
| 174 | + $result = \readdir($dir_handle); |
|
| 175 | + } else { |
|
| 176 | + $result = \readdir(); |
|
| 177 | + } |
|
| 178 | + return $result; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function openssl_encrypt(string $data, string $method, string $key, int $options = 0, string $iv = "", string &$tag = "", string $aad = "", int $tag_length = 16): string |
| 200 | 200 | { |
| 201 | - error_clear_last(); |
|
| 202 | - // The $tag parameter is handled in a weird way by openssl_encrypt. It cannot be provided unless encoding is AEAD |
|
| 203 | - if (func_num_args() <= 5) { |
|
| 204 | - $result = \openssl_encrypt($data, $method, $key, $options, $iv); |
|
| 205 | - } else { |
|
| 206 | - $result = \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length); |
|
| 207 | - } |
|
| 208 | - if ($result === false) { |
|
| 209 | - throw OpensslException::createFromPhpError(); |
|
| 210 | - } |
|
| 211 | - return $result; |
|
| 201 | + error_clear_last(); |
|
| 202 | + // The $tag parameter is handled in a weird way by openssl_encrypt. It cannot be provided unless encoding is AEAD |
|
| 203 | + if (func_num_args() <= 5) { |
|
| 204 | + $result = \openssl_encrypt($data, $method, $key, $options, $iv); |
|
| 205 | + } else { |
|
| 206 | + $result = \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length); |
|
| 207 | + } |
|
| 208 | + if ($result === false) { |
|
| 209 | + throw OpensslException::createFromPhpError(); |
|
| 210 | + } |
|
| 211 | + return $result; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | function socket_write($socket, string $buffer, int $length = 0): int |
| 234 | 234 | { |
| 235 | - error_clear_last(); |
|
| 236 | - $result = $length === 0 ? \socket_write($socket, $buffer) : \socket_write($socket, $buffer, $length); |
|
| 237 | - if ($result === false) { |
|
| 238 | - throw SocketsException::createFromPhpError(); |
|
| 239 | - } |
|
| 240 | - return $result; |
|
| 235 | + error_clear_last(); |
|
| 236 | + $result = $length === 0 ? \socket_write($socket, $buffer) : \socket_write($socket, $buffer, $length); |
|
| 237 | + if ($result === false) { |
|
| 238 | + throw SocketsException::createFromPhpError(); |
|
| 239 | + } |
|
| 240 | + return $result; |
|
| 241 | 241 | } |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | |
| 6 | 6 | class OpensslException extends \Exception implements SafeExceptionInterface |
| 7 | 7 | { |
| 8 | - public static function createFromPhpError(): self |
|
| 9 | - { |
|
| 10 | - return new self(\openssl_error_string() ?: '', 0); |
|
| 11 | - } |
|
| 8 | + public static function createFromPhpError(): self |
|
| 9 | + { |
|
| 10 | + return new self(\openssl_error_string() ?: '', 0); |
|
| 11 | + } |
|
| 12 | 12 | } |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | |
| 6 | 6 | class JsonException extends \Exception implements SafeExceptionInterface |
| 7 | 7 | { |
| 8 | - public static function createFromPhpError(): self |
|
| 9 | - { |
|
| 10 | - return new self(\json_last_error_msg(), \json_last_error()); |
|
| 11 | - } |
|
| 8 | + public static function createFromPhpError(): self |
|
| 9 | + { |
|
| 10 | + return new self(\json_last_error_msg(), \json_last_error()); |
|
| 11 | + } |
|
| 12 | 12 | } |
@@ -5,11 +5,11 @@ |
||
| 5 | 5 | |
| 6 | 6 | class CurlException extends \Exception implements SafeExceptionInterface |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * @param resource $ch |
|
| 10 | - */ |
|
| 11 | - public static function createFromCurlResource($ch): self |
|
| 12 | - { |
|
| 13 | - return new self(\curl_error($ch), \curl_errno($ch)); |
|
| 14 | - } |
|
| 8 | + /** |
|
| 9 | + * @param resource $ch |
|
| 10 | + */ |
|
| 11 | + public static function createFromCurlResource($ch): self |
|
| 12 | + { |
|
| 13 | + return new self(\curl_error($ch), \curl_errno($ch)); |
|
| 14 | + } |
|
| 15 | 15 | } |
@@ -5,17 +5,17 @@ |
||
| 5 | 5 | |
| 6 | 6 | class PcreException extends \Exception implements SafeExceptionInterface |
| 7 | 7 | { |
| 8 | - public static function createFromPhpError(): self |
|
| 9 | - { |
|
| 10 | - $errorMap = [ |
|
| 11 | - PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR: Internal error', |
|
| 12 | - PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR: Backtrack limit reached', |
|
| 13 | - PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR: Recursion limit reached', |
|
| 14 | - PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR: Invalid UTF8 character', |
|
| 15 | - PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR', |
|
| 16 | - PREG_JIT_STACKLIMIT_ERROR => 'PREG_JIT_STACKLIMIT_ERROR', |
|
| 17 | - ]; |
|
| 18 | - $errMsg = $errorMap[preg_last_error()] ?? 'Unknown PCRE error: '.preg_last_error(); |
|
| 19 | - return new self($errMsg, \preg_last_error()); |
|
| 20 | - } |
|
| 8 | + public static function createFromPhpError(): self |
|
| 9 | + { |
|
| 10 | + $errorMap = [ |
|
| 11 | + PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR: Internal error', |
|
| 12 | + PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR: Backtrack limit reached', |
|
| 13 | + PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR: Recursion limit reached', |
|
| 14 | + PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR: Invalid UTF8 character', |
|
| 15 | + PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR', |
|
| 16 | + PREG_JIT_STACKLIMIT_ERROR => 'PREG_JIT_STACKLIMIT_ERROR', |
|
| 17 | + ]; |
|
| 18 | + $errMsg = $errorMap[preg_last_error()] ?? 'Unknown PCRE error: '.preg_last_error(); |
|
| 19 | + return new self($errMsg, \preg_last_error()); |
|
| 20 | + } |
|
| 21 | 21 | } |