@@ -120,6 +120,9 @@ |
||
120 | 120 | |
121 | 121 | private $underscores = []; |
122 | 122 | |
123 | + /** |
|
124 | + * @param string $input |
|
125 | + */ |
|
123 | 126 | private function toUnderscore($input) |
124 | 127 | { |
125 | 128 | if(!array_key_exists($input, $this->underscores)) { |
@@ -3,13 +3,10 @@ |
||
3 | 3 | namespace Tarantool\Mapper\Plugins; |
4 | 4 | |
5 | 5 | use Exception; |
6 | - |
|
7 | 6 | use phpDocumentor\Reflection\DocBlockFactory; |
8 | 7 | use ReflectionClass; |
9 | 8 | use ReflectionProperty; |
10 | - |
|
11 | 9 | use Tarantool\Mapper\Entity; |
12 | -use Tarantool\Mapper\Plugin; |
|
13 | 10 | use Tarantool\Mapper\Repository; |
14 | 11 | |
15 | 12 | class DocBlock extends UserClasses |
@@ -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($name, $class); |
48 | 48 | } else { |
49 | 49 | $this->mapRepository($name, $class); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | $schema = $this->mapper->getSchema(); |
59 | 59 | |
60 | - foreach($this->entities as $entity) { |
|
60 | + foreach ($this->entities as $entity) { |
|
61 | 61 | |
62 | 62 | $class = new ReflectionClass($entity); |
63 | 63 | $spaceName = $this->toUnderscore($class->getShortName()); |
@@ -65,34 +65,34 @@ discard block |
||
65 | 65 | $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName); |
66 | 66 | $this->mapEntity($spaceName, $entity); |
67 | 67 | |
68 | - foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
68 | + foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
69 | 69 | |
70 | 70 | $description = $factory->create($property->getDocComment()); |
71 | 71 | $tags = $description->getTags('var'); |
72 | 72 | |
73 | - if(!count($tags)) { |
|
73 | + if (!count($tags)) { |
|
74 | 74 | throw new Exception("No var tag for ".$entity.'::'.$property->getName()); |
75 | 75 | } |
76 | 76 | |
77 | - if(count($tags) > 1) { |
|
77 | + if (count($tags) > 1) { |
|
78 | 78 | throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName()); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $property = $this->toUnderscore($property->getName()); |
82 | 82 | $type = $this->getTarantoolType($tags[0]->getType()); |
83 | 83 | |
84 | - if(!$space->hasProperty($property)) { |
|
84 | + if (!$space->hasProperty($property)) { |
|
85 | 85 | $space->addProperty($property, $type); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - foreach($this->repositories as $repository) { |
|
90 | + foreach ($this->repositories as $repository) { |
|
91 | 91 | |
92 | 92 | $class = new ReflectionClass($repository); |
93 | 93 | $spaceName = $this->toUnderscore($class->getShortName()); |
94 | 94 | |
95 | - if(!$schema->hasSpace($spaceName)) { |
|
95 | + if (!$schema->hasSpace($spaceName)) { |
|
96 | 96 | throw new Exception("Repository with no entity definition"); |
97 | 97 | } |
98 | 98 | |
@@ -100,18 +100,18 @@ discard block |
||
100 | 100 | |
101 | 101 | $space = $schema->getSpace($spaceName); |
102 | 102 | $properties = $class->getDefaultProperties(); |
103 | - if(array_key_exists('indexes', $properties)) { |
|
104 | - foreach($properties['indexes'] as $index) { |
|
103 | + if (array_key_exists('indexes', $properties)) { |
|
104 | + foreach ($properties['indexes'] as $index) { |
|
105 | 105 | $space->addIndex($index); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - foreach($schema->getSpaces() as $space) { |
|
110 | + foreach ($schema->getSpaces() as $space) { |
|
111 | 111 | |
112 | - if(!count($space->getIndexes())) { |
|
113 | - if(!$space->hasProperty('id')) { |
|
114 | - throw new Exception("No primary index on ". $space->getName()); |
|
112 | + if (!count($space->getIndexes())) { |
|
113 | + if (!$space->hasProperty('id')) { |
|
114 | + throw new Exception("No primary index on ".$space->getName()); |
|
115 | 115 | } |
116 | 116 | $space->addIndex(['id']); |
117 | 117 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | private function toUnderscore($input) |
124 | 124 | { |
125 | - if(!array_key_exists($input, $this->underscores)) { |
|
125 | + if (!array_key_exists($input, $this->underscores)) { |
|
126 | 126 | preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); |
127 | 127 | $ret = $matches[0]; |
128 | 128 | foreach ($ret as &$match) { |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | |
138 | 138 | private function getTarantoolType(string $type) |
139 | 139 | { |
140 | - if(array_key_exists($type, $this->tarantoolTypes)) { |
|
140 | + if (array_key_exists($type, $this->tarantoolTypes)) { |
|
141 | 141 | return $this->tarantoolTypes[$type]; |
142 | 142 | } |
143 | 143 | |
144 | - switch($type) { |
|
144 | + switch ($type) { |
|
145 | 145 | case 'int': |
146 | 146 | return $this->tarantoolTypes[$type] = 'unsigned'; |
147 | 147 |