Completed
Push — master ( e5f0e8...efdf1e )
by Dmitry
02:54
created
src/Schema.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
         $this->spaces[$id] = new Space($this->mapper, $id, $space);
30 30
 
31
-        if($properties) {
31
+        if ($properties) {
32 32
             $this->spaces[$id]->addProperties($properties);
33 33
         }
34 34
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     public function formatValue($type, $value)
39 39
     {
40
-        switch($type) {
40
+        switch ($type) {
41 41
             case 'str': return (string) $value;
42 42
             case 'unsigned': return (int) $value;
43 43
             default: return $value;
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 
47 47
     public function getSpace($id)
48 48
     {
49
-        if(is_string($id)) {
49
+        if (is_string($id)) {
50 50
             return $this->getSpace($this->getSpaceId($id));
51 51
         }
52 52
 
53
-        if(!$id) {
53
+        if (!$id) {
54 54
             throw new Exception("Space id or name not defined");
55 55
         }
56 56
 
57
-        if(!array_key_exists($id, $this->spaces)) {
57
+        if (!array_key_exists($id, $this->spaces)) {
58 58
             $this->spaces[$id] = new Space($this->mapper, $id, array_search($id, $this->names));
59 59
         }
60 60
         return $this->spaces[$id];
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     public function getSpaceId($name)
64 64
     {
65
-        if(!$this->hasSpace($name)) {
65
+        if (!$this->hasSpace($name)) {
66 66
             throw new Exception("No space $name");
67 67
         }
68 68
         return $this->names[$name];
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
     public function getSpaces()
72 72
     {
73
-        foreach($this->names as $id) {
73
+        foreach ($this->names as $id) {
74 74
             $this->getSpace($id);
75 75
         }
76 76
         return $this->spaces;
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 
84 84
     public function once($name, $callback)
85 85
     {
86
-        $key = 'once' . $name;
86
+        $key = 'once'.$name;
87 87
 
88 88
         $rows = $this->mapper->find('_schema', ['key' => $key]);
89
-        if(!count($rows)) {
89
+        if (!count($rows)) {
90 90
             $this->mapper->create('_schema', ['key' => $key]);
91 91
             return $callback($this->mapper);
92 92
         }
Please login to merge, or discard this patch.
src/Plugins/DocBlock.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,18 +101,18 @@  discard block
 block discarded – undo
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) {
104
+            if (array_key_exists('indexes', $properties)) {
105
+                foreach ($properties['indexes'] as $index) {
106 106
                     $space->addIndex($index);
107 107
                 }
108 108
             }
109 109
         }
110 110
 
111
-        foreach($schema->getSpaces() as $space) {
111
+        foreach ($schema->getSpaces() as $space) {
112 112
 
113
-            if(!count($space->getIndexes())) {
114
-                if(!$space->hasProperty('id')) {
115
-                    throw new Exception("No primary index on ". $space->getName());
113
+            if (!count($space->getIndexes())) {
114
+                if (!$space->hasProperty('id')) {
115
+                    throw new Exception("No primary index on ".$space->getName());
116 116
                 }
117 117
                 $space->addIndex(['id']);
118 118
             }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
     private function toUnderscore($input)
127 127
     {
128
-        if(!array_key_exists($input, $this->underscores)) {
128
+        if (!array_key_exists($input, $this->underscores)) {
129 129
             preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
130 130
             $ret = $matches[0];
131 131
             foreach ($ret as &$match) {
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
 
141 141
     private function getTarantoolType(string $type)
142 142
     {
143
-        if(array_key_exists($type, $this->tarantoolTypes)) {
143
+        if (array_key_exists($type, $this->tarantoolTypes)) {
144 144
             return $this->tarantoolTypes[$type];
145 145
         }
146 146
 
147
-        if($type[0] == '\\') {
147
+        if ($type[0] == '\\') {
148 148
             return $this->tarantoolTypes[$type] = 'unsigned';
149 149
         }
150 150
 
151
-        switch($type) {
151
+        switch ($type) {
152 152
             case 'int':
153 153
                 return $this->tarantoolTypes[$type] = 'unsigned';
154 154
 
Please login to merge, or discard this patch.