Skip to content

Commit 4f4774d

Browse files
committed
cs fixes
1 parent b4d9260 commit 4f4774d

File tree

12 files changed

+189
-193
lines changed

12 files changed

+189
-193
lines changed

src/Bootstrap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public function register($instance)
2020
public function migrate()
2121
{
2222
$schema = $this->mapper->getSchema();
23-
foreach($this->migrations as $migration) {
24-
if(!is_object($migration)) {
23+
foreach ($this->migrations as $migration) {
24+
if (!is_object($migration)) {
2525
$migration = new $migration;
2626
}
27-
$schema->once(get_class($migration), function() use ($migration) {
27+
$schema->once(get_class($migration), function () use ($migration) {
2828
$migration->migrate($this->mapper);
2929
});
3030
}
3131
}
32-
}
32+
}

src/Client.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private function log($start, $class, $request = [], $response = [])
3737
public function getTimeSummary()
3838
{
3939
$summary = 0;
40-
foreach($this->log as $request) {
40+
foreach ($this->log as $request) {
4141
$summary += $request[0];
4242
}
4343
return $summary;
@@ -52,5 +52,4 @@ public function getLog()
5252
{
5353
return $this->log;
5454
}
55-
5655
}

src/Mapper.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(Client $client)
1919

2020
public function addPlugin($class)
2121
{
22-
if(!is_subclass_of($class, Plugin::class)) {
22+
if (!is_subclass_of($class, Plugin::class)) {
2323
throw new Exception("Plugin should extend " . Plugin::class . " class");
2424
}
2525

@@ -48,8 +48,8 @@ public function find($space, $params = [])
4848

4949
public function findRepository(Entity $instance)
5050
{
51-
foreach($this->getSchema()->getSpaces() as $space) {
52-
if($space->getRepository()->knows($instance)) {
51+
foreach ($this->getSchema()->getSpaces() as $space) {
52+
if ($space->getRepository()->knows($instance)) {
5353
return $space->getRepository();
5454
}
5555
}
@@ -69,7 +69,7 @@ public function getClient()
6969

7070
public function getPlugin($class)
7171
{
72-
if(!array_key_exists($class, $this->plugins)) {
72+
if (!array_key_exists($class, $this->plugins)) {
7373
throw new Exception("No plugin $class");
7474
}
7575
return $this->plugins[$class];
@@ -88,8 +88,8 @@ public function getRepository($space)
8888
public function getRepositories()
8989
{
9090
$repositories = [];
91-
foreach($this->getSchema()->getSpaces() as $space) {
92-
if($space->repositoryExists()) {
91+
foreach ($this->getSchema()->getSpaces() as $space) {
92+
if ($space->repositoryExists()) {
9393
$repositories[] = $space->getRepository();
9494
}
9595
}
@@ -103,9 +103,8 @@ public function getSchema()
103103

104104
public function remove($space, $params = [])
105105
{
106-
if($space instanceof Entity) {
106+
if ($space instanceof Entity) {
107107
$this->findRepository($space)->removeEntity($space);
108-
109108
} else {
110109
$this->getRepository($space)->remove($params);
111110
}

src/Migration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
interface Migration
66
{
77
public function migrate(Mapper $mapper);
8-
}
8+
}

src/Plugin.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ public function __construct(Mapper $mapper)
1111
$this->mapper = $mapper;
1212
}
1313

14-
public function getRepositoryClass(Space $space) {}
15-
public function getEntityClass(Space $space) {}
16-
public function generateKey(Entity $instance, Space $space) {}
17-
public function beforeCreate(Entity $instance, Space $space) {}
18-
public function beforeUpdate(Entity $instance, Space $space) {}
19-
public function beforeRemove(Entity $instance, Space $space) {}
14+
public function getRepositoryClass(Space $space)
15+
{
16+
}
17+
public function getEntityClass(Space $space)
18+
{
19+
}
20+
public function generateKey(Entity $instance, Space $space)
21+
{
22+
}
23+
public function beforeCreate(Entity $instance, Space $space)
24+
{
25+
}
26+
public function beforeUpdate(Entity $instance, Space $space)
27+
{
28+
}
29+
public function beforeRemove(Entity $instance, Space $space)
30+
{
31+
}
2032
}

src/Plugins/Annotation.php

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Plugins/Sequence.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Sequence extends Plugin
1111
public function generateKey(Entity $instance, Space $space)
1212
{
1313
$primary = $space->getPrimaryIndex();
14-
if(count($primary->parts) == 1) {
14+
if (count($primary->parts) == 1) {
1515
$key = $space->getFormat()[$primary->parts[0][0]]['name'];
16-
if(!property_exists($instance, $key)) {
16+
if (!property_exists($instance, $key)) {
1717
$instance->$key = $this->generateValue($space);
1818
}
1919
}
@@ -23,17 +23,15 @@ private function generateValue($space)
2323
{
2424
$spaceId = $space->getId();
2525

26-
if(!$this->mapper->getSchema()->hasSpace('sequence')) {
27-
26+
if (!$this->mapper->getSchema()->hasSpace('sequence')) {
2827
$sequence = $this->mapper->getSchema()->createSpace('sequence');
2928
$sequence->addProperty('space', 'unsigned');
3029
$sequence->addProperty('counter', 'unsigned');
3130
$sequence->createIndex('space');
3231
}
3332

3433
$entity = $this->mapper->findOne('sequence', $space->getId());
35-
if(!$entity) {
36-
34+
if (!$entity) {
3735
$query = "return box.space.".$space->getName().".index[0]:max()";
3836
$data = $this->mapper->getClient()->evaluate($query)->getData();
3937
$max = $data ? $data[0][0] : 0;

src/Plugins/Spy.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function beforeCreate(Entity $instance, Space $space)
2020
public function beforeUpdate(Entity $instance, Space $space)
2121
{
2222
$key = $this->getKey($instance, $space);
23-
if(!array_key_exists($key, $this->created)) {
23+
if (!array_key_exists($key, $this->created)) {
2424
$this->updated[$key] = $instance;
2525
}
2626
}
@@ -29,12 +29,12 @@ public function beforeRemove(Entity $instance, Space $space)
2929
{
3030
$key = $this->getKey($instance, $space);
3131

32-
if(array_key_exists($key, $this->created)) {
32+
if (array_key_exists($key, $this->created)) {
3333
unset($this->created[$key]);
3434
return;
3535
}
3636

37-
if(array_key_exists($key, $this->updated)) {
37+
if (array_key_exists($key, $this->updated)) {
3838
unset($this->updated[$key]);
3939
}
4040

@@ -53,7 +53,7 @@ private function getKey(Entity $instance, Space $space)
5353
$key = [$space->getName()];
5454

5555
$format = $space->getFormat();
56-
foreach($space->getPrimaryIndex()->parts as $part) {
56+
foreach ($space->getPrimaryIndex()->parts as $part) {
5757
$key[] = $instance->{$format[$part[0]]['name']};
5858
}
5959

@@ -64,11 +64,11 @@ public function getChanges()
6464
{
6565
$result = (object) [];
6666

67-
foreach(['created', 'updated', 'removed'] as $action) {
67+
foreach (['created', 'updated', 'removed'] as $action) {
6868
$data = [];
69-
foreach($this->$action as $key => $row) {
69+
foreach ($this->$action as $key => $row) {
7070
list($space) = explode(':', $key);
71-
if(!array_key_exists($space, $data)) {
71+
if (!array_key_exists($space, $data)) {
7272
$data[$space] = [];
7373
}
7474
$data[$space][] = $row;

0 commit comments

Comments
 (0)