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

update stan #300

Merged
merged 1 commit into from
Nov 17, 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
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.11.9" installed="1.11.9" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.25.0" installed="5.25.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
</phive>
31 changes: 31 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
ignoreErrors:
-
message: '#^Creating callable from array\{mixed, non\-falsy\-string\} but it might not be a callable\.$#'
identifier: callable.nonCallable
count: 2
path: src/AuthorizationService.php

-
message: '#^Method Authorization\\Controller\\Component\\AuthorizationComponent\:\:can\(\) should return bool but returns Authorization\\Policy\\ResultInterface\|bool\.$#'
identifier: return.type
count: 1
path: src/Controller/Component/AuthorizationComponent.php

-
message: '#^Method Authorization\\Controller\\Component\\AuthorizationComponent\:\:canResult\(\) should return Authorization\\Policy\\ResultInterface but returns Authorization\\Policy\\ResultInterface\|bool\.$#'
identifier: return.type
count: 1
path: src/Controller/Component/AuthorizationComponent.php

-
message: '#^Cannot call method getIdentifier\(\) on array\|Authentication\\IdentityInterface\.$#'
Copy link
Member

Choose a reason for hiding this comment

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

This error should actually be addressed at some point, good for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have that prop as ArrayAccess|array with native PHP attributes but overwritten with @var \Authentication\IdentityInterface because of the nature of it being a decorator implementation.

Haven't taken too much time thinking about it but feels pretty hard to get stan to understand that correctly.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's a tricky one, hence I too have been ignoring it 😛.

identifier: method.nonObject
count: 1
path: src/Identity.php

-
message: '#^Cannot call method getOriginalData\(\) on array\|Authentication\\IdentityInterface\.$#'
identifier: method.nonObject
count: 1
path: src/Identity.php
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 6
level: 7
treatPhpDocTypesAsCertain: false
paths:
- src/
Expand Down
20 changes: 10 additions & 10 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<file src="src/Command/PolicyCommand.php">
<RiskyTruthyFalsyComparison>
<code>!$name</code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/IdentityDecorator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[$this->identity]]></code>
</RiskyTruthyFalsyComparison>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Controller/Component/AuthorizationComponent.php">
<InvalidReturnStatement>
<code><![CDATA[$this->performCheck($resource, $action)]]></code>
<code><![CDATA[$this->performCheck($resource, $action, 'canResult')]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[\Authorization\Policy\ResultInterface]]></code>
<code><![CDATA[bool]]></code>
</InvalidReturnType>
</file>
</files>
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<MissingClosureParamType errorLevel="info" />

<RedundantConditionGivenDocblockType errorLevel="info" />
<RiskyTruthyFalsyComparison errorLevel="info" />
</issueHandlers>
</psalm>
6 changes: 1 addition & 5 deletions src/Controller/Component/AuthorizationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ public function authorize(mixed $resource, ?string $action = null): void
* @param mixed $resource The resource to check authorization on.
* @param string|null $action The action to check authorization for.
* @return bool
* @psalm-suppress InvalidReturnType
*/
public function can(mixed $resource, ?string $action = null): bool
{
/** @psalm-suppress InvalidReturnStatement */
return $this->performCheck($resource, $action);
}

Expand All @@ -108,11 +106,9 @@ public function can(mixed $resource, ?string $action = null): bool
* @param mixed $resource The resource to check authorization on.
* @param string|null $action The action to check authorization for.
* @return \Authorization\Policy\ResultInterface
* @psalm-suppress InvalidReturnType
*/
public function canResult(mixed $resource, ?string $action = null): ResultInterface
{
/** @psalm-suppress InvalidReturnStatement */
return $this->performCheck($resource, $action, 'canResult');
}

Expand Down Expand Up @@ -348,7 +344,7 @@ protected function getDefaultAction(ServerRequest $request): string
public function implementedEvents(): array
{
return [
$this->getConfig('authorizationEvent') => 'authorizeAction',
(string)$this->getConfig('authorizationEvent') => 'authorizeAction',
];
}
}
1 change: 0 additions & 1 deletion src/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Identity extends IdentityDecorator implements AuthenIdentityInterface
*
* @param \Authorization\AuthorizationServiceInterface $service The authorization service.
* @param \Authentication\IdentityInterface $identity Identity data
* @throws \InvalidArgumentException When invalid identity data is passed.
*/
public function __construct(AuthorizationServiceInterface $service, AuthenIdentityInterface $identity)
{
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class IdentityDecorator implements IdentityInterface
*
* @param \Authorization\AuthorizationServiceInterface $service The authorization service.
* @param \ArrayAccess|array $identity Identity data
* @throws \InvalidArgumentException When invalid identity data is passed.
*/
public function __construct(AuthorizationServiceInterface $service, ArrayAccess|array $identity)
{
Expand Down Expand Up @@ -111,6 +110,7 @@ public function __call(string $method, array $args): mixed
}
$call = [$this->identity, $method];

/** @phpstan-ignore callable.nonCallable */
return $call(...$args);
}

Expand Down