@@ -25,27 +25,27 @@ public function register($class)
2525 $ isEntity = is_subclass_of ($ class , Entity::class);
2626 $ isRepository = is_subclass_of ($ class , Repository::class);
2727
28- if (!$ isEntity && !$ isRepository ) {
28+ if (!$ isEntity && !$ isRepository ) {
2929 throw new Exception ("Invalid registration " );
3030 }
3131
32- if ($ isEntity ) {
33- if ($ class == Entity::class) {
32+ if ($ isEntity ) {
33+ if ($ class == Entity::class) {
3434 throw new Exception ("Invalid entity registration " );
3535 }
3636 $ this ->entities [] = $ class ;
3737 }
3838
39- if ($ isRepository ) {
40- if ($ class == Repository::class) {
39+ if ($ isRepository ) {
40+ if ($ class == Repository::class) {
4141 throw new Exception ("Invalid repository registration " );
4242 }
4343 $ this ->repositories [] = $ class ;
4444 }
4545
4646 $ space = $ this ->getSpaceName ($ class );
47- if ($ this ->mapper ->getSchema ()->hasSpace ($ space )) {
48- if ($ isEntity ) {
47+ if ($ this ->mapper ->getSchema ()->hasSpace ($ space )) {
48+ if ($ isEntity ) {
4949 $ this ->mapEntity ($ space , $ class );
5050 } else {
5151 $ this ->mapRepository ($ space , $ class );
@@ -60,55 +60,52 @@ public function migrate()
6060
6161 $ schema = $ this ->mapper ->getSchema ();
6262
63- foreach ($ this ->entities as $ entity ) {
64-
63+ foreach ($ this ->entities as $ entity ) {
6564 $ spaceName = $ this ->getSpaceName ($ entity );
6665 $ space = $ schema ->hasSpace ($ spaceName ) ? $ schema ->getSpace ($ spaceName ) : $ schema ->createSpace ($ spaceName );
6766
6867 $ this ->mapEntity ($ spaceName , $ entity );
6968
7069 $ class = new ReflectionClass ($ entity );
7170
72- foreach ($ class ->getProperties (ReflectionProperty::IS_PUBLIC ) as $ property ) {
73-
71+ foreach ($ class ->getProperties (ReflectionProperty::IS_PUBLIC ) as $ property ) {
7472 $ description = $ factory ->create ($ property ->getDocComment ());
7573 $ tags = $ description ->getTags ('var ' );
7674
77- if (!count ($ tags )) {
75+ if (!count ($ tags )) {
7876 throw new Exception ("No var tag for " .$ entity .':: ' .$ property ->getName ());
7977 }
8078
81- if (count ($ tags ) > 1 ) {
79+ if (count ($ tags ) > 1 ) {
8280 throw new Exception ("Invalid var tag for " .$ entity .':: ' .$ property ->getName ());
8381 }
8482
8583 $ property = $ this ->toUnderscore ($ property ->getName ());
8684 $ type = $ this ->getTarantoolType ($ tags [0 ]->getType ());
8785
88- if (!$ space ->hasProperty ($ property )) {
86+ if (!$ space ->hasProperty ($ property )) {
8987 $ space ->addProperty ($ property , $ type );
9088 }
9189 }
9290 }
9391
94- foreach ($ this ->repositories as $ repository ) {
95-
92+ foreach ($ this ->repositories as $ repository ) {
9693 $ spaceName = $ this ->getSpaceName ($ repository );
9794
98- if (!$ schema ->hasSpace ($ spaceName )) {
95+ if (!$ schema ->hasSpace ($ spaceName )) {
9996 throw new Exception ("Repository with no entity definition " );
10097 }
10198
10299 $ this ->mapRepository ($ spaceName , $ repository );
103100
104101 $ space = $ schema ->getSpace ($ spaceName );
105102 $ properties = $ class ->getDefaultProperties ();
106- if (array_key_exists ('indexes ' , $ properties )) {
107- foreach ($ properties ['indexes ' ] as $ index ) {
108- if (!is_array ($ index )) {
103+ if (array_key_exists ('indexes ' , $ properties )) {
104+ foreach ($ properties ['indexes ' ] as $ index ) {
105+ if (!is_array ($ index )) {
109106 $ index = (array ) $ index ;
110107 }
111- if (!array_key_exists ('fields ' , $ index )) {
108+ if (!array_key_exists ('fields ' , $ index )) {
112109 $ index = ['fields ' => $ index ];
113110 }
114111
@@ -118,10 +115,9 @@ public function migrate()
118115 }
119116 }
120117
121- foreach ($ schema ->getSpaces () as $ space ) {
122-
123- if (!count ($ space ->getIndexes ())) {
124- if (!$ space ->hasProperty ('id ' )) {
118+ foreach ($ schema ->getSpaces () as $ space ) {
119+ if (!count ($ space ->getIndexes ())) {
120+ if (!$ space ->hasProperty ('id ' )) {
125121 throw new Exception ("No primary index on " . $ space ->getName ());
126122 }
127123 $ space ->addIndex (['id ' ]);
@@ -146,7 +142,7 @@ public function setRepositoryPostfix($postfix)
146142 public function getRepositoryMapping ()
147143 {
148144 $ mapping = [];
149- foreach ($ this ->repositories as $ class ) {
145+ foreach ($ this ->repositories as $ class ) {
150146 $ mapping [$ this ->getSpaceName ($ class )] = $ class ;
151147 }
152148 return $ mapping ;
@@ -155,7 +151,7 @@ public function getRepositoryMapping()
155151 public function getEntityMapping ()
156152 {
157153 $ mapping = [];
158- foreach ($ this ->entities as $ class ) {
154+ foreach ($ this ->entities as $ class ) {
159155 $ mapping [$ this ->getSpaceName ($ class )] = $ class ;
160156 }
161157 return $ mapping ;
@@ -165,19 +161,18 @@ public function getEntityMapping()
165161
166162 public function getSpaceName ($ class )
167163 {
168- if (!array_key_exists ($ class , $ this ->spaceNames )) {
169-
164+ if (!array_key_exists ($ class , $ this ->spaceNames )) {
170165 $ reflection = new ReflectionClass ($ class );
171166 $ className = $ reflection ->getShortName ();
172167
173- if ($ reflection ->isSubclassOf (Repository::class)) {
174- if ($ this ->repositoryPostifx ) {
168+ if ($ reflection ->isSubclassOf (Repository::class)) {
169+ if ($ this ->repositoryPostifx ) {
175170 $ className = substr ($ className , 0 , strlen ($ className ) - strlen ($ this ->repositoryPostifx ));
176171 }
177172 }
178173
179- if ($ reflection ->isSubclassOf (Entity::class)) {
180- if ($ this ->entityPostfix ) {
174+ if ($ reflection ->isSubclassOf (Entity::class)) {
175+ if ($ this ->entityPostfix ) {
181176 $ className = substr ($ className , 0 , strlen ($ className ) - strlen ($ this ->entityPostfix ));
182177 }
183178 }
@@ -192,7 +187,7 @@ public function getSpaceName($class)
192187
193188 private function toUnderscore ($ input )
194189 {
195- if (!array_key_exists ($ input , $ this ->underscores )) {
190+ if (!array_key_exists ($ input , $ this ->underscores )) {
196191 preg_match_all ('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)! ' , $ input , $ matches );
197192 $ ret = $ matches [0 ];
198193 foreach ($ ret as &$ match ) {
@@ -207,15 +202,15 @@ private function toUnderscore($input)
207202
208203 private function getTarantoolType (string $ type )
209204 {
210- if (array_key_exists ($ type , $ this ->tarantoolTypes )) {
205+ if (array_key_exists ($ type , $ this ->tarantoolTypes )) {
211206 return $ this ->tarantoolTypes [$ type ];
212207 }
213208
214- if ($ type [0 ] == '\\' ) {
209+ if ($ type [0 ] == '\\' ) {
215210 return $ this ->tarantoolTypes [$ type ] = 'unsigned ' ;
216211 }
217212
218- switch ($ type ) {
213+ switch ($ type ) {
219214 case 'int ' :
220215 return $ this ->tarantoolTypes [$ type ] = 'unsigned ' ;
221216
0 commit comments