Skip to content

Commit 490e550

Browse files
feature #1411 [make:user] Add phpdocs in class generated by make:user for PHPStan
1 parent eb4542f commit 490e550

8 files changed

+63
-10
lines changed

src/Security/UserClassBuilder.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,38 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi
9999
if ($userClassConfig->isEntity()) {
100100
// add entity property
101101
$manipulator->addEntityField(
102-
new ClassProperty(propertyName: 'roles', type: 'json')
102+
new ClassProperty(propertyName: 'roles', type: 'json', comments: ['@var list<string> The user roles'])
103103
);
104104
} else {
105105
// add normal property
106106
$manipulator->addProperty(
107107
name: 'roles',
108-
defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT])
108+
defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]),
109+
comments: [
110+
'@var list<string> The user roles',
111+
]
109112
);
110113

111114
$manipulator->addGetter(
112115
'roles',
113116
'array',
114-
false
115-
);
116-
117-
$manipulator->addSetter(
118-
'roles',
119-
'array',
120-
false
117+
false,
121118
);
122119
}
123120

121+
$manipulator->addSetter(
122+
'roles',
123+
'array',
124+
false,
125+
['@param list<string> $roles']
126+
);
127+
124128
// define getRoles (if it was defined above, this will override)
125129
$builder = $manipulator->createMethodBuilder(
126130
'getRoles',
127131
'array',
128132
false,
129-
['@see UserInterface']
133+
['@see UserInterface', '@return list<string>']
130134
);
131135

132136
// $roles = $this->roles

tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
1717
#[ORM\Column(length: 180, unique: true)]
1818
private ?string $email = null;
1919

20+
/**
21+
* @var list<string> The user roles
22+
*/
2023
#[ORM\Column]
2124
private array $roles = [];
2225

@@ -55,6 +58,7 @@ public function getUserIdentifier(): string
5558

5659
/**
5760
* @see UserInterface
61+
* @return list<string>
5862
*/
5963
public function getRoles(): array
6064
{
@@ -65,6 +69,9 @@ public function getRoles(): array
6569
return array_unique($roles);
6670
}
6771

72+
/**
73+
* @param list<string> $roles
74+
*/
6875
public function setRoles(array $roles): static
6976
{
7077
$this->roles = $roles;

tests/Security/fixtures/expected/UserEntityWithPassword.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
1717
#[ORM\Column(length: 180, unique: true)]
1818
private ?string $userIdentifier = null;
1919

20+
/**
21+
* @var list<string> The user roles
22+
*/
2023
#[ORM\Column]
2124
private array $roles = [];
2225

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

5154
/**
5255
* @see UserInterface
56+
* @return list<string>
5357
*/
5458
public function getRoles(): array
5559
{
@@ -60,6 +64,9 @@ public function getRoles(): array
6064
return array_unique($roles);
6165
}
6266

67+
/**
68+
* @param list<string> $roles
69+
*/
6370
public function setRoles(array $roles): static
6471
{
6572
$this->roles = $roles;

tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
1717
#[ORM\Column(length: 180, unique: true)]
1818
private ?string $user_identifier = null;
1919

20+
/**
21+
* @var list<string> The user roles
22+
*/
2023
#[ORM\Column]
2124
private array $roles = [];
2225

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

5154
/**
5255
* @see UserInterface
56+
* @return list<string>
5357
*/
5458
public function getRoles(): array
5559
{
@@ -60,6 +64,9 @@ public function getRoles(): array
6064
return array_unique($roles);
6165
}
6266

67+
/**
68+
* @param list<string> $roles
69+
*/
6370
public function setRoles(array $roles): static
6471
{
6572
$this->roles = $roles;

tests/Security/fixtures/expected/UserEntityWithoutPassword.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class User implements UserInterface
1616
#[ORM\Column(length: 180, unique: true)]
1717
private ?string $userIdentifier = null;
1818

19+
/**
20+
* @var list<string> The user roles
21+
*/
1922
#[ORM\Column]
2023
private array $roles = [];
2124

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

4447
/**
4548
* @see UserInterface
49+
* @return list<string>
4650
*/
4751
public function getRoles(): array
4852
{
@@ -53,6 +57,9 @@ public function getRoles(): array
5357
return array_unique($roles);
5458
}
5559

60+
/**
61+
* @param list<string> $roles
62+
*/
5663
public function setRoles(array $roles): static
5764
{
5865
$this->roles = $roles;

tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
99
{
1010
private $email;
1111

12+
/**
13+
* @var list<string> The user roles
14+
*/
1215
private $roles = [];
1316

1417
/**
@@ -40,6 +43,7 @@ public function getUserIdentifier(): string
4043

4144
/**
4245
* @see UserInterface
46+
* @return list<string>
4347
*/
4448
public function getRoles(): array
4549
{
@@ -50,6 +54,9 @@ public function getRoles(): array
5054
return array_unique($roles);
5155
}
5256

57+
/**
58+
* @param list<string> $roles
59+
*/
5360
public function setRoles(array $roles): static
5461
{
5562
$this->roles = $roles;

tests/Security/fixtures/expected/UserModelWithPassword.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
99
{
1010
private $userIdentifier;
1111

12+
/**
13+
* @var list<string> The user roles
14+
*/
1215
private $roles = [];
1316

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

3639
/**
3740
* @see UserInterface
41+
* @return list<string>
3842
*/
3943
public function getRoles(): array
4044
{
@@ -45,6 +49,9 @@ public function getRoles(): array
4549
return array_unique($roles);
4650
}
4751

52+
/**
53+
* @param list<string> $roles
54+
*/
4855
public function setRoles(array $roles): static
4956
{
5057
$this->roles = $roles;

tests/Security/fixtures/expected/UserModelWithoutPassword.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class User implements UserInterface
88
{
99
private $userIdentifier;
1010

11+
/**
12+
* @var list<string> The user roles
13+
*/
1114
private $roles = [];
1215

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

3033
/**
3134
* @see UserInterface
35+
* @return list<string>
3236
*/
3337
public function getRoles(): array
3438
{
@@ -39,6 +43,9 @@ public function getRoles(): array
3943
return array_unique($roles);
4044
}
4145

46+
/**
47+
* @param list<string> $roles
48+
*/
4249
public function setRoles(array $roles): static
4350
{
4451
$this->roles = $roles;

0 commit comments

Comments
 (0)