Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add property type declarations #697

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions example/src/Entity/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,24 @@ final class Avatar
* name="url",
* type="string"
* )
*
* @var string
*/
private $url = '';
private string $url = '';

/**
* @ORM\Mapping\Column(
* name="width",
* type="integer"
* )
*
* @var int
*/
private $width = 0;
private int $width = 0;

/**
* @ORM\Mapping\Column(
* name="height",
* type="integer"
* )
*
* @var int
*/
private $height = 0;
private int $height = 0;

public function url(): string
{
Expand Down
16 changes: 4 additions & 12 deletions example/src/Entity/CodeOfConduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,32 @@ class CodeOfConduct
/**
* @ORM\Mapping\Id
* @ORM\Mapping\Column(type="string")
*
* @var string
*/
private $key;
private string $key;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*
* @var string
*/
private $name;
private string $name;

/**
* @ORM\Mapping\Column(
* name="url",
* type="string"
* )
*
* @var string
*/
private $url;
private string $url;

/**
* @ORM\Mapping\Column(
* name="body",
* type="text"
* )
*
* @var string
*/
private $body;
private string $body;

public function __construct(string $key, string $name, string $url, string $body)
{
Expand Down
26 changes: 7 additions & 19 deletions example/src/Entity/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,33 @@ class Organization
* type="string",
* length=36
* )
*
* @var string
*/
private $id;
private string $id;

/**
* @ORM\Mapping\Column(
* name="is_verified",
* type="boolean"
* )
*
* @var bool
*/
private $isVerified = false;
private bool $isVerified = false;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*
* @var string
*/
private $name;
private string $name;

/**
* @ORM\Mapping\Column(
* name="url",
* type="string",
* nullable=true
* )
*
* @var null|string
*/
private $url;
private ?string $url = null;

/**
* @ORM\Mapping\OneToMany(
Expand All @@ -74,7 +66,7 @@ class Organization
*
* @var Common\Collections\Collection<int, Repository>
*/
private $repositories;
private Common\Collections\Collection $repositories;

/**
* @ORM\Mapping\ManyToMany(
Expand All @@ -84,12 +76,8 @@ class Organization
*
* @var Common\Collections\Collection<int, User>
*/
private $members;

/**
* @var bool
*/
private $constructorWasCalled = false;
private Common\Collections\Collection$members;
private bool $constructorWasCalled = false;

public function __construct(string $name)
{
Expand Down
12 changes: 3 additions & 9 deletions example/src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ class Project
* type="string",
* length=36
* )
*
* @var string
*/
private $id;
private string $id;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*
* @var string
*/
private $name;
private string $name;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
Expand All @@ -51,10 +47,8 @@ class Project
* referencedColumnName="id",
* nullable=false
* )
*
* @var Repository
*/
private $repository;
private Repository $repository;

public function __construct(string $name, Repository $repository)
{
Expand Down
20 changes: 5 additions & 15 deletions example/src/Entity/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ class Repository
* name="id",
* type="string"
* )
*
* @var string
*/
private $id;
private string $id;

/**
* @ORM\Mapping\Column(
* name="name",
* type="string"
* )
*
* @var string
*/
private $name;
private string $name;

/**
* @ORM\Mapping\ManyToOne(
Expand All @@ -54,32 +50,26 @@ class Repository
* referencedColumnName="id",
* nullable=false
* )
*
* @var Organization
*/
private $organization;
private Organization $organization;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
* @ORM\Mapping\JoinColumn(
* name="template_id",
* referencedColumnName="id"
* )
*
* @var null|Repository
*/
private $template;
private ?Repository $template;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\CodeOfConduct")
* @ORM\Mapping\JoinColumn(
* name="code_of_conduct_key",
* referencedColumnName="key"
* )
*
* @var null|CodeOfConduct
*/
private $codeOfConduct;
private ?CodeOfConduct $codeOfConduct;

public function __construct(
Organization $organization,
Expand Down
18 changes: 5 additions & 13 deletions example/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,33 @@ class User
* type="string",
* length=36
* )
*
* @var string
*/
private $id;
private string $id;

/**
* @ORM\Mapping\Column(
* name="login",
* type="string"
* )
*
* @var string
*/
private $login;
private string $login;

/**
* @ORM\Mapping\Column(
* name="location",
* type="string",
* nullable=true
* )
*
* @var null|string
*/
private $location;
private ?string $location;

/**
* @ORM\Mapping\Embedded(
* class="Example\Entity\Avatar",
* columnPrefix="avatar"
* )
*
* @var Avatar
*/
private $avatar;
private Avatar $avatar;

/**
* @ORM\Mapping\ManyToMany(
Expand All @@ -74,7 +66,7 @@ class User
*
* @var Common\Collections\Collection<int, Organization>
*/
private $organizations;
private Common\Collections\Collection $organizations;

public function __construct(string $login, Avatar $avatar, ?string $location = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function accept(FactoryBot\FixtureFactory $fixtureFactory): void
'id' => FactoryBot\FieldDefinition::closure(static function (Generator $faker): string {
return $faker->uuid;
}),
'isVerified' => FactoryBot\FieldDefinition::optionalClosure(static function (Generator $faker): bool {
'isVerified' => FactoryBot\FieldDefinition::closure(static function (Generator $faker): bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field is not nullable.

return $faker->boolean;
}),
'members' => FactoryBot\FieldDefinition::references(
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ parameters:
count: 1
path: example/src/Entity/Organization.php

-
message: "#^Property Example\\\\Entity\\\\Organization\\:\\:\\$url is never written, only read\\.$#"
count: 1
path: example/src/Entity/Organization.php

-
message: "#^Constructor in Example\\\\Entity\\\\Repository has parameter \\$codeOfConduct with default value\\.$#"
count: 1
Expand Down
11 changes: 2 additions & 9 deletions src/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@

final class Count
{
/**
* @var int
*/
private $minimum;

/**
* @var int
*/
private $maximum;
private int $minimum;
private int $maximum;

private function __construct(
int $minimum,
Expand Down
13 changes: 3 additions & 10 deletions src/EntityDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@
*/
final class EntityDefinition
{
/**
* @var ORM\Mapping\ClassMetadata
*/
private $classMetadata;
private ORM\Mapping\ClassMetadata $classMetadata;

/**
* @var array<string, FieldDefinition\Resolvable>
*/
private $fieldDefinitions;

/**
* @var \Closure
*/
private $afterCreate;
private array $fieldDefinitions;
private \Closure $afterCreate;

/**
* @param array<string, FieldDefinition\Resolvable> $fieldDefinitions
Expand Down
5 changes: 1 addition & 4 deletions src/FieldDefinition/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
*/
final class Closure implements Resolvable
{
/**
* @var \Closure
*/
private $closure;
private \Closure $closure;

public function __construct(\Closure $closure)
{
Expand Down
5 changes: 1 addition & 4 deletions src/FieldDefinition/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
*/
final class Optional implements Resolvable
{
/**
* @var Resolvable
*/
private $resolvable;
private Resolvable $resolvable;

public function __construct(Resolvable $resolvable)
{
Expand Down
4 changes: 1 addition & 3 deletions src/FieldDefinition/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ final class Reference implements Resolvable
* @phpstan-var class-string<T>
*
* @psalm-var class-string<T>
*
* @var string
*/
private $className;
private string $className;

/**
* @phpstan-param class-string<T> $className
Expand Down
Loading