@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private static function registerCallback(string $alias, string $class, callable $callback, callable $sql): void |
63 | 63 | { |
64 | - if(static::hasType($alias)) { |
|
64 | + if (static::hasType($alias)) { |
|
65 | 65 | throw new \LogicException(sprintf('Alias `%s` was already registered in PlatenumDoctrineType.', $class)); |
66 | 66 | } |
67 | - if(false === in_array(EnumTrait::class, static::allTraitsOf($class))) { |
|
67 | + if (false === in_array(EnumTrait::class, static::allTraitsOf($class))) { |
|
68 | 68 | throw new \LogicException(sprintf('PlatenumDoctrineType allows only Platenum enumerations, `%s` given.', $class)); |
69 | 69 | } |
70 | 70 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $traits = []; |
88 | 88 | |
89 | 89 | do { |
90 | - foreach(class_uses($class, true) as $fqcn) { |
|
90 | + foreach (class_uses($class, true) as $fqcn) { |
|
91 | 91 | $traits[] = $fqcn; |
92 | 92 | } |
93 | - } while($class = get_parent_class($class)); |
|
93 | + } while ($class = get_parent_class($class)); |
|
94 | 94 | |
95 | 95 | foreach ($traits as $trait => $same) { |
96 | - foreach(class_uses($same, true) as $fqcn) { |
|
96 | + foreach (class_uses($same, true) as $fqcn) { |
|
97 | 97 | $traits[] = $fqcn; |
98 | 98 | } |
99 | 99 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | { |
16 | 16 | $class = static::class; |
17 | 17 | $doc = (new \ReflectionClass($class))->getDocComment(); |
18 | - if(false === $doc) { |
|
18 | + if (false === $doc) { |
|
19 | 19 | throw PlatenumException::fromMissingDocblock($class); |
20 | 20 | } |
21 | 21 | |
22 | - if(\preg_match_all('~^\s+\*\s+@method\s+static\s+(?:self|static)\s+(?<key>\w+)\(\)$~m', $doc, $matches) < 1) { |
|
22 | + if (\preg_match_all('~^\s+\*\s+@method\s+static\s+(?:self|static)\s+(?<key>\w+)\(\)$~m', $doc, $matches) < 1) { |
|
23 | 23 | throw PlatenumException::fromEmptyDocblock($class); |
24 | 24 | } |
25 | 25 | /** @var array<string,array<int,string>> $matches */ |
26 | 26 | $matches = $matches; |
27 | - if(\count($matches['key']) !== substr_count($doc, '@method')) { |
|
27 | + if (\count($matches['key']) !== substr_count($doc, '@method')) { |
|
28 | 28 | throw PlatenumException::fromMalformedDocblock($class); |
29 | 29 | } |
30 | 30 | |
31 | 31 | $values = []; |
32 | 32 | /** @var array<string,array<int,string>> $matches */ |
33 | - foreach($matches['key'] as $key) { |
|
33 | + foreach ($matches['key'] as $key) { |
|
34 | 34 | $values[$key] = $key; |
35 | 35 | } |
36 | 36 |
@@ -16,7 +16,7 @@ |
||
16 | 16 | $class = static::class; |
17 | 17 | // reflection instead of property_exists because of PHP 7.4 bug #78632 |
18 | 18 | // @see https://bugs.php.net/bug.php?id=78632 |
19 | - if(false === (new \ReflectionClass($class))->hasProperty('mapping')) { |
|
19 | + if (false === (new \ReflectionClass($class))->hasProperty('mapping')) { |
|
20 | 20 | throw PlatenumException::fromMissingMappingProperty($class); |
21 | 21 | } |
22 | 22 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** @param callable():array<string,int|string> $callback */ |
18 | 18 | final public static function initialize(callable $callback): void |
19 | 19 | { |
20 | - if(array_key_exists(static::class, static::$callbacks)) { |
|
20 | + if (array_key_exists(static::class, static::$callbacks)) { |
|
21 | 21 | throw PlatenumException::fromAlreadyInitializedCallback(static::class); |
22 | 22 | } |
23 | 23 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | final private static function resolve(): array |
28 | 28 | { |
29 | 29 | $class = static::class; |
30 | - if(false === (array_key_exists($class, static::$callbacks) && is_callable(static::$callbacks[$class]))) { |
|
30 | + if (false === (array_key_exists($class, static::$callbacks) && is_callable(static::$callbacks[$class]))) { |
|
31 | 31 | throw PlatenumException::fromInvalidCallback($class); |
32 | 32 | } |
33 | 33 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | final public static function __callStatic(string $member, array $arguments) |
32 | 32 | { |
33 | 33 | $class = static::class; |
34 | - if($arguments) { |
|
34 | + if ($arguments) { |
|
35 | 35 | throw PlatenumException::fromConstantArguments($class); |
36 | 36 | } |
37 | 37 | |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | final public static function fromMember(string $member): self |
42 | 42 | { |
43 | 43 | $class = static::class; |
44 | - if(isset(static::$instances[$class][$member])) { |
|
44 | + if (isset(static::$instances[$class][$member])) { |
|
45 | 45 | return static::$instances[$class][$member]; |
46 | 46 | } |
47 | 47 | |
48 | 48 | static::resolveMembers(); |
49 | - if(false === array_key_exists($member, static::$members[$class])) { |
|
49 | + if (false === array_key_exists($member, static::$members[$class])) { |
|
50 | 50 | static::throwInvalidMemberException($member); |
51 | 51 | static::throwDefaultInvalidMemberException($member); |
52 | 52 | } |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | final public static function fromValue($value): self |
63 | 63 | { |
64 | 64 | $class = static::class; |
65 | - if(false === is_scalar($value)) { |
|
65 | + if (false === is_scalar($value)) { |
|
66 | 66 | throw PlatenumException::fromIllegalValue($class, $value); |
67 | 67 | } |
68 | 68 | |
69 | 69 | static::resolveMembers(); |
70 | 70 | $member = array_search($value, static::$members[$class], true); |
71 | - if(false === $member) { |
|
71 | + if (false === $member) { |
|
72 | 72 | static::throwInvalidValueException($value); |
73 | 73 | static::throwDefaultInvalidValueException($value); |
74 | 74 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | final public static function fromEnum($enum): self |
85 | 85 | { |
86 | - if(false === $enum instanceof static) { |
|
86 | + if (false === $enum instanceof static) { |
|
87 | 87 | throw PlatenumException::fromMismatchedClass(static::class, \get_class($enum)); |
88 | 88 | } |
89 | 89 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | /** @return int|string */ |
186 | 186 | final public static function memberToValue(string $member) |
187 | 187 | { |
188 | - if(false === static::memberExists($member)) { |
|
188 | + if (false === static::memberExists($member)) { |
|
189 | 189 | static::throwInvalidMemberException($member); |
190 | 190 | static::throwDefaultInvalidMemberException($member); |
191 | 191 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | /** @param int|string $value */ |
197 | 197 | final public static function valueToMember($value): string |
198 | 198 | { |
199 | - if(false === static::valueExists($value)) { |
|
199 | + if (false === static::valueExists($value)) { |
|
200 | 200 | static::throwInvalidValueException($value); |
201 | 201 | static::throwDefaultInvalidValueException($value); |
202 | 202 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | final private static function resolveMembers(): void |
231 | 231 | { |
232 | 232 | $class = static::class; |
233 | - if(isset(static::$members[$class])) { |
|
233 | + if (isset(static::$members[$class])) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
@@ -242,17 +242,17 @@ discard block |
||
242 | 242 | $hasResolve = (new \ReflectionClass($class))->hasMethod('resolve'); |
243 | 243 | /** @var array<string,int|string> $members */ |
244 | 244 | $members = $hasResolve ? static::resolve() : $throwMissingResolve($class); |
245 | - if(empty($members)) { |
|
245 | + if (empty($members)) { |
|
246 | 246 | throw PlatenumException::fromEmptyMembers($class); |
247 | 247 | } |
248 | - if(\count($members) !== \count(\array_unique($members))) { |
|
248 | + if (\count($members) !== \count(\array_unique($members))) { |
|
249 | 249 | throw PlatenumException::fromNonUniqueMembers($class); |
250 | 250 | } |
251 | 251 | /** @psalm-suppress RedundantCondition */ |
252 | - if(['string'] !== \array_unique(\array_map('gettype', array_keys($members)))) { |
|
252 | + if (['string'] !== \array_unique(\array_map('gettype', array_keys($members)))) { |
|
253 | 253 | throw PlatenumException::fromNonStringMembers($class); |
254 | 254 | } |
255 | - if(1 !== \count(\array_unique(\array_map('gettype', $members)))) { |
|
255 | + if (1 !== \count(\array_unique(\array_map('gettype', $members)))) { |
|
256 | 256 | throw PlatenumException::fromNonUniformMemberValues($class, $members); |
257 | 257 | } |
258 | 258 |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | $this->writeln('Platenum (c) 2019 Tomasz Kowalczyk.'); |
33 | 33 | $this->writeln(''); |
34 | 34 | |
35 | - if($argc < 4) { |
|
35 | + if ($argc < 4) { |
|
36 | 36 | $this->writeln('usage: bin/generate <source> <class> MEMBER=value,MEMBER=value,...'); |
37 | 37 | $this->writeln('examples: bin/generate constants UserStatus ACTIVE=1,INACTIVE=2'); |
38 | 38 | $this->writeln(' bin/generate docblock PaymentType INTERNAL,EXTERNAL'); |
39 | 39 | $this->writeln(' bin/generate static "Project\\Namespace\\Currency" PLN=10,EUR=12,USD=14'); |
40 | 40 | exit(1); |
41 | 41 | } |
42 | - if(false === in_array($argv[1], ['constants', 'docblock', 'static'], true)) { |
|
42 | + if (false === in_array($argv[1], ['constants', 'docblock', 'static'], true)) { |
|
43 | 43 | $this->writeln(sprintf('Unrecognized type `%s`. Allowed: `%s`.', $argv[1], 'constants,docblock,static')); |
44 | 44 | exit(1); |
45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $path = $this->computeClassPath($argv[2]); |
48 | 48 | $code = $this->generateClassCode($argv[1], $argv[2], $argv[3]); |
49 | 49 | |
50 | - if(file_exists($path)) { |
|
50 | + if (file_exists($path)) { |
|
51 | 51 | $this->writeln("\e[0;31mFile already exists.\e[0m"); |
52 | 52 | return; |
53 | 53 | } |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | |
62 | 62 | private function writeFile(string $path, string $content): void |
63 | 63 | { |
64 | - if(!$path) { |
|
64 | + if (!$path) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | 68 | $directory = \dirname($path); |
69 | - if(!file_exists($directory) && !\mkdir($directory, 0777, true) && !\is_dir($directory)) { |
|
69 | + if (!file_exists($directory) && !\mkdir($directory, 0777, true) && !\is_dir($directory)) { |
|
70 | 70 | throw new PlatenumException(sprintf('Failed to create target directory `%s`.', $directory)); |
71 | 71 | } |
72 | 72 | |
73 | 73 | $bytes = file_put_contents($path, $content); |
74 | - if($bytes !== \strlen($content)) { |
|
74 | + if ($bytes !== \strlen($content)) { |
|
75 | 75 | throw new PlatenumException(sprintf('Failed to write target file at path `%s`.', $path)); |
76 | 76 | } |
77 | 77 | } |
@@ -84,15 +84,15 @@ discard block |
||
84 | 84 | * @var string $ns |
85 | 85 | * @var string[] $paths |
86 | 86 | */ |
87 | - foreach($this->classLoader->getPrefixesPsr4() as $ns => $paths) { |
|
88 | - if(0 === strpos($fqcn, $ns)) { |
|
87 | + foreach ($this->classLoader->getPrefixesPsr4() as $ns => $paths) { |
|
88 | + if (0 === strpos($fqcn, $ns)) { |
|
89 | 89 | $prefix = $ns; |
90 | 90 | $path = (string)realpath($paths[0]); |
91 | 91 | break; |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - if(false === ($prefix && $path)) { |
|
95 | + if (false === ($prefix && $path)) { |
|
96 | 96 | $this->writeln(sprintf("Namespace `\e[0;32m%s\e[0m` is not mapped in Composer autoloader.", $fqcn)); |
97 | 97 | $this->writeln('Generated code will be written below. No files will be written to disk.'); |
98 | 98 | return ''; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $namespace = $lastSlash ? substr($namespace, 0, $lastSlash) : 'X'; |
114 | 114 | |
115 | 115 | preg_match_all('~(?<key>[a-zA-Z]+)(=(?<value>[^,$]+),?)?~', $keys, $matches); |
116 | - if(PREG_NO_ERROR !== preg_last_error()) { |
|
116 | + if (PREG_NO_ERROR !== preg_last_error()) { |
|
117 | 117 | throw new PlatenumException(sprintf('Failed to parse keys, `%s`.', preg_last_error())); |
118 | 118 | } |
119 | 119 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | $staticEntries = []; |
124 | 124 | /** @var array<string,array<int,string>> $matches */ |
125 | 125 | $count = \count($matches['key']); |
126 | - for($i = 0; $i < $count; $i++) { |
|
126 | + for ($i = 0; $i < $count; $i++) { |
|
127 | 127 | $key = $matches['key'][$i]; |
128 | 128 | $value = $matches['value'][$i] ?: $index++; |
129 | - if(false === ctype_digit((string)$value)) { |
|
129 | + if (false === ctype_digit((string)$value)) { |
|
130 | 130 | $value = '\''.$value.'\''; |
131 | 131 | } |
132 | 132 | |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | |
138 | 138 | $values = [ |
139 | 139 | 'constants' => ['template' => static::CONSTANTS_TEMPLATE, 'trait' => ConstantsEnumTrait::class, 'members' => implode("\n", $constantsEntries)], |
140 | - 'docblock' => ['template' => static::DOCBLOCK_TEMPLATE, 'trait' => DocblockEnumTrait::class, 'members' => ''], |
|
141 | - 'static' => ['template' => static::STATIC_TEMPLATE, 'trait' => StaticEnumTrait::class, 'members' => implode("\n", $staticEntries)], |
|
140 | + 'docblock' => ['template' => static::DOCBLOCK_TEMPLATE, 'trait' => DocblockEnumTrait::class, 'members' => ''], |
|
141 | + 'static' => ['template' => static::STATIC_TEMPLATE, 'trait' => StaticEnumTrait::class, 'members' => implode("\n", $staticEntries)], |
|
142 | 142 | ]; |
143 | 143 | $replaces = [ |
144 | 144 | '<NS>' => $namespace, |