Skip to content

Commit 94fc28b

Browse files
committed
Apply code style
1 parent be4fd74 commit 94fc28b

File tree

104 files changed

+984
-851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+984
-851
lines changed

psalm-baseline.xml

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.

src/Compiler.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Cycle\Schema\Exception\TableInheritance\DiscriminatorColumnNotPresentException;
1616
use Cycle\Schema\Exception\TableInheritance\WrongDiscriminatorColumnException;
1717
use Cycle\Schema\Exception\TableInheritance\WrongParentKeyColumnException;
18-
use Throwable;
1918

2019
final class Compiler
2120
{
@@ -37,8 +36,8 @@ public function compile(Registry $registry, array $generators = [], array $defau
3736
sprintf(
3837
'Invalid generator `%s`. It should implement `%s` interface.',
3938
\is_object($generator) ? $generator::class : \var_export($generator, true),
40-
GeneratorInterface::class
41-
)
39+
GeneratorInterface::class,
40+
),
4241
);
4342
}
4443

@@ -126,16 +125,16 @@ private function compute(Registry $registry, Entity $entity): void
126125
\assert($modifier instanceof SchemaModifierInterface);
127126
try {
128127
$modifier->modifySchema($schema);
129-
} catch (Throwable $e) {
128+
} catch (\Throwable $e) {
130129
throw new SchemaModifierException(
131130
sprintf(
132131
'Unable to apply schema modifier `%s` for the `%s` role. %s',
133132
$modifier::class,
134133
$role,
135-
$e->getMessage()
134+
$e->getMessage(),
136135
),
137-
(int)$e->getCode(),
138-
$e
136+
(int) $e->getCode(),
137+
$e,
139138
);
140139
}
141140
}
@@ -172,11 +171,11 @@ private function renderColumns(Entity $entity): array
172171
}
173172
try {
174173
$comparator->compare();
175-
} catch (Throwable $e) {
174+
} catch (\Throwable $e) {
176175
throw new Exception\CompilerException(sprintf(
177176
"Error compiling the `%s` role.\n\n%s",
178177
$entity->getRole() ?? 'unknown',
179-
$e->getMessage()
178+
$e->getMessage(),
180179
), (int) $e->getCode());
181180
}
182181
}

src/Defaults.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public function __construct(
2424
SchemaInterface::SOURCE => Source::class,
2525
SchemaInterface::SCOPE => null,
2626
SchemaInterface::TYPECAST_HANDLER => null,
27-
]
28-
) {
29-
}
27+
],
28+
) {}
3029

3130
/**
3231
* @param array<int, mixed> $defaults

src/Definition/Comparator/FieldComparator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
namespace Cycle\Schema\Definition\Comparator;
66

77
use Cycle\Schema\Definition\Field;
8-
use Exception;
9-
use InvalidArgumentException;
108

119
final class FieldComparator
1210
{
1311
private $columnName;
12+
1413
/** @var Field[] */
1514
private $fields = [];
1615

@@ -20,7 +19,7 @@ public function addField(string $key, Field $field): self
2019
$this->columnName = $field->getColumn();
2120
}
2221
if ($this->columnName !== $field->getColumn()) {
23-
throw new InvalidArgumentException('The field comparator only accepts fields with the same column name.');
22+
throw new \InvalidArgumentException('The field comparator only accepts fields with the same column name.');
2423
}
2524
$this->fields[$key] = $field;
2625
return $this;
@@ -33,9 +32,9 @@ public function compare(): void
3332
}
3433
// Check options
3534
if (!$this->compareOptions() || !$this->compareProperties()) {
36-
throw new Exception(
35+
throw new \Exception(
3736
"Different definitions are specified for the `$this->columnName` column:"
38-
. "\n\n{$this->generateErrorText()}"
37+
. "\n\n{$this->generateErrorText()}",
3938
);
4039
}
4140
}

src/Definition/Entity.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ final class Entity
7070
private array|string|null $typecast = null;
7171

7272
private array $schema = [];
73-
7473
private FieldMap $fields;
75-
7674
private RelationMap $relations;
7775
private FieldMap $primaryFields;
7876
private array $schemaModifiers = [];
7977
private ?Inheritance $inheritance = null;
78+
8079
/** @var class-string|null */
8180
private ?string $stiParent = null;
81+
8282
private ForeignKeyMap $foreignKeys;
8383

8484
public function __construct()
@@ -90,18 +90,6 @@ public function __construct()
9090
$this->foreignKeys = new ForeignKeyMap();
9191
}
9292

93-
/**
94-
* Full entity copy.
95-
*/
96-
public function __clone()
97-
{
98-
$this->options = clone $this->options;
99-
$this->fields = clone $this->fields;
100-
$this->primaryFields = clone $this->primaryFields;
101-
$this->relations = clone $this->relations;
102-
$this->foreignKeys = clone $this->foreignKeys;
103-
}
104-
10593
public function getOptions(): OptionMap
10694
{
10795
return $this->options;
@@ -253,7 +241,7 @@ public function getForeignKeys(): ForeignKeyMap
253241
public function addSchemaModifier(SchemaModifierInterface $modifier): self
254242
{
255243
$this->schemaModifiers[] = $modifier->withRole($this->role ?? throw new EntityException(
256-
'Entity must have a `role` to be able to add a modifier.'
244+
'Entity must have a `role` to be able to add a modifier.',
257245
));
258246

259247
return $this;
@@ -364,25 +352,6 @@ public function getPrimaryFields(): FieldMap
364352
return $this->primaryFields;
365353
}
366354

367-
/**
368-
* @template T of object
369-
*
370-
* @param class-string<T>|null $class
371-
*
372-
* @return ($class is class-string<T> ? class-string<T> : null)
373-
*/
374-
private function normalizeClass(string $class = null): ?string
375-
{
376-
if ($class === null) {
377-
return null;
378-
}
379-
380-
/** @var class-string<T> $class */
381-
$class = \ltrim($class, '\\');
382-
383-
return $class;
384-
}
385-
386355
public function setInheritance(Inheritance $inheritance): void
387356
{
388357
$this->inheritance = $inheritance;
@@ -434,4 +403,35 @@ public function setTableName(string $tableName): void
434403
{
435404
$this->tableName = $tableName;
436405
}
406+
407+
/**
408+
* Full entity copy.
409+
*/
410+
public function __clone()
411+
{
412+
$this->options = clone $this->options;
413+
$this->fields = clone $this->fields;
414+
$this->primaryFields = clone $this->primaryFields;
415+
$this->relations = clone $this->relations;
416+
$this->foreignKeys = clone $this->foreignKeys;
417+
}
418+
419+
/**
420+
* @template T of object
421+
*
422+
* @param class-string<T>|null $class
423+
*
424+
* @return ($class is class-string<T> ? class-string<T> : null)
425+
*/
426+
private function normalizeClass(?string $class = null): ?string
427+
{
428+
if ($class === null) {
429+
return null;
430+
}
431+
432+
/** @var class-string<T> $class */
433+
$class = \ltrim($class, '\\');
434+
435+
return $class;
436+
}
437437
}

src/Definition/Field.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ final class Field
3434
private array|string|null $typecast = null;
3535

3636
private ?int $generated = null;
37-
3837
private bool $referenced = false;
3938
private ?string $entityClass = null;
4039

@@ -44,12 +43,6 @@ public function __construct()
4443
$this->attributes = new OptionMap();
4544
}
4645

47-
public function __clone()
48-
{
49-
$this->options = clone $this->options;
50-
$this->attributes = clone $this->attributes;
51-
}
52-
5346
public function getOptions(): OptionMap
5447
{
5548
return $this->options;
@@ -105,9 +98,9 @@ public function setColumn(string $column): self
10598
}
10699

107100
/**
101+
* @return non-empty-string
108102
* @throws FieldException
109103
*
110-
* @return non-empty-string
111104
*/
112105
public function getColumn(): string
113106
{
@@ -179,4 +172,10 @@ public function setEntityClass(?string $entityClass): self
179172

180173
return $this;
181174
}
175+
176+
public function __clone()
177+
{
178+
$this->options = clone $this->options;
179+
$this->attributes = clone $this->attributes;
180+
}
182181
}

src/Definition/Inheritance.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace Cycle\Schema\Definition;
66

7-
abstract class Inheritance
8-
{
9-
}
7+
abstract class Inheritance {}

src/Definition/Inheritance/JoinedTable.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ final class JoinedTable extends Inheritance
1111
{
1212
public function __construct(
1313
private Entity $parent,
14-
private ?string $outerKey = null
15-
) {
16-
}
14+
private ?string $outerKey = null,
15+
) {}
1716

1817
public function getOuterKey(): ?string
1918
{

src/Definition/Inheritance/SingleTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final class SingleTable extends Inheritance
1010
{
1111
/** @var array<non-empty-string, class-string> */
1212
private array $children = [];
13+
1314
private ?string $discriminator = null;
1415

1516
/**

src/Definition/Map/FieldMap.php

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Cycle\Schema\Definition\Field;
88
use Cycle\Schema\Exception\FieldException;
9-
use Traversable;
109

1110
/**
1211
* Manage the set of fields associated with the entity.
@@ -18,19 +17,6 @@ final class FieldMap implements \IteratorAggregate, \Countable
1817
/** @var Field[] */
1918
private $fields = [];
2019

21-
/**
22-
* Cloning.
23-
*/
24-
public function __clone()
25-
{
26-
foreach ($this->fields as $name => $field) {
27-
$this->fields[$name] = clone $field;
28-
}
29-
}
30-
31-
/**
32-
* @return int
33-
*/
3420
public function count(): int
3521
{
3622
return count($this->fields);
@@ -54,11 +40,6 @@ public function getNames(): array
5440
return array_keys($this->fields);
5541
}
5642

57-
/**
58-
* @param string $name
59-
*
60-
* @return bool
61-
*/
6243
public function has(string $name): bool
6344
{
6445
return isset($this->fields[$name]);
@@ -118,12 +99,6 @@ public function getByColumnName(string $name): Field
11899
throw new FieldException("Undefined field with column name `{$name}`.");
119100
}
120101

121-
/**
122-
* @param string $name
123-
* @param Field $field
124-
*
125-
* @return FieldMap
126-
*/
127102
public function set(string $name, Field $field): self
128103
{
129104
if ($this->has($name)) {
@@ -135,19 +110,24 @@ public function set(string $name, Field $field): self
135110
return $this;
136111
}
137112

138-
/**
139-
* @param string $name
140-
*
141-
* @return FieldMap
142-
*/
143113
public function remove(string $name): self
144114
{
145115
unset($this->fields[$name]);
146116
return $this;
147117
}
148118

149-
public function getIterator(): Traversable
119+
public function getIterator(): \Traversable
150120
{
151121
return new \ArrayIterator($this->fields);
152122
}
123+
124+
/**
125+
* Cloning.
126+
*/
127+
public function __clone()
128+
{
129+
foreach ($this->fields as $name => $field) {
130+
$this->fields[$name] = clone $field;
131+
}
132+
}
153133
}

0 commit comments

Comments
 (0)