Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 13, 2024
1 parent be4fd74 commit 94fc28b
Show file tree
Hide file tree
Showing 104 changed files with 984 additions and 851 deletions.
412 changes: 412 additions & 0 deletions psalm-baseline.xml

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Cycle\Schema\Exception\TableInheritance\DiscriminatorColumnNotPresentException;
use Cycle\Schema\Exception\TableInheritance\WrongDiscriminatorColumnException;
use Cycle\Schema\Exception\TableInheritance\WrongParentKeyColumnException;
use Throwable;

final class Compiler
{
Expand All @@ -37,8 +36,8 @@ public function compile(Registry $registry, array $generators = [], array $defau
sprintf(
'Invalid generator `%s`. It should implement `%s` interface.',
\is_object($generator) ? $generator::class : \var_export($generator, true),
GeneratorInterface::class
)
GeneratorInterface::class,
),
);
}

Expand Down Expand Up @@ -126,16 +125,16 @@ private function compute(Registry $registry, Entity $entity): void
\assert($modifier instanceof SchemaModifierInterface);
try {
$modifier->modifySchema($schema);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new SchemaModifierException(
sprintf(
'Unable to apply schema modifier `%s` for the `%s` role. %s',
$modifier::class,
$role,
$e->getMessage()
$e->getMessage(),
),
(int)$e->getCode(),
$e
(int) $e->getCode(),
$e,
);
}
}
Expand Down Expand Up @@ -172,11 +171,11 @@ private function renderColumns(Entity $entity): array
}
try {
$comparator->compare();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new Exception\CompilerException(sprintf(
"Error compiling the `%s` role.\n\n%s",
$entity->getRole() ?? 'unknown',
$e->getMessage()
$e->getMessage(),
), (int) $e->getCode());
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public function __construct(
SchemaInterface::SOURCE => Source::class,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST_HANDLER => null,
]
) {
}
],
) {}

/**
* @param array<int, mixed> $defaults
Expand Down
9 changes: 4 additions & 5 deletions src/Definition/Comparator/FieldComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace Cycle\Schema\Definition\Comparator;

use Cycle\Schema\Definition\Field;
use Exception;
use InvalidArgumentException;

final class FieldComparator
{
private $columnName;

/** @var Field[] */
private $fields = [];

Expand All @@ -20,7 +19,7 @@ public function addField(string $key, Field $field): self
$this->columnName = $field->getColumn();
}
if ($this->columnName !== $field->getColumn()) {
throw new InvalidArgumentException('The field comparator only accepts fields with the same column name.');
throw new \InvalidArgumentException('The field comparator only accepts fields with the same column name.');
}
$this->fields[$key] = $field;
return $this;
Expand All @@ -33,9 +32,9 @@ public function compare(): void
}
// Check options
if (!$this->compareOptions() || !$this->compareProperties()) {
throw new Exception(
throw new \Exception(
"Different definitions are specified for the `$this->columnName` column:"
. "\n\n{$this->generateErrorText()}"
. "\n\n{$this->generateErrorText()}",
);
}
}
Expand Down
68 changes: 34 additions & 34 deletions src/Definition/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ final class Entity
private array|string|null $typecast = null;

private array $schema = [];

private FieldMap $fields;

private RelationMap $relations;
private FieldMap $primaryFields;
private array $schemaModifiers = [];
private ?Inheritance $inheritance = null;

/** @var class-string|null */
private ?string $stiParent = null;

private ForeignKeyMap $foreignKeys;

public function __construct()
Expand All @@ -90,18 +90,6 @@ public function __construct()
$this->foreignKeys = new ForeignKeyMap();
}

/**
* Full entity copy.
*/
public function __clone()
{
$this->options = clone $this->options;
$this->fields = clone $this->fields;
$this->primaryFields = clone $this->primaryFields;
$this->relations = clone $this->relations;
$this->foreignKeys = clone $this->foreignKeys;
}

public function getOptions(): OptionMap
{
return $this->options;
Expand Down Expand Up @@ -253,7 +241,7 @@ public function getForeignKeys(): ForeignKeyMap
public function addSchemaModifier(SchemaModifierInterface $modifier): self
{
$this->schemaModifiers[] = $modifier->withRole($this->role ?? throw new EntityException(
'Entity must have a `role` to be able to add a modifier.'
'Entity must have a `role` to be able to add a modifier.',
));

return $this;
Expand Down Expand Up @@ -364,25 +352,6 @@ public function getPrimaryFields(): FieldMap
return $this->primaryFields;
}

/**
* @template T of object
*
* @param class-string<T>|null $class
*
* @return ($class is class-string<T> ? class-string<T> : null)
*/
private function normalizeClass(string $class = null): ?string
{
if ($class === null) {
return null;
}

/** @var class-string<T> $class */
$class = \ltrim($class, '\\');

return $class;
}

public function setInheritance(Inheritance $inheritance): void
{
$this->inheritance = $inheritance;
Expand Down Expand Up @@ -434,4 +403,35 @@ public function setTableName(string $tableName): void
{
$this->tableName = $tableName;
}

/**
* Full entity copy.
*/
public function __clone()
{
$this->options = clone $this->options;
$this->fields = clone $this->fields;
$this->primaryFields = clone $this->primaryFields;
$this->relations = clone $this->relations;
$this->foreignKeys = clone $this->foreignKeys;
}

/**
* @template T of object
*
* @param class-string<T>|null $class
*
* @return ($class is class-string<T> ? class-string<T> : null)
*/
private function normalizeClass(?string $class = null): ?string
{
if ($class === null) {
return null;
}

/** @var class-string<T> $class */
$class = \ltrim($class, '\\');

return $class;
}
}
15 changes: 7 additions & 8 deletions src/Definition/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ final class Field
private array|string|null $typecast = null;

private ?int $generated = null;

private bool $referenced = false;
private ?string $entityClass = null;

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

public function __clone()
{
$this->options = clone $this->options;
$this->attributes = clone $this->attributes;
}

public function getOptions(): OptionMap
{
return $this->options;
Expand Down Expand Up @@ -105,9 +98,9 @@ public function setColumn(string $column): self
}

/**
* @return non-empty-string
* @throws FieldException
*
* @return non-empty-string
*/
public function getColumn(): string
{
Expand Down Expand Up @@ -179,4 +172,10 @@ public function setEntityClass(?string $entityClass): self

return $this;
}

public function __clone()
{
$this->options = clone $this->options;
$this->attributes = clone $this->attributes;
}
}
4 changes: 1 addition & 3 deletions src/Definition/Inheritance.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Cycle\Schema\Definition;

abstract class Inheritance
{
}
abstract class Inheritance {}
5 changes: 2 additions & 3 deletions src/Definition/Inheritance/JoinedTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ final class JoinedTable extends Inheritance
{
public function __construct(
private Entity $parent,
private ?string $outerKey = null
) {
}
private ?string $outerKey = null,
) {}

public function getOuterKey(): ?string
{
Expand Down
1 change: 1 addition & 0 deletions src/Definition/Inheritance/SingleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final class SingleTable extends Inheritance
{
/** @var array<non-empty-string, class-string> */
private array $children = [];

private ?string $discriminator = null;

/**
Expand Down
42 changes: 11 additions & 31 deletions src/Definition/Map/FieldMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Cycle\Schema\Definition\Field;
use Cycle\Schema\Exception\FieldException;
use Traversable;

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

/**
* Cloning.
*/
public function __clone()
{
foreach ($this->fields as $name => $field) {
$this->fields[$name] = clone $field;
}
}

/**
* @return int
*/
public function count(): int
{
return count($this->fields);
Expand All @@ -54,11 +40,6 @@ public function getNames(): array
return array_keys($this->fields);
}

/**
* @param string $name
*
* @return bool
*/
public function has(string $name): bool
{
return isset($this->fields[$name]);
Expand Down Expand Up @@ -118,12 +99,6 @@ public function getByColumnName(string $name): Field
throw new FieldException("Undefined field with column name `{$name}`.");
}

/**
* @param string $name
* @param Field $field
*
* @return FieldMap
*/
public function set(string $name, Field $field): self
{
if ($this->has($name)) {
Expand All @@ -135,19 +110,24 @@ public function set(string $name, Field $field): self
return $this;
}

/**
* @param string $name
*
* @return FieldMap
*/
public function remove(string $name): self
{
unset($this->fields[$name]);
return $this;
}

public function getIterator(): Traversable
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->fields);
}

/**
* Cloning.
*/
public function __clone()
{
foreach ($this->fields as $name => $field) {
$this->fields[$name] = clone $field;
}
}
}
Loading

0 comments on commit 94fc28b

Please sign in to comment.