@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | $isEntity = is_subclass_of($class, Entity::class); |
23 | 23 | $isRepository = is_subclass_of($class, Repository::class); |
24 | 24 | |
25 | - if(!$isEntity && !$isRepository) { |
|
25 | + if (!$isEntity && !$isRepository) { |
|
26 | 26 | throw new Exception("Invalid registration"); |
27 | 27 | } |
28 | 28 | |
29 | - if($isEntity) { |
|
30 | - if($class == Entity::class) { |
|
29 | + if ($isEntity) { |
|
30 | + if ($class == Entity::class) { |
|
31 | 31 | throw new Exception("Invalid entity registration"); |
32 | 32 | } |
33 | 33 | $this->entities[] = $class; |
34 | 34 | } |
35 | 35 | |
36 | - if($isRepository) { |
|
37 | - if($class == Repository::class) { |
|
36 | + if ($isRepository) { |
|
37 | + if ($class == Repository::class) { |
|
38 | 38 | throw new Exception("Invalid repository registration"); |
39 | 39 | } |
40 | 40 | $this->repositories[] = $class; |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | $reflection = new ReflectionClass($class); |
44 | 44 | $space = $this->toUnderscore($reflection->getShortName()); |
45 | - if($this->mapper->getSchema()->hasSpace($space)) { |
|
46 | - if($isEntity) { |
|
45 | + if ($this->mapper->getSchema()->hasSpace($space)) { |
|
46 | + if ($isEntity) { |
|
47 | 47 | $this->mapEntity($space, $class); |
48 | 48 | } else { |
49 | 49 | $this->mapRepository($space, $class); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | $schema = $this->mapper->getSchema(); |
60 | 60 | |
61 | - foreach($this->entities as $entity) { |
|
61 | + foreach ($this->entities as $entity) { |
|
62 | 62 | |
63 | 63 | $class = new ReflectionClass($entity); |
64 | 64 | $spaceName = $this->toUnderscore($class->getShortName()); |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName); |
67 | 67 | $this->mapEntity($spaceName, $entity); |
68 | 68 | |
69 | - foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
69 | + foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
70 | 70 | |
71 | 71 | $description = $factory->create($property->getDocComment()); |
72 | 72 | $tags = $description->getTags('var'); |
73 | 73 | |
74 | - if(!count($tags)) { |
|
74 | + if (!count($tags)) { |
|
75 | 75 | throw new Exception("No var tag for ".$entity.'::'.$property->getName()); |
76 | 76 | } |
77 | 77 | |
78 | - if(count($tags) > 1) { |
|
78 | + if (count($tags) > 1) { |
|
79 | 79 | throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName()); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $property = $this->toUnderscore($property->getName()); |
83 | 83 | $type = $this->getTarantoolType($tags[0]->getType()); |
84 | 84 | |
85 | - if(!$space->hasProperty($property)) { |
|
85 | + if (!$space->hasProperty($property)) { |
|
86 | 86 | $space->addProperty($property, $type); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach($this->repositories as $repository) { |
|
91 | + foreach ($this->repositories as $repository) { |
|
92 | 92 | |
93 | 93 | $class = new ReflectionClass($repository); |
94 | 94 | $spaceName = $this->toUnderscore($class->getShortName()); |
95 | 95 | |
96 | - if(!$schema->hasSpace($spaceName)) { |
|
96 | + if (!$schema->hasSpace($spaceName)) { |
|
97 | 97 | throw new Exception("Repository with no entity definition"); |
98 | 98 | } |
99 | 99 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | |
102 | 102 | $space = $schema->getSpace($spaceName); |
103 | 103 | $properties = $class->getDefaultProperties(); |
104 | - if(array_key_exists('indexes', $properties)) { |
|
105 | - foreach($properties['indexes'] as $index) { |
|
106 | - if(!is_array($index)) { |
|
104 | + if (array_key_exists('indexes', $properties)) { |
|
105 | + foreach ($properties['indexes'] as $index) { |
|
106 | + if (!is_array($index)) { |
|
107 | 107 | $index = (array) $index; |
108 | 108 | } |
109 | - if(!array_key_exists('fields', $index)) { |
|
109 | + if (!array_key_exists('fields', $index)) { |
|
110 | 110 | $index = ['fields' => $index]; |
111 | 111 | } |
112 | 112 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - foreach($schema->getSpaces() as $space) { |
|
119 | + foreach ($schema->getSpaces() as $space) { |
|
120 | 120 | |
121 | - if(!count($space->getIndexes())) { |
|
122 | - if(!$space->hasProperty('id')) { |
|
123 | - throw new Exception("No primary index on ". $space->getName()); |
|
121 | + if (!count($space->getIndexes())) { |
|
122 | + if (!$space->hasProperty('id')) { |
|
123 | + throw new Exception("No primary index on ".$space->getName()); |
|
124 | 124 | } |
125 | 125 | $space->addIndex(['id']); |
126 | 126 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | private function toUnderscore($input) |
135 | 135 | { |
136 | - if(!array_key_exists($input, $this->underscores)) { |
|
136 | + if (!array_key_exists($input, $this->underscores)) { |
|
137 | 137 | preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); |
138 | 138 | $ret = $matches[0]; |
139 | 139 | foreach ($ret as &$match) { |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | |
149 | 149 | private function getTarantoolType(string $type) |
150 | 150 | { |
151 | - if(array_key_exists($type, $this->tarantoolTypes)) { |
|
151 | + if (array_key_exists($type, $this->tarantoolTypes)) { |
|
152 | 152 | return $this->tarantoolTypes[$type]; |
153 | 153 | } |
154 | 154 | |
155 | - if($type[0] == '\\') { |
|
155 | + if ($type[0] == '\\') { |
|
156 | 156 | return $this->tarantoolTypes[$type] = 'unsigned'; |
157 | 157 | } |
158 | 158 | |
159 | - switch($type) { |
|
159 | + switch ($type) { |
|
160 | 160 | case 'int': |
161 | 161 | return $this->tarantoolTypes[$type] = 'unsigned'; |
162 | 162 |