Skip to content

Commit

Permalink
Enhancement: Use attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 12, 2023
1 parent 7f6b50c commit 70ff034
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 238 deletions.
34 changes: 13 additions & 21 deletions example/src/Entity/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,25 @@

use Doctrine\ORM;

/**
* @ORM\Mapping\Embeddable
*/
#[ORM\Mapping\Embeddable()]
final class Avatar
{
/**
* @ORM\Mapping\Column(
* name="url",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'url',
type: 'string',
)]
private string $url = '';

/**
* @ORM\Mapping\Column(
* name="width",
* type="integer"
* )
*/
#[ORM\Mapping\Column(
name: 'width',
type: 'integer',
)]
private int $width = 0;

/**
* @ORM\Mapping\Column(
* name="height",
* type="integer"
* )
*/
#[ORM\Mapping\Column(
name: 'height',
type: 'integer',
)]
private int $height = 0;

public function url(): string
Expand Down
46 changes: 18 additions & 28 deletions example/src/Entity/CodeOfConduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,32 @@

use Doctrine\ORM;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="code_of_conduct")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'code_of_conduct')]
class CodeOfConduct
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\Column(type="string")
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\Column(
type: 'string',
)]
private string $key;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'name',
type: 'string',
)]
private string $name;

/**
* @ORM\Mapping\Column(
* name="url",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'url',
type: 'string',
)]
private string $url;

/**
* @ORM\Mapping\Column(
* name="body",
* type="text"
* )
*/
#[ORM\Mapping\Column(
name: 'body',
type: 'text',
)]
private string $body;

public function __construct(
Expand Down
79 changes: 29 additions & 50 deletions example/src/Entity/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,47 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="organization")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'organization')]
class Organization
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* type="string",
* length=36
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
type: 'string',
length: 36,
)]
private string $id;

/**
* @ORM\Mapping\Column(
* name="is_verified",
* type="boolean"
* )
*/
#[ORM\Mapping\Column(
name: 'is_verified',
type: 'boolean',
)]
private bool $isVerified = false;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'name',
type: 'string',
)]
private string $name;

/**
* @ORM\Mapping\Column(
* name="url",
* type="string",
* nullable=true
* )
*/
#[ORM\Mapping\Column(
name: 'url',
type: 'string',
nullable: true,
)]
private ?string $url = null;

/**
* @ORM\Mapping\OneToMany(
* targetEntity="Example\Entity\Repository",
* mappedBy="organization"
* )
*
* @var Common\Collections\Collection<int, Repository>
*/
#[ORM\Mapping\OneToMany(
targetEntity: 'Example\Entity\Repository',
mappedBy: 'organization',
)]
private Common\Collections\Collection $repositories;

Check failure on line 55 in example/src/Entity/Organization.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.1, locked)

Property Example\Entity\Organization::$repositories type mapping mismatch: property can contain Doctrine\Common\Collections\Collection but database expects Doctrine\Common\Collections\Collection&iterable<Example\Entity\Repository>.

Check failure on line 55 in example/src/Entity/Organization.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.1, locked)

Property Example\Entity\Organization::$repositories with generic interface Doctrine\Common\Collections\Collection does not specify its types: TKey, T

/**
* @ORM\Mapping\ManyToMany(
* targetEntity="Example\Entity\User",
* inversedBy="organizations"
* )
*
* @var Common\Collections\Collection<int, User>
*/
#[ORM\Mapping\ManyToMany(
targetEntity: 'Example\Entity\User',
inversedBy: 'organizations',
)]
private Common\Collections\Collection $members;

Check failure on line 61 in example/src/Entity/Organization.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.1, locked)

Property Example\Entity\Organization::$members type mapping mismatch: property can contain Doctrine\Common\Collections\Collection but database expects Doctrine\Common\Collections\Collection&iterable<Example\Entity\User>.

Check failure on line 61 in example/src/Entity/Organization.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.1, locked)

Property Example\Entity\Organization::$members with generic interface Doctrine\Common\Collections\Collection does not specify its types: TKey, T
private bool $constructorWasCalled = false;

Expand Down
48 changes: 18 additions & 30 deletions example/src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,30 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="project")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'project')]
class Project
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* type="string",
* length=36
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
type: 'string',
length: 36,
)]
private string $id;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'name',
type: 'string',
)]
private string $name;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
*
* @ORM\Mapping\JoinColumn(
* name="repository_id",
* referencedColumnName="id",
* nullable=false
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: Repository::class)]
#[ORM\Mapping\JoinColumn(
name: 'repository_id',
referencedColumnName: 'id',
nullable: false,
)]
private Repository $repository;

public function __construct(
Expand Down
80 changes: 31 additions & 49 deletions example/src/Entity/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,47 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="repository")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'repository')]
class Repository
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* name="id",
* type="string"
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
name: 'id',
type: 'string',
)]
private string $id;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'name',
type: 'string',
)]
private string $name;

/**
* @ORM\Mapping\ManyToOne(
* targetEntity="Example\Entity\Organization",
* inversedBy="repositories"
* )
*
* @ORM\Mapping\JoinColumn(
* name="organization_id",
* referencedColumnName="id",
* nullable=false
* )
*/
#[ORM\Mapping\ManyToOne(
targetEntity: Organization::class,
inversedBy: 'repositories',
)]
#[ORM\Mapping\JoinColumn(
name: 'organization_id',
referencedColumnName: 'id',
nullable: false,
)]
private Organization $organization;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
*
* @ORM\Mapping\JoinColumn(
* name="template_id",
* referencedColumnName="id"
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: self::class)]
#[ORM\Mapping\JoinColumn(
name: 'template_id',
referencedColumnName: 'id',
)]
private ?Repository $template;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\CodeOfConduct")
*
* @ORM\Mapping\JoinColumn(
* name="code_of_conduct_key",
* referencedColumnName="key"
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: CodeOfConduct::class)]
#[ORM\Mapping\JoinColumn(
name: 'code_of_conduct_key',
referencedColumnName: 'key',
)]
private ?CodeOfConduct $codeOfConduct;

public function __construct(
Expand Down
Loading

0 comments on commit 70ff034

Please sign in to comment.