Skip to content

Commit bf336d2

Browse files
committed
coding style
1 parent be8361d commit bf336d2

File tree

11 files changed

+31
-35
lines changed

11 files changed

+31
-35
lines changed

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function getConfigSchema(): Nette\Schema\Schema
4040
'password' => Expect::string(),
4141
'roles' => Expect::anyOf(Expect::string(), Expect::listOf('string')),
4242
'data' => Expect::array(),
43-
])->castTo('array')
44-
)
43+
])->castTo('array'),
44+
),
4545
),
4646
'roles' => Expect::arrayOf('string|array|null'), // role => parent(s)
4747
'resources' => Expect::arrayOf('string|null'), // resource => parent

src/Bridges/SecurityHttp/CookieStorage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ public function saveAuthentication(IIdentity $identity): void
6464
$this->cookieName,
6565
$uid,
6666
$this->cookieExpiration,
67-
null,
68-
$this->cookieDomain,
69-
null,
70-
true,
71-
$this->cookieSameSite
67+
domain: $this->cookieDomain,
68+
sameSite: $this->cookieSameSite,
7269
);
7370
}
7471

@@ -78,8 +75,7 @@ public function clearAuthentication(bool $clearIdentity): void
7875
$this->uid = '';
7976
$this->response->deleteCookie(
8077
$this->cookieName,
81-
null,
82-
$this->cookieDomain
78+
domain: $this->cookieDomain,
8379
);
8480
}
8581

@@ -106,7 +102,7 @@ public function setExpiration(?string $expire, bool $clearIdentity): void
106102
public function setCookieParameters(
107103
?string $name = null,
108104
?string $domain = null,
109-
?string $sameSite = null
105+
?string $sameSite = null,
110106
) {
111107
$this->cookieName = $name ?? $this->cookieName;
112108
$this->cookieDomain = $domain ?? $this->cookieDomain;

src/Security/Passwords.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct($algo = PASSWORD_DEFAULT, array $options = [])
4242
*/
4343
public function hash(
4444
#[\SensitiveParameter]
45-
string $password
45+
string $password,
4646
): string
4747
{
4848
if ($password === '') {
@@ -64,7 +64,7 @@ public function hash(
6464
public function verify(
6565
#[\SensitiveParameter]
6666
string $password,
67-
string $hash
67+
string $hash,
6868
): bool
6969
{
7070
return password_verify($password, $hash);

src/Security/Permission.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Permission implements Authorizator
6161
*/
6262
public function addRole(string $role, $parents = null)
6363
{
64-
$this->checkRole($role, false);
64+
$this->checkRole($role, exists: false);
6565
if (isset($this->roles[$role])) {
6666
throw new Nette\InvalidStateException("Role '$role' already exists in the list.");
6767
}
@@ -94,7 +94,7 @@ public function addRole(string $role, $parents = null)
9494
*/
9595
public function hasRole(string $role): bool
9696
{
97-
$this->checkRole($role, false);
97+
$this->checkRole($role, exists: false);
9898
return isset($this->roles[$role]);
9999
}
100100

@@ -234,7 +234,7 @@ public function removeAllRoles()
234234
*/
235235
public function addResource(string $resource, ?string $parent = null)
236236
{
237-
$this->checkResource($resource, false);
237+
$this->checkResource($resource, exists: false);
238238

239239
if (isset($this->resources[$resource])) {
240240
throw new Nette\InvalidStateException("Resource '$resource' already exists in the list.");
@@ -259,7 +259,7 @@ public function addResource(string $resource, ?string $parent = null)
259259
*/
260260
public function hasResource(string $resource): bool
261261
{
262-
$this->checkResource($resource, false);
262+
$this->checkResource($resource, exists: false);
263263
return isset($this->resources[$resource]);
264264
}
265265

@@ -391,7 +391,7 @@ public function allow(
391391
$roles = self::All,
392392
$resources = self::All,
393393
$privileges = self::All,
394-
?callable $assertion = null
394+
?callable $assertion = null,
395395
) {
396396
$this->setRule(true, self::Allow, $roles, $resources, $privileges, $assertion);
397397
return $this;
@@ -411,7 +411,7 @@ public function deny(
411411
$roles = self::All,
412412
$resources = self::All,
413413
$privileges = self::All,
414-
?callable $assertion = null
414+
?callable $assertion = null,
415415
) {
416416
$this->setRule(true, self::Deny, $roles, $resources, $privileges, $assertion);
417417
return $this;
@@ -497,7 +497,7 @@ protected function setRule(bool $toAdd, bool $type, $roles, $resources, $privile
497497
if ($toAdd) { // add to the rules
498498
foreach ($resources as $resource) {
499499
foreach ($roles as $role) {
500-
$rules = &$this->getRules($resource, $role, true);
500+
$rules = &$this->getRules($resource, $role, create: true);
501501
if (count($privileges) === 0) {
502502
$rules['allPrivileges']['type'] = $type;
503503
$rules['allPrivileges']['assert'] = $assertion;

src/Security/SimpleAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
#[\SensitiveParameter]
3939
array $passwords,
4040
array $roles = [],
41-
array $data = []
41+
array $data = [],
4242
) {
4343
$this->passwords = $passwords;
4444
$this->roles = $roles;
@@ -54,7 +54,7 @@ public function __construct(
5454
public function authenticate(
5555
string $username,
5656
#[\SensitiveParameter]
57-
string $password
57+
string $password,
5858
): IIdentity
5959
{
6060
foreach ($this->passwords as $name => $pass) {

src/Security/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(
7676
?IUserStorage $legacyStorage = null,
7777
?IAuthenticator $authenticator = null,
7878
?Authorizator $authorizator = null,
79-
?UserStorage $storage = null
79+
?UserStorage $storage = null,
8080
) {
8181
$this->storage = $storage ?? $legacyStorage; // back compatibility
8282
if (!$this->storage) {
@@ -108,7 +108,7 @@ final public function getStorage()
108108
public function login(
109109
$user,
110110
#[\SensitiveParameter]
111-
?string $password = null
111+
?string $password = null,
112112
): void
113113
{
114114
$this->logout(true);

tests/Security.Http/CookieStorage.getState.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ $storage = new CookieStorage($request, $response);
1515
Assert::same([false, null, null], $storage->getState());
1616

1717
// short id
18-
$request = new Nette\Http\Request(new Nette\Http\UrlScript, [], [], ['userid' => 'short']);
18+
$request = new Nette\Http\Request(new Nette\Http\UrlScript, cookies: ['userid' => 'short']);
1919
$storage = new CookieStorage($request, $response);
2020
Assert::same([false, null, null], $storage->getState());
2121

2222
// correct id
2323
$id = '123456789123456';
24-
$request = new Nette\Http\Request(new Nette\Http\UrlScript, [], [], ['userid' => $id]);
24+
$request = new Nette\Http\Request(new Nette\Http\UrlScript, cookies: ['userid' => $id]);
2525
$storage = new CookieStorage($request, $response);
2626
Assert::equal([true, new SimpleIdentity($id), null], $storage->getState());
2727

2828
// custom cookie
29-
$request = new Nette\Http\Request(new Nette\Http\UrlScript, [], [], ['foo' => $id]);
29+
$request = new Nette\Http\Request(new Nette\Http\UrlScript, cookies: ['foo' => $id]);
3030
$storage = new CookieStorage($request, $response);
3131
$storage->setCookieParameters('foo');
3232
Assert::equal([true, new SimpleIdentity($id), null], $storage->getState());

tests/Security/Passwords.hash().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
Assert::truthy(
17-
preg_match('#^\$.{50,}\z#', (new Passwords)->hash('my-password'))
17+
preg_match('#^\$.{50,}\z#', (new Passwords)->hash('my-password')),
1818
);
1919

2020
Assert::truthy(
21-
preg_match('#^\$2y\$05\$.{53}\z#', (new Passwords(PASSWORD_BCRYPT, ['cost' => 5]))->hash('dg'))
21+
preg_match('#^\$2y\$05\$.{53}\z#', (new Passwords(PASSWORD_BCRYPT, ['cost' => 5]))->hash('dg')),
2222
);
2323

2424
$hash = (new Passwords(PASSWORD_BCRYPT))->hash('dg');

tests/Security/Permission.ResourceInherits.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ $acl->addResource('building', 'city');
1919
$acl->addResource('room', 'building');
2020

2121
Assert::same(['city', 'building', 'room'], $acl->getResources());
22-
Assert::true($acl->resourceInheritsFrom('building', 'city', true));
23-
Assert::true($acl->resourceInheritsFrom('room', 'building', true));
22+
Assert::true($acl->resourceInheritsFrom('building', 'city', onlyParent: true));
23+
Assert::true($acl->resourceInheritsFrom('room', 'building', onlyParent: true));
2424
Assert::true($acl->resourceInheritsFrom('room', 'city'));
25-
Assert::false($acl->resourceInheritsFrom('room', 'city', true));
25+
Assert::false($acl->resourceInheritsFrom('room', 'city', onlyParent: true));
2626
Assert::false($acl->resourceInheritsFrom('city', 'building'));
2727
Assert::false($acl->resourceInheritsFrom('building', 'room'));
2828
Assert::false($acl->resourceInheritsFrom('city', 'room'));

tests/Security/Permission.RoleRegistryInherits.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Assert::same(['guest'], $acl->getRoleParents('member'));
2323
Assert::same(['member'], $acl->getRoleParents('editor'));
2424

2525

26-
Assert::true($acl->roleInheritsFrom('member', 'guest', true));
27-
Assert::true($acl->roleInheritsFrom('editor', 'member', true));
26+
Assert::true($acl->roleInheritsFrom('member', 'guest', onlyParents: true));
27+
Assert::true($acl->roleInheritsFrom('editor', 'member', onlyParents: true));
2828
Assert::true($acl->roleInheritsFrom('editor', 'guest'));
29-
Assert::false($acl->roleInheritsFrom('editor', 'guest', true));
29+
Assert::false($acl->roleInheritsFrom('editor', 'guest', onlyParents: true));
3030
Assert::false($acl->roleInheritsFrom('guest', 'member'));
3131
Assert::false($acl->roleInheritsFrom('member', 'editor'));
3232
Assert::false($acl->roleInheritsFrom('guest', 'editor'));

0 commit comments

Comments
 (0)