Skip to content

Commit

Permalink
Add types to mapping builders (#10052)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Sep 22, 2022
1 parent a3ec3f3 commit ffd47ce
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 309 deletions.
85 changes: 32 additions & 53 deletions lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,115 +9,99 @@

class AssociationBuilder
{
/** @var ClassMetadataBuilder */
protected $builder;

/** @var mixed[] */
protected $mapping;

/** @var mixed[]|null */
protected $joinColumns;
protected array|null $joinColumns = null;

/**
* @param mixed[] $mapping
* @param int $type
*/
public function __construct(ClassMetadataBuilder $builder, array $mapping, protected $type)
{
$this->builder = $builder;
$this->mapping = $mapping;
/** @param mixed[] $mapping */
public function __construct(
protected readonly ClassMetadataBuilder $builder,
protected array $mapping,
protected readonly int $type,
) {
}

/**
* @param string $fieldName
*
* @return $this
*/
public function mappedBy($fieldName)
/** @return $this */
public function mappedBy(string $fieldName): static
{
$this->mapping['mappedBy'] = $fieldName;

return $this;
}

/**
* @param string $fieldName
*
* @return $this
*/
public function inversedBy($fieldName)
/** @return $this */
public function inversedBy(string $fieldName): static
{
$this->mapping['inversedBy'] = $fieldName;

return $this;
}

/** @return $this */
public function cascadeAll()
public function cascadeAll(): static
{
$this->mapping['cascade'] = ['ALL'];

return $this;
}

/** @return $this */
public function cascadePersist()
public function cascadePersist(): static
{
$this->mapping['cascade'][] = 'persist';

return $this;
}

/** @return $this */
public function cascadeRemove()
public function cascadeRemove(): static
{
$this->mapping['cascade'][] = 'remove';

return $this;
}

/** @return $this */
public function cascadeMerge()
public function cascadeMerge(): static
{
$this->mapping['cascade'][] = 'merge';

return $this;
}

/** @return $this */
public function cascadeDetach()
public function cascadeDetach(): static
{
$this->mapping['cascade'][] = 'detach';

return $this;
}

/** @return $this */
public function cascadeRefresh()
public function cascadeRefresh(): static
{
$this->mapping['cascade'][] = 'refresh';

return $this;
}

/** @return $this */
public function fetchExtraLazy()
public function fetchExtraLazy(): static
{
$this->mapping['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY;

return $this;
}

/** @return $this */
public function fetchEager()
public function fetchEager(): static
{
$this->mapping['fetch'] = ClassMetadata::FETCH_EAGER;

return $this;
}

/** @return $this */
public function fetchLazy()
public function fetchLazy(): static
{
$this->mapping['fetch'] = ClassMetadata::FETCH_LAZY;

Expand All @@ -127,17 +111,16 @@ public function fetchLazy()
/**
* Add Join Columns.
*
* @param string $columnName
* @param string $referencedColumnName
* @param bool $nullable
* @param bool $unique
* @param string|null $onDelete
* @param string|null $columnDef
*
* @return $this
*/
public function addJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null)
{
public function addJoinColumn(
string $columnName,
string $referencedColumnName,
bool $nullable = true,
bool $unique = false,
string|null $onDelete = null,
string|null $columnDef = null,
): static {
$this->joinColumns[] = [
'name' => $columnName,
'referencedColumnName' => $referencedColumnName,
Expand All @@ -155,7 +138,7 @@ public function addJoinColumn($columnName, $referencedColumnName, $nullable = tr
*
* @return $this
*/
public function makePrimaryKey()
public function makePrimaryKey(): static
{
$this->mapping['id'] = true;

Expand All @@ -167,19 +150,15 @@ public function makePrimaryKey()
*
* @return $this
*/
public function orphanRemoval()
public function orphanRemoval(): static
{
$this->mapping['orphanRemoval'] = true;

return $this;
}

/**
* @return ClassMetadataBuilder
*
* @throws InvalidArgumentException
*/
public function build()
/** @throws InvalidArgumentException */
public function build(): ClassMetadataBuilder
{
$mapping = $this->mapping;
if ($this->joinColumns) {
Expand Down
Loading

0 comments on commit ffd47ce

Please sign in to comment.