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

2.x update stan #681

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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.10.14" installed="1.10.14" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.10.0" installed="5.10.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>
48 changes: 12 additions & 36 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,61 +1,37 @@
parameters:
ignoreErrors:
-
message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#"
message: '#^Strict comparison using \=\=\= between string and false will always evaluate to false\.$#'
identifier: identical.alwaysFalse
count: 1
path: src/Authenticator/HttpDigestAuthenticator.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/Authenticator/Result.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Authenticator/Result.php

-
message: "#^Parameter \\#1 \\$ldap of function ldap_bind expects LDAP\\\\Connection, resource given\\.$#"
message: '#^Parameter \#1 \$ldap of function ldap_bind expects LDAP\\Connection, resource given\.$#'
identifier: argument.type
count: 1
path: src/Identifier/Ldap/ExtensionAdapter.php

-
message: "#^Parameter \\#1 \\$ldap of function ldap_get_option expects LDAP\\\\Connection, resource given\\.$#"
message: '#^Parameter \#1 \$ldap of function ldap_get_option expects LDAP\\Connection, resource given\.$#'
identifier: argument.type
count: 1
path: src/Identifier/Ldap/ExtensionAdapter.php

-
message: "#^Parameter \\#1 \\$ldap of function ldap_set_option expects LDAP\\\\Connection\\|null, resource given\\.$#"
message: '#^Parameter \#1 \$ldap of function ldap_set_option expects LDAP\\Connection\|null, resource given\.$#'
identifier: argument.type
count: 1
path: src/Identifier/Ldap/ExtensionAdapter.php

-
message: "#^Parameter \\#1 \\$ldap of function ldap_unbind expects LDAP\\\\Connection, resource\\|null given\\.$#"
message: '#^Parameter \#1 \$ldap of function ldap_unbind expects LDAP\\Connection, resource\|null given\.$#'
identifier: argument.type
count: 1
path: src/Identifier/Ldap/ExtensionAdapter.php

-
message: "#^Property Authentication\\\\Identifier\\\\Ldap\\\\ExtensionAdapter\\:\\:\\$_connection \\(resource\\|null\\) does not accept LDAP\\\\Connection\\.$#"
message: '#^Property Authentication\\Identifier\\Ldap\\ExtensionAdapter\:\:\$_connection \(resource\|null\) does not accept LDAP\\Connection\.$#'
identifier: assign.propertyType
count: 1
path: src/Identifier/Ldap/ExtensionAdapter.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/Identity.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Identity.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 2
path: src/Middleware/AuthenticationMiddleware.php

-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Middleware/AuthenticationMiddleware.php
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ includes:

parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
ignoreErrors:
-
identifier: missingType.iterableValue
-
identifier: missingType.generics
118 changes: 89 additions & 29 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,60 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/AuthenticationService.php">
<PossiblyNullArgument>
<code><![CDATA[$provider]]></code>
</PossiblyNullArgument>
<RiskyTruthyFalsyComparison>
dereuromark marked this conversation as resolved.
Show resolved Hide resolved
<code><![CDATA[empty($parsed['host'])]]></code>
<code><![CDATA[empty($parsed['scheme'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/AuthenticatorCollection.php">
<MoreSpecificImplementedParamType occurrences="1">
<code>$class</code>
<MoreSpecificImplementedParamType>
<code><![CDATA[$class]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/Authenticator/CookieAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($identity)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/EnvironmentAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($data)]]></code>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/FormAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/HttpDigestAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($digest)]]></code>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/JwtAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/Result.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($data)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/SessionAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($user)]]></code>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Authenticator/TokenAuthenticator.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($headerLine)]]></code>
<code><![CDATA[empty($queryParam)]]></code>
<code><![CDATA[empty($user)]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Identifier/IdentifierCollection.php">
<MoreSpecificImplementedParamType occurrences="1">
<code>$class</code>
<MoreSpecificImplementedParamType>
<code><![CDATA[$class]]></code>
</MoreSpecificImplementedParamType>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$result]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Identifier/Ldap/ExtensionAdapter.php">
<InvalidArgument occurrences="4">
<code>$this-&gt;_connection</code>
<code>$this-&gt;getConnection()</code>
<code>$this-&gt;getConnection()</code>
<code>$this-&gt;getConnection()</code>
<InvalidArgument>
<code><![CDATA[$this->_connection]]></code>
<code><![CDATA[$this->getConnection()]]></code>
<code><![CDATA[$this->getConnection()]]></code>
<code><![CDATA[$this->getConnection()]]></code>
</InvalidArgument>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$resource</code>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$resource]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="src/Identity.php">
<LessSpecificImplementedReturnType occurrences="1">
<code>mixed</code>
<LessSpecificImplementedReturnType>
<code><![CDATA[mixed]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Middleware/AuthenticationMiddleware.php">
<PossiblyNullArgument occurrences="1">
<code>$result-&gt;getData()</code>
<PossiblyNullArgument>
<code><![CDATA[$result->getData()]]></code>
</PossiblyNullArgument>
<RedundantCast occurrences="1">
<code>(int)$e-&gt;getCode()</code>
<RedundantCast>
<code><![CDATA[(int)$e->getCode()]]></code>
</RedundantCast>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$url]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/PasswordHasher/DefaultPasswordHasher.php">
<MoreSpecificImplementedParamType occurrences="2">
<code>$password</code>
<code>$password</code>
<MoreSpecificImplementedParamType>
<code><![CDATA[$password]]></code>
<code><![CDATA[$password]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/PasswordHasher/FallbackPasswordHasher.php">
<MoreSpecificImplementedParamType occurrences="2">
<code>$password</code>
<code>$password</code>
<MoreSpecificImplementedParamType>
<code><![CDATA[$password]]></code>
<code><![CDATA[$password]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/PasswordHasher/LegacyPasswordHasher.php">
<MoreSpecificImplementedParamType occurrences="2">
<code>$password</code>
<code>$password</code>
<MoreSpecificImplementedParamType>
<code><![CDATA[$password]]></code>
<code><![CDATA[$password]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/UrlChecker/DefaultUrlChecker.php">
<NoInterfaceProperties occurrences="1">
<code>$uri-&gt;base</code>
<NoInterfaceProperties>
<code><![CDATA[$uri->base]]></code>
</NoInterfaceProperties>
</file>
</files>
1 change: 0 additions & 1 deletion src/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ public function isImpersonating(ServerRequestInterface $request): bool
*/
protected function getImpersonationProvider(): ImpersonationInterface
{
/** @var \Authentication\Authenticator\ImpersonationInterface $provider */
$provider = $this->getAuthenticationProvider();
if (!($provider instanceof ImpersonationInterface)) {
$className = get_class($provider);
Expand Down
2 changes: 1 addition & 1 deletion src/Authenticator/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Result implements ResultInterface
/**
* Sets the result status, identity, and failure messages
*
* @param null|array|\ArrayAccess $data The identity data
* @param null|array|\ArrayAccess|mixed $data The identity data
Copy link
Contributor Author

@LordSimal LordSimal Nov 17, 2024

Choose a reason for hiding this comment

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

These mixed types needed to be added since we check for this and manually throw an exception. Otherwise phpstan would complain, that the if() cannot be reached.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like we forgot to add types to this class when updating for 5.x. I would just add proper types to the props/methods and bump the plugin version as required to minor/major.

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 did not miss it, this is 2.x and therefore CakePHP 4
Or would you not update stan of the 2.x version of this plugin?

Copy link
Member

Choose a reason for hiding this comment

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

I wouldnt. Only cake5 ones IMO.

* @param string $status Status constant equivalent.
* @param array $messages Messages.
* @throws \InvalidArgumentException When invalid identity data is passed.
Expand Down
2 changes: 1 addition & 1 deletion src/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Identity implements IdentityInterface
/**
* Constructor
*
* @param array|\ArrayAccess $data Identity data
* @param array|\ArrayAccess|mixed $data Identity data
* @param array $config Config options
* @throws \InvalidArgumentException When invalid identity data is passed.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/AuthenticationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AuthenticationMiddleware implements MiddlewareInterface
/**
* Authentication service or application instance.
*
* @var \Authentication\AuthenticationServiceInterface|\Authentication\AuthenticationServiceProviderInterface
* @var \Authentication\AuthenticationServiceInterface|\Authentication\AuthenticationServiceProviderInterface|mixed
*/
protected $subject;

Expand All @@ -74,7 +74,7 @@ class AuthenticationMiddleware implements MiddlewareInterface
/**
* Constructor
*
* @param \Authentication\AuthenticationServiceInterface|\Authentication\AuthenticationServiceProviderInterface $subject Authentication service or application instance.
* @param \Authentication\AuthenticationServiceInterface|\Authentication\AuthenticationServiceProviderInterface|mixed $subject Authentication service or application instance.
* @param array $config Array of configuration settings.
* @param \Cake\Core\ContainerInterface|null $container The container instance from the application
* @throws \InvalidArgumentException When invalid subject has been passed.
Expand Down
Loading