@@ -11,6 +11,6 @@ |
||
| 11 | 11 | |
| 12 | 12 | class DateTimeType extends VarDateTimeType implements CarbonDoctrineType |
| 13 | 13 | { |
| 14 | - /** @use CarbonTypeConverter<Carbon> */ |
|
| 15 | - use CarbonTypeConverter; |
|
| 14 | + /** @use CarbonTypeConverter<Carbon> */ |
|
| 15 | + use CarbonTypeConverter; |
|
| 16 | 16 | } |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | |
| 14 | 14 | class DateTimeDefaultPrecision |
| 15 | 15 | { |
| 16 | - private static $precision = 6; |
|
| 16 | + private static $precision = 6; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Change the default Doctrine datetime and datetime_immutable precision. |
|
| 20 | - * |
|
| 21 | - * @param int $precision |
|
| 22 | - */ |
|
| 23 | - public static function set(int $precision): void |
|
| 24 | - { |
|
| 25 | - self::$precision = $precision; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Change the default Doctrine datetime and datetime_immutable precision. |
|
| 20 | + * |
|
| 21 | + * @param int $precision |
|
| 22 | + */ |
|
| 23 | + public static function set(int $precision): void |
|
| 24 | + { |
|
| 25 | + self::$precision = $precision; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Get the default Doctrine datetime and datetime_immutable precision. |
|
| 30 | - * |
|
| 31 | - * @return int |
|
| 32 | - */ |
|
| 33 | - public static function get(): int |
|
| 34 | - { |
|
| 35 | - return self::$precision; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Get the default Doctrine datetime and datetime_immutable precision. |
|
| 30 | + * |
|
| 31 | + * @return int |
|
| 32 | + */ |
|
| 33 | + public static function get(): int |
|
| 34 | + { |
|
| 35 | + return self::$precision; |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -23,101 +23,101 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | trait CarbonTypeConverter |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @return class-string<T> |
|
| 28 | - */ |
|
| 29 | - protected function getCarbonClassName(): string |
|
| 30 | - { |
|
| 31 | - return Carbon::class; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
| 38 | - { |
|
| 39 | - $precision = $fieldDeclaration['precision'] ?: 10; |
|
| 40 | - |
|
| 41 | - if ($fieldDeclaration['secondPrecision'] ?? false) { |
|
| 42 | - $precision = 0; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($precision === 10) { |
|
| 46 | - $precision = DateTimeDefaultPrecision::get(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $type = parent::getSQLDeclaration($fieldDeclaration, $platform); |
|
| 50 | - |
|
| 51 | - if (!$precision) { |
|
| 52 | - return $type; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if (str_contains($type, '(')) { |
|
| 56 | - return preg_replace('/\(\d+\)/', "($precision)", $type); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - [$before, $after] = explode(' ', "$type "); |
|
| 60 | - |
|
| 61 | - return trim("$before($precision) $after"); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 66 | - * |
|
| 67 | - * @return T|null |
|
| 68 | - */ |
|
| 69 | - public function convertToPHPValue($value, AbstractPlatform $platform) |
|
| 70 | - { |
|
| 71 | - $class = $this->getCarbonClassName(); |
|
| 72 | - |
|
| 73 | - if ($value === null || is_a($value, $class)) { |
|
| 74 | - return $value; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - if ($value instanceof DateTimeInterface) { |
|
| 78 | - return $class::instance($value); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $date = null; |
|
| 82 | - $error = null; |
|
| 83 | - |
|
| 84 | - try { |
|
| 85 | - $date = $class::parse($value); |
|
| 86 | - } catch (Exception $exception) { |
|
| 87 | - $error = $exception; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - if (!$date) { |
|
| 91 | - throw ConversionException::conversionFailedFormat( |
|
| 92 | - $value, |
|
| 93 | - $this->getName(), |
|
| 94 | - 'Y-m-d H:i:s.u or any format supported by '.$class.'::parse()', |
|
| 95 | - $error |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $date; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 104 | - * |
|
| 105 | - * @return string|null |
|
| 106 | - */ |
|
| 107 | - public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
| 108 | - { |
|
| 109 | - if ($value === null) { |
|
| 110 | - return $value; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ($value instanceof DateTimeInterface) { |
|
| 114 | - return $value->format('Y-m-d H:i:s.u'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - throw ConversionException::conversionFailedInvalidType( |
|
| 118 | - $value, |
|
| 119 | - $this->getName(), |
|
| 120 | - ['null', 'DateTime', 'Carbon'] |
|
| 121 | - ); |
|
| 122 | - } |
|
| 26 | + /** |
|
| 27 | + * @return class-string<T> |
|
| 28 | + */ |
|
| 29 | + protected function getCarbonClassName(): string |
|
| 30 | + { |
|
| 31 | + return Carbon::class; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
| 38 | + { |
|
| 39 | + $precision = $fieldDeclaration['precision'] ?: 10; |
|
| 40 | + |
|
| 41 | + if ($fieldDeclaration['secondPrecision'] ?? false) { |
|
| 42 | + $precision = 0; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($precision === 10) { |
|
| 46 | + $precision = DateTimeDefaultPrecision::get(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $type = parent::getSQLDeclaration($fieldDeclaration, $platform); |
|
| 50 | + |
|
| 51 | + if (!$precision) { |
|
| 52 | + return $type; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if (str_contains($type, '(')) { |
|
| 56 | + return preg_replace('/\(\d+\)/', "($precision)", $type); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + [$before, $after] = explode(' ', "$type "); |
|
| 60 | + |
|
| 61 | + return trim("$before($precision) $after"); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 66 | + * |
|
| 67 | + * @return T|null |
|
| 68 | + */ |
|
| 69 | + public function convertToPHPValue($value, AbstractPlatform $platform) |
|
| 70 | + { |
|
| 71 | + $class = $this->getCarbonClassName(); |
|
| 72 | + |
|
| 73 | + if ($value === null || is_a($value, $class)) { |
|
| 74 | + return $value; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + if ($value instanceof DateTimeInterface) { |
|
| 78 | + return $class::instance($value); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $date = null; |
|
| 82 | + $error = null; |
|
| 83 | + |
|
| 84 | + try { |
|
| 85 | + $date = $class::parse($value); |
|
| 86 | + } catch (Exception $exception) { |
|
| 87 | + $error = $exception; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + if (!$date) { |
|
| 91 | + throw ConversionException::conversionFailedFormat( |
|
| 92 | + $value, |
|
| 93 | + $this->getName(), |
|
| 94 | + 'Y-m-d H:i:s.u or any format supported by '.$class.'::parse()', |
|
| 95 | + $error |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $date; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 104 | + * |
|
| 105 | + * @return string|null |
|
| 106 | + */ |
|
| 107 | + public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
| 108 | + { |
|
| 109 | + if ($value === null) { |
|
| 110 | + return $value; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ($value instanceof DateTimeInterface) { |
|
| 114 | + return $value->format('Y-m-d H:i:s.u'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + throw ConversionException::conversionFailedInvalidType( |
|
| 118 | + $value, |
|
| 119 | + $this->getName(), |
|
| 120 | + ['null', 'DateTime', 'Carbon'] |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -15,23 +15,23 @@ |
||
| 15 | 15 | |
| 16 | 16 | class CarbonType extends DateTimeType implements CarbonDoctrineType |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - * |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function getName() |
|
| 24 | - { |
|
| 25 | - return 'carbon'; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + * |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function getName() |
|
| 24 | + { |
|
| 25 | + return 'carbon'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - * |
|
| 31 | - * @return bool |
|
| 32 | - */ |
|
| 33 | - public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
| 34 | - { |
|
| 35 | - return true; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + * |
|
| 31 | + * @return bool |
|
| 32 | + */ |
|
| 33 | + public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
| 34 | + { |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -15,9 +15,9 @@ |
||
| 15 | 15 | |
| 16 | 16 | interface CarbonDoctrineType |
| 17 | 17 | { |
| 18 | - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform); |
|
| 18 | + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform); |
|
| 19 | 19 | |
| 20 | - public function convertToPHPValue($value, AbstractPlatform $platform); |
|
| 20 | + public function convertToPHPValue($value, AbstractPlatform $platform); |
|
| 21 | 21 | |
| 22 | - public function convertToDatabaseValue($value, AbstractPlatform $platform); |
|
| 22 | + public function convertToDatabaseValue($value, AbstractPlatform $platform); |
|
| 23 | 23 | } |
@@ -15,23 +15,23 @@ |
||
| 15 | 15 | |
| 16 | 16 | class CarbonImmutableType extends DateTimeImmutableType implements CarbonDoctrineType |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - * |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function getName() |
|
| 24 | - { |
|
| 25 | - return 'carbon_immutable'; |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + * |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function getName() |
|
| 24 | + { |
|
| 25 | + return 'carbon_immutable'; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - * |
|
| 31 | - * @return bool |
|
| 32 | - */ |
|
| 33 | - public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
| 34 | - { |
|
| 35 | - return true; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + * |
|
| 31 | + * @return bool |
|
| 32 | + */ |
|
| 33 | + public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
| 34 | + { |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -241,86 +241,86 @@ |
||
| 241 | 241 | */ |
| 242 | 242 | class Factory |
| 243 | 243 | { |
| 244 | - protected $className = Carbon::class; |
|
| 244 | + protected $className = Carbon::class; |
|
| 245 | 245 | |
| 246 | - protected $settings = []; |
|
| 246 | + protected $settings = []; |
|
| 247 | 247 | |
| 248 | - public function __construct(array $settings = [], ?string $className = null) |
|
| 249 | - { |
|
| 250 | - if ($className) { |
|
| 251 | - $this->className = $className; |
|
| 252 | - } |
|
| 248 | + public function __construct(array $settings = [], ?string $className = null) |
|
| 249 | + { |
|
| 250 | + if ($className) { |
|
| 251 | + $this->className = $className; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - $this->settings = $settings; |
|
| 255 | - } |
|
| 254 | + $this->settings = $settings; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - public function getClassName() |
|
| 258 | - { |
|
| 259 | - return $this->className; |
|
| 260 | - } |
|
| 257 | + public function getClassName() |
|
| 258 | + { |
|
| 259 | + return $this->className; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - public function setClassName(string $className) |
|
| 263 | - { |
|
| 264 | - $this->className = $className; |
|
| 262 | + public function setClassName(string $className) |
|
| 263 | + { |
|
| 264 | + $this->className = $className; |
|
| 265 | 265 | |
| 266 | - return $this; |
|
| 267 | - } |
|
| 266 | + return $this; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - public function className(string $className = null) |
|
| 270 | - { |
|
| 271 | - return $className === null ? $this->getClassName() : $this->setClassName($className); |
|
| 272 | - } |
|
| 269 | + public function className(string $className = null) |
|
| 270 | + { |
|
| 271 | + return $className === null ? $this->getClassName() : $this->setClassName($className); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - public function getSettings() |
|
| 275 | - { |
|
| 276 | - return $this->settings; |
|
| 277 | - } |
|
| 274 | + public function getSettings() |
|
| 275 | + { |
|
| 276 | + return $this->settings; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - public function setSettings(array $settings) |
|
| 280 | - { |
|
| 281 | - $this->settings = $settings; |
|
| 279 | + public function setSettings(array $settings) |
|
| 280 | + { |
|
| 281 | + $this->settings = $settings; |
|
| 282 | 282 | |
| 283 | - return $this; |
|
| 284 | - } |
|
| 283 | + return $this; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - public function settings(array $settings = null) |
|
| 287 | - { |
|
| 288 | - return $settings === null ? $this->getSettings() : $this->setSettings($settings); |
|
| 289 | - } |
|
| 286 | + public function settings(array $settings = null) |
|
| 287 | + { |
|
| 288 | + return $settings === null ? $this->getSettings() : $this->setSettings($settings); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - public function mergeSettings(array $settings) |
|
| 292 | - { |
|
| 293 | - $this->settings = array_merge($this->settings, $settings); |
|
| 291 | + public function mergeSettings(array $settings) |
|
| 292 | + { |
|
| 293 | + $this->settings = array_merge($this->settings, $settings); |
|
| 294 | 294 | |
| 295 | - return $this; |
|
| 296 | - } |
|
| 295 | + return $this; |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - public function __call($name, $arguments) |
|
| 299 | - { |
|
| 300 | - $method = new ReflectionMethod($this->className, $name); |
|
| 301 | - $settings = $this->settings; |
|
| 298 | + public function __call($name, $arguments) |
|
| 299 | + { |
|
| 300 | + $method = new ReflectionMethod($this->className, $name); |
|
| 301 | + $settings = $this->settings; |
|
| 302 | 302 | |
| 303 | - if ($settings && isset($settings['timezone'])) { |
|
| 304 | - $tzParameters = array_filter($method->getParameters(), function ($parameter) { |
|
| 305 | - return \in_array($parameter->getName(), ['tz', 'timezone'], true); |
|
| 306 | - }); |
|
| 303 | + if ($settings && isset($settings['timezone'])) { |
|
| 304 | + $tzParameters = array_filter($method->getParameters(), function ($parameter) { |
|
| 305 | + return \in_array($parameter->getName(), ['tz', 'timezone'], true); |
|
| 306 | + }); |
|
| 307 | 307 | |
| 308 | - if (isset($arguments[0]) && \in_array($name, ['instance', 'make', 'create', 'parse'], true)) { |
|
| 309 | - if ($arguments[0] instanceof DateTimeInterface) { |
|
| 310 | - $settings['innerTimezone'] = $settings['timezone']; |
|
| 311 | - } elseif (\is_string($arguments[0]) && date_parse($arguments[0])['is_localtime']) { |
|
| 312 | - unset($settings['timezone'], $settings['innerTimezone']); |
|
| 313 | - } |
|
| 314 | - } elseif (\count($tzParameters)) { |
|
| 315 | - array_splice($arguments, key($tzParameters), 0, [$settings['timezone']]); |
|
| 316 | - unset($settings['timezone']); |
|
| 317 | - } |
|
| 318 | - } |
|
| 308 | + if (isset($arguments[0]) && \in_array($name, ['instance', 'make', 'create', 'parse'], true)) { |
|
| 309 | + if ($arguments[0] instanceof DateTimeInterface) { |
|
| 310 | + $settings['innerTimezone'] = $settings['timezone']; |
|
| 311 | + } elseif (\is_string($arguments[0]) && date_parse($arguments[0])['is_localtime']) { |
|
| 312 | + unset($settings['timezone'], $settings['innerTimezone']); |
|
| 313 | + } |
|
| 314 | + } elseif (\count($tzParameters)) { |
|
| 315 | + array_splice($arguments, key($tzParameters), 0, [$settings['timezone']]); |
|
| 316 | + unset($settings['timezone']); |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - $result = $this->className::$name(...$arguments); |
|
| 320 | + $result = $this->className::$name(...$arguments); |
|
| 321 | 321 | |
| 322 | - return $result instanceof CarbonInterface && !empty($settings) |
|
| 323 | - ? $result->settings($settings) |
|
| 324 | - : $result; |
|
| 325 | - } |
|
| 322 | + return $result instanceof CarbonInterface && !empty($settings) |
|
| 323 | + ? $result->settings($settings) |
|
| 324 | + : $result; |
|
| 325 | + } |
|
| 326 | 326 | } |
@@ -13,26 +13,26 @@ |
||
| 13 | 13 | |
| 14 | 14 | class Invoker |
| 15 | 15 | { |
| 16 | - public const CLI_CLASS_NAME = 'Carbon\\Cli'; |
|
| 16 | + public const CLI_CLASS_NAME = 'Carbon\\Cli'; |
|
| 17 | 17 | |
| 18 | - protected function runWithCli(string $className, array $parameters): bool |
|
| 19 | - { |
|
| 20 | - $cli = new $className(); |
|
| 18 | + protected function runWithCli(string $className, array $parameters): bool |
|
| 19 | + { |
|
| 20 | + $cli = new $className(); |
|
| 21 | 21 | |
| 22 | - return $cli(...$parameters); |
|
| 23 | - } |
|
| 22 | + return $cli(...$parameters); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function __invoke(...$parameters): bool |
|
| 26 | - { |
|
| 27 | - if (class_exists(self::CLI_CLASS_NAME)) { |
|
| 28 | - return $this->runWithCli(self::CLI_CLASS_NAME, $parameters); |
|
| 29 | - } |
|
| 25 | + public function __invoke(...$parameters): bool |
|
| 26 | + { |
|
| 27 | + if (class_exists(self::CLI_CLASS_NAME)) { |
|
| 28 | + return $this->runWithCli(self::CLI_CLASS_NAME, $parameters); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $function = (($parameters[1] ?? '') === 'install' ? ($parameters[2] ?? null) : null) ?: 'shell_exec'; |
|
| 32 | - $function('composer require carbon-cli/carbon-cli --no-interaction'); |
|
| 31 | + $function = (($parameters[1] ?? '') === 'install' ? ($parameters[2] ?? null) : null) ?: 'shell_exec'; |
|
| 32 | + $function('composer require carbon-cli/carbon-cli --no-interaction'); |
|
| 33 | 33 | |
| 34 | - echo 'Installation succeeded.'; |
|
| 34 | + echo 'Installation succeeded.'; |
|
| 35 | 35 | |
| 36 | - return true; |
|
| 37 | - } |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -18,5 +18,5 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface TranslatorStrongTypeInterface |
| 20 | 20 | { |
| 21 | - public function getFromCatalogue(MessageCatalogueInterface $catalogue, string $id, string $domain = 'messages'); |
|
| 21 | + public function getFromCatalogue(MessageCatalogueInterface $catalogue, string $id, string $domain = 'messages'); |
|
| 22 | 22 | } |