Skip to content

Commit ca3a81f

Browse files
committed
improved phpDoc types
1 parent 737eee7 commit ca3a81f

9 files changed

Lines changed: 56 additions & 18 deletions

File tree

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getConfigSchema(): Nette\Schema\Schema
5353

5454
public function loadConfiguration(): void
5555
{
56-
/** @var object{debugger: bool, users: array, roles: array, resources: array, authentication: \stdClass} $config */
56+
/** @var object{debugger: bool, users: array<string, string|array{password: string, roles?: string|string[], data?: array<string, mixed>}>, roles: array<string, string|string[]|null>, resources: array<string, string|null>, authentication: \stdClass} $config */
5757
$config = $this->config;
5858
$builder = $this->getContainerBuilder();
5959

src/Bridges/SecurityHttp/CookieStorage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function setExpiration(?string $expire, bool $clearIdentity): void
8484
}
8585

8686

87+
/** @param 'Lax'|'Strict'|'None'|null $sameSite */
8788
public function setCookieParameters(
8889
?string $name = null,
8990
?string $domain = null,

src/Security/IAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* @deprecated update to Nette\Security\Authenticator
13-
* @method IIdentity authenticate(array $credentials)
13+
* @method IIdentity authenticate(array{string, string} $credentials)
1414
*/
1515
interface IAuthenticator
1616
{

src/Security/IIdentity.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010

1111
/**
1212
* Represents the user of application.
13-
* @method array getData()
13+
* @method array<string, mixed> getData()
1414
*/
1515
interface IIdentity
1616
{
1717
/**
1818
* Returns the ID of user.
19-
* @return mixed
19+
* @return string|int
2020
*/
2121
function getId();
2222

2323
/**
2424
* Returns a list of roles that the user is a member of.
25+
* @return string[]
2526
*/
2627
function getRoles(): array;
2728

src/Security/Identity.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@
1313
/**
1414
* @deprecated use Nette\Security\SimpleIdentity
1515
* @property string|int $id
16-
* @property array $roles
17-
* @property array $data
16+
* @property string[] $roles
17+
* @property array<string,mixed> $data
1818
*/
1919
class Identity implements IIdentity
2020
{
2121
private string|int $id;
22+
23+
/** @var string[] */
2224
private array $roles;
25+
26+
/** @var array<string, mixed> */
2327
private array $data;
2428

2529

26-
public function __construct(string|int $id, $roles = null, ?iterable $data = null)
30+
/**
31+
* @param string|string[]|null $roles
32+
* @param ?iterable<string, mixed> $data
33+
*/
34+
public function __construct(string|int $id, string|array|null $roles = null, ?iterable $data = null)
2735
{
2836
$this->setId($id);
2937
$this->setRoles((array) $roles);
@@ -54,6 +62,7 @@ public function getId(): string|int
5462

5563
/**
5664
* Sets a list of roles that the user is a member of.
65+
* @param string[] $roles
5766
*/
5867
public function setRoles(array $roles): static
5968
{
@@ -64,6 +73,7 @@ public function setRoles(array $roles): static
6473

6574
/**
6675
* Returns a list of roles that the user is a member of.
76+
* @return string[]
6777
*/
6878
public function getRoles(): array
6979
{
@@ -73,6 +83,7 @@ public function getRoles(): array
7383

7484
/**
7585
* Returns user data.
86+
* @return array<string, mixed>
7687
*/
7788
public function getData(): array
7889
{

src/Security/Passwords.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Passwords
1818
{
1919
/**
2020
* Configures the hashing algorithm and its options.
21-
* @see https://php.net/manual/en/password.constants.php
2221
*/
2322
public function __construct(
2423
private readonly string $algo = PASSWORD_DEFAULT,
24+
/** @var array<string, mixed> algorithm-specific options, see https://php.net/manual/en/password.constants.php */
2525
private readonly array $options = [],
2626
) {
2727
}

src/Security/Permission.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
*/
1919
class Permission implements Authorizator
2020
{
21+
/** @var array<string, array{parents: array<string, true>, children: array<string, true>}> */
2122
private array $roles = [];
23+
24+
/** @var array<string, array{parent: ?string, children: array<string, true>}> */
2225
private array $resources = [];
2326

24-
/** Access Control List rules; whitelist (deny everything to all) by default */
27+
/** @var array<string, mixed> Access Control List rules; whitelist (deny everything to all) by default */
2528
private array $rules = [
2629
'allResources' => [
2730
'allRoles' => [
@@ -46,6 +49,7 @@ class Permission implements Authorizator
4649
/**
4750
* Adds a Role to the list. The most recently added parent
4851
* takes precedence over parents that were previously added.
52+
* @param string|string[]|null $parents
4953
* @throws Nette\InvalidArgumentException
5054
* @throws Nette\InvalidStateException
5155
*/
@@ -106,6 +110,7 @@ private function checkRole(string $role, bool $exists = true): void
106110

107111
/**
108112
* Returns all Roles.
113+
* @return list<string>
109114
*/
110115
public function getRoles(): array
111116
{
@@ -115,6 +120,7 @@ public function getRoles(): array
115120

116121
/**
117122
* Returns existing Role's parents ordered by ascending priority.
123+
* @return list<string>
118124
*/
119125
public function getRoleParents(string $role): array
120126
{
@@ -267,6 +273,7 @@ private function checkResource(string $resource, bool $exists = true): void
267273

268274
/**
269275
* Returns all Resources.
276+
* @return list<string>
270277
*/
271278
public function getResources(): array
272279
{
@@ -365,6 +372,10 @@ public function removeAllResources(): static
365372
/**
366373
* Allows one or more Roles access to [certain $privileges upon] the specified Resource(s).
367374
* If $assertion is provided, then it must return true in order for rule to apply.
375+
* @param string|string[]|null $roles
376+
* @param string|string[]|null $resources
377+
* @param string|string[]|null $privileges
378+
* @param callable(self, ?string, ?string, ?string): bool $assertion
368379
*/
369380
public function allow(
370381
string|array|null $roles = self::All,
@@ -381,6 +392,10 @@ public function allow(
381392
/**
382393
* Denies one or more Roles access to [certain $privileges upon] the specified Resource(s).
383394
* If $assertion is provided, then it must return true in order for rule to apply.
395+
* @param string|string[]|null $roles
396+
* @param string|string[]|null $resources
397+
* @param string|string[]|null $privileges
398+
* @param callable(self, ?string, ?string, ?string): bool $assertion
384399
*/
385400
public function deny(
386401
string|array|null $roles = self::All,
@@ -396,6 +411,9 @@ public function deny(
396411

397412
/**
398413
* Removes "allow" permissions from the list in the context of the given Roles, Resources, and privileges.
414+
* @param string|string[]|null $roles
415+
* @param string|string[]|null $resources
416+
* @param string|string[]|null $privileges
399417
*/
400418
public function removeAllow(
401419
string|array|null $roles = self::All,
@@ -410,6 +428,9 @@ public function removeAllow(
410428

411429
/**
412430
* Removes "deny" restrictions from the list in the context of the given Roles, Resources, and privileges.
431+
* @param string|string[]|null $roles
432+
* @param string|string[]|null $resources
433+
* @param string|string[]|null $privileges
413434
*/
414435
public function removeDeny(
415436
string|array|null $roles = self::All,
@@ -424,6 +445,10 @@ public function removeDeny(
424445

425446
/**
426447
* Performs operations on Access Control List rules.
448+
* @param string|string[]|null $roles
449+
* @param string|string[]|null $resources
450+
* @param string|string[]|null $privileges
451+
* @param callable(self, ?string, ?string, ?string): bool $assertion
427452
* @throws Nette\InvalidStateException
428453
*/
429454
protected function setRule(
@@ -711,6 +736,7 @@ private function getRuleType(?string $resource, ?string $role, ?string $privileg
711736
/**
712737
* Returns the rules associated with a Resource and a Role, or null if no such rules exist.
713738
* If the $create parameter is true, then a rule set is first created and then returned to the caller.
739+
* @return array<string, mixed>|null
714740
*/
715741
private function &getRules(?string $resource, ?string $role, bool $create = false): ?array
716742
{

src/Security/SimpleAuthenticator.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
*/
1414
class SimpleAuthenticator implements Authenticator
1515
{
16-
/**
17-
* @param array $passwords list of pairs username => password
18-
* @param array $roles list of pairs username => role[]
19-
* @param array $data list of pairs username => mixed[]
20-
*/
2116
public function __construct(
17+
/** @var array<string, string> */
2218
#[\SensitiveParameter]
2319
private array $passwords,
20+
/** @var array<string, string|string[]|null> */
2421
private array $roles = [],
22+
/** @var array<string, array<string, mixed>> */
2523
private array $data = [],
2624
) {
2725
}

src/Security/User.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* User authentication and authorization.
1717
*
1818
* @property-read bool $loggedIn
19-
* @property-read IIdentity $identity
20-
* @property-read string|int $id
21-
* @property-read array $roles
22-
* @property-read int $logoutReason
19+
* @property-read ?IIdentity $identity
20+
* @property-read string|int|null $id
21+
* @property-read string[] $roles
22+
* @property-read ?int $logoutReason
2323
* @property IAuthenticator $authenticator
2424
* @property Authorizator $authorizator
2525
*/
@@ -250,6 +250,7 @@ final public function getLogoutReason(): ?int
250250

251251
/**
252252
* Returns effective roles of the user. Unauthenticated users get the guest role.
253+
* @return string[]
253254
*/
254255
public function getRoles(): array
255256
{

0 commit comments

Comments
 (0)