@@ -17,25 +17,25 @@ |
||
17 | 17 | use ReflectionMethod; |
18 | 18 | |
19 | 19 | if (!class_exists(AbstractReflectionMacro::class, false)) { |
20 | - abstract class AbstractReflectionMacro extends AbstractMacro |
|
21 | - { |
|
22 | - /** |
|
23 | - * {@inheritdoc} |
|
24 | - */ |
|
25 | - public function getReflection(): ?Reflection\Adapter\ReflectionMethod |
|
26 | - { |
|
27 | - if ($this->reflectionFunction instanceof Reflection\Adapter\ReflectionMethod) { |
|
28 | - return $this->reflectionFunction; |
|
29 | - } |
|
20 | + abstract class AbstractReflectionMacro extends AbstractMacro |
|
21 | + { |
|
22 | + /** |
|
23 | + * {@inheritdoc} |
|
24 | + */ |
|
25 | + public function getReflection(): ?Reflection\Adapter\ReflectionMethod |
|
26 | + { |
|
27 | + if ($this->reflectionFunction instanceof Reflection\Adapter\ReflectionMethod) { |
|
28 | + return $this->reflectionFunction; |
|
29 | + } |
|
30 | 30 | |
31 | - return $this->reflectionFunction instanceof ReflectionMethod |
|
32 | - ? new Reflection\Adapter\ReflectionMethod( |
|
33 | - Reflection\ReflectionMethod::createFromName( |
|
34 | - $this->reflectionFunction->getDeclaringClass()->getName(), |
|
35 | - $this->reflectionFunction->getName() |
|
36 | - ) |
|
37 | - ) |
|
38 | - : null; |
|
39 | - } |
|
40 | - } |
|
31 | + return $this->reflectionFunction instanceof ReflectionMethod |
|
32 | + ? new Reflection\Adapter\ReflectionMethod( |
|
33 | + Reflection\ReflectionMethod::createFromName( |
|
34 | + $this->reflectionFunction->getDeclaringClass()->getName(), |
|
35 | + $this->reflectionFunction->getName() |
|
36 | + ) |
|
37 | + ) |
|
38 | + : null; |
|
39 | + } |
|
40 | + } |
|
41 | 41 | } |
@@ -14,39 +14,39 @@ |
||
14 | 14 | use Symfony\Component\Translation\MessageCatalogueInterface; |
15 | 15 | |
16 | 16 | if (!class_exists(LazyTranslator::class, false)) { |
17 | - class LazyTranslator extends AbstractTranslator implements TranslatorStrongTypeInterface |
|
18 | - { |
|
19 | - public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string |
|
20 | - { |
|
21 | - return $this->translate($id, $parameters, $domain, $locale); |
|
22 | - } |
|
23 | - |
|
24 | - public function getFromCatalogue(MessageCatalogueInterface $catalogue, string $id, string $domain = 'messages') |
|
25 | - { |
|
26 | - $messages = $this->getPrivateProperty($catalogue, 'messages'); |
|
27 | - |
|
28 | - if (isset($messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id])) { |
|
29 | - return $messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id]; |
|
30 | - } |
|
31 | - |
|
32 | - if (isset($messages[$domain][$id])) { |
|
33 | - return $messages[$domain][$id]; |
|
34 | - } |
|
35 | - |
|
36 | - $fallbackCatalogue = $this->getPrivateProperty($catalogue, 'fallbackCatalogue'); |
|
37 | - |
|
38 | - if ($fallbackCatalogue !== null) { |
|
39 | - return $this->getFromCatalogue($fallbackCatalogue, $id, $domain); |
|
40 | - } |
|
41 | - |
|
42 | - return $id; |
|
43 | - } |
|
44 | - |
|
45 | - private function getPrivateProperty($instance, string $field) |
|
46 | - { |
|
47 | - return (function (string $field) { |
|
48 | - return $this->$field; |
|
49 | - })->call($instance, $field); |
|
50 | - } |
|
51 | - } |
|
17 | + class LazyTranslator extends AbstractTranslator implements TranslatorStrongTypeInterface |
|
18 | + { |
|
19 | + public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string |
|
20 | + { |
|
21 | + return $this->translate($id, $parameters, $domain, $locale); |
|
22 | + } |
|
23 | + |
|
24 | + public function getFromCatalogue(MessageCatalogueInterface $catalogue, string $id, string $domain = 'messages') |
|
25 | + { |
|
26 | + $messages = $this->getPrivateProperty($catalogue, 'messages'); |
|
27 | + |
|
28 | + if (isset($messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id])) { |
|
29 | + return $messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id]; |
|
30 | + } |
|
31 | + |
|
32 | + if (isset($messages[$domain][$id])) { |
|
33 | + return $messages[$domain][$id]; |
|
34 | + } |
|
35 | + |
|
36 | + $fallbackCatalogue = $this->getPrivateProperty($catalogue, 'fallbackCatalogue'); |
|
37 | + |
|
38 | + if ($fallbackCatalogue !== null) { |
|
39 | + return $this->getFromCatalogue($fallbackCatalogue, $id, $domain); |
|
40 | + } |
|
41 | + |
|
42 | + return $id; |
|
43 | + } |
|
44 | + |
|
45 | + private function getPrivateProperty($instance, string $field) |
|
46 | + { |
|
47 | + return (function (string $field) { |
|
48 | + return $this->$field; |
|
49 | + })->call($instance, $field); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -44,7 +44,7 @@ |
||
44 | 44 | |
45 | 45 | private function getPrivateProperty($instance, string $field) |
46 | 46 | { |
47 | - return (function (string $field) { |
|
47 | + return (function(string $field) { |
|
48 | 48 | return $this->$field; |
49 | 49 | })->call($instance, $field); |
50 | 50 | } |
@@ -15,5 +15,5 @@ |
||
15 | 15 | |
16 | 16 | interface CarbonConverterInterface |
17 | 17 | { |
18 | - public function convertDate(DateTimeInterface $dateTime, bool $negated = false): CarbonInterface; |
|
18 | + public function convertDate(DateTimeInterface $dateTime, bool $negated = false): CarbonInterface; |
|
19 | 19 | } |
@@ -17,83 +17,83 @@ |
||
17 | 17 | |
18 | 18 | class TranslatorImmutable extends Translator |
19 | 19 | { |
20 | - /** @var bool */ |
|
21 | - private $constructed = false; |
|
22 | - |
|
23 | - public function __construct($locale, MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false) |
|
24 | - { |
|
25 | - parent::__construct($locale, $formatter, $cacheDir, $debug); |
|
26 | - $this->constructed = true; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @codeCoverageIgnore |
|
31 | - */ |
|
32 | - public function setDirectories(array $directories) |
|
33 | - { |
|
34 | - $this->disallowMutation(__METHOD__); |
|
35 | - |
|
36 | - return parent::setDirectories($directories); |
|
37 | - } |
|
38 | - |
|
39 | - public function setLocale($locale) |
|
40 | - { |
|
41 | - $this->disallowMutation(__METHOD__); |
|
42 | - |
|
43 | - return parent::setLocale($locale); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @codeCoverageIgnore |
|
48 | - */ |
|
49 | - public function setMessages($locale, $messages) |
|
50 | - { |
|
51 | - $this->disallowMutation(__METHOD__); |
|
52 | - |
|
53 | - return parent::setMessages($locale, $messages); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @codeCoverageIgnore |
|
58 | - */ |
|
59 | - public function setTranslations($messages) |
|
60 | - { |
|
61 | - $this->disallowMutation(__METHOD__); |
|
62 | - |
|
63 | - return parent::setTranslations($messages); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @codeCoverageIgnore |
|
68 | - */ |
|
69 | - public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) |
|
70 | - { |
|
71 | - $this->disallowMutation(__METHOD__); |
|
72 | - |
|
73 | - parent::setConfigCacheFactory($configCacheFactory); |
|
74 | - } |
|
75 | - |
|
76 | - public function resetMessages($locale = null) |
|
77 | - { |
|
78 | - $this->disallowMutation(__METHOD__); |
|
79 | - |
|
80 | - return parent::resetMessages($locale); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @codeCoverageIgnore |
|
85 | - */ |
|
86 | - public function setFallbackLocales(array $locales) |
|
87 | - { |
|
88 | - $this->disallowMutation(__METHOD__); |
|
89 | - |
|
90 | - parent::setFallbackLocales($locales); |
|
91 | - } |
|
92 | - |
|
93 | - private function disallowMutation($method) |
|
94 | - { |
|
95 | - if ($this->constructed) { |
|
96 | - throw new ImmutableException($method.' not allowed on '.static::class); |
|
97 | - } |
|
98 | - } |
|
20 | + /** @var bool */ |
|
21 | + private $constructed = false; |
|
22 | + |
|
23 | + public function __construct($locale, MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false) |
|
24 | + { |
|
25 | + parent::__construct($locale, $formatter, $cacheDir, $debug); |
|
26 | + $this->constructed = true; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @codeCoverageIgnore |
|
31 | + */ |
|
32 | + public function setDirectories(array $directories) |
|
33 | + { |
|
34 | + $this->disallowMutation(__METHOD__); |
|
35 | + |
|
36 | + return parent::setDirectories($directories); |
|
37 | + } |
|
38 | + |
|
39 | + public function setLocale($locale) |
|
40 | + { |
|
41 | + $this->disallowMutation(__METHOD__); |
|
42 | + |
|
43 | + return parent::setLocale($locale); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @codeCoverageIgnore |
|
48 | + */ |
|
49 | + public function setMessages($locale, $messages) |
|
50 | + { |
|
51 | + $this->disallowMutation(__METHOD__); |
|
52 | + |
|
53 | + return parent::setMessages($locale, $messages); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @codeCoverageIgnore |
|
58 | + */ |
|
59 | + public function setTranslations($messages) |
|
60 | + { |
|
61 | + $this->disallowMutation(__METHOD__); |
|
62 | + |
|
63 | + return parent::setTranslations($messages); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @codeCoverageIgnore |
|
68 | + */ |
|
69 | + public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) |
|
70 | + { |
|
71 | + $this->disallowMutation(__METHOD__); |
|
72 | + |
|
73 | + parent::setConfigCacheFactory($configCacheFactory); |
|
74 | + } |
|
75 | + |
|
76 | + public function resetMessages($locale = null) |
|
77 | + { |
|
78 | + $this->disallowMutation(__METHOD__); |
|
79 | + |
|
80 | + return parent::resetMessages($locale); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @codeCoverageIgnore |
|
85 | + */ |
|
86 | + public function setFallbackLocales(array $locales) |
|
87 | + { |
|
88 | + $this->disallowMutation(__METHOD__); |
|
89 | + |
|
90 | + parent::setFallbackLocales($locales); |
|
91 | + } |
|
92 | + |
|
93 | + private function disallowMutation($method) |
|
94 | + { |
|
95 | + if ($this->constructed) { |
|
96 | + throw new ImmutableException($method.' not allowed on '.static::class); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
@@ -11,14 +11,14 @@ |
||
11 | 11 | |
12 | 12 | class DateTimeImmutableType extends VarDateTimeImmutableType implements CarbonDoctrineType |
13 | 13 | { |
14 | - /** @use CarbonTypeConverter<CarbonImmutable> */ |
|
15 | - use CarbonTypeConverter; |
|
14 | + /** @use CarbonTypeConverter<CarbonImmutable> */ |
|
15 | + use CarbonTypeConverter; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return class-string<CarbonImmutable> |
|
19 | - */ |
|
20 | - protected function getCarbonClassName(): string |
|
21 | - { |
|
22 | - return CarbonImmutable::class; |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return class-string<CarbonImmutable> |
|
19 | + */ |
|
20 | + protected function getCarbonClassName(): string |
|
21 | + { |
|
22 | + return CarbonImmutable::class; |
|
23 | + } |
|
24 | 24 | } |
@@ -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 | } |