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

[make:user] Add phpdocs in class generated by make:user for PHPStan #1411

Merged
merged 2 commits into from
Feb 20, 2024
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
24 changes: 14 additions & 10 deletions src/Security/UserClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,38 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi
if ($userClassConfig->isEntity()) {
// add entity property
$manipulator->addEntityField(
new ClassProperty(propertyName: 'roles', type: 'json')
new ClassProperty(propertyName: 'roles', type: 'json', comments: ['@var list<string> The user roles'])
);
} else {
// add normal property
$manipulator->addProperty(
name: 'roles',
defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT])
defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]),
comments: [
'@var list<string> The user roles',
]
);

$manipulator->addGetter(
'roles',
'array',
false
);

$manipulator->addSetter(
'roles',
'array',
false
false,
);
}

$manipulator->addSetter(
'roles',
'array',
false,
['@param list<string> $roles']
);

// define getRoles (if it was defined above, this will override)
$builder = $manipulator->createMethodBuilder(
'getRoles',
'array',
false,
['@see UserInterface']
['@see UserInterface', '@return list<string>']
);

// $roles = $this->roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;

/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];

Expand Down Expand Up @@ -55,6 +58,7 @@ public function getUserIdentifier(): string

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -65,6 +69,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
7 changes: 7 additions & 0 deletions tests/Security/fixtures/expected/UserEntityWithPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 180, unique: true)]
private ?string $userIdentifier = null;

/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];

Expand Down Expand Up @@ -50,6 +53,7 @@ public function setUserIdentifier(string $userIdentifier): static

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -60,6 +64,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 180, unique: true)]
private ?string $user_identifier = null;

/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];

Expand Down Expand Up @@ -50,6 +53,7 @@ public function setUserIdentifier(string $user_identifier): static

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -60,6 +64,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class User implements UserInterface
#[ORM\Column(length: 180, unique: true)]
private ?string $userIdentifier = null;

/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];

Expand Down Expand Up @@ -43,6 +46,7 @@ public function setUserIdentifier(string $userIdentifier): static

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -53,6 +57,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
private $email;

/**
* @var list<string> The user roles
*/
private $roles = [];

/**
Expand Down Expand Up @@ -40,6 +43,7 @@ public function getUserIdentifier(): string

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -50,6 +54,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
7 changes: 7 additions & 0 deletions tests/Security/fixtures/expected/UserModelWithPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
{
private $userIdentifier;

/**
* @var list<string> The user roles
*/
private $roles = [];

/**
Expand All @@ -35,6 +38,7 @@ public function setUserIdentifier(string $userIdentifier): static

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -45,6 +49,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
7 changes: 7 additions & 0 deletions tests/Security/fixtures/expected/UserModelWithoutPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class User implements UserInterface
{
private $userIdentifier;

/**
* @var list<string> The user roles
*/
private $roles = [];

/**
Expand All @@ -29,6 +32,7 @@ public function setUserIdentifier(string $userIdentifier): static

/**
* @see UserInterface
* @return list<string>
*/
public function getRoles(): array
{
Expand All @@ -39,6 +43,9 @@ public function getRoles(): array
return array_unique($roles);
}

/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
Expand Down
Loading