Skip to content

Commit d773b4c

Browse files
committed
Replace Psalm with PHPstan
1 parent b969760 commit d773b4c

File tree

10 files changed

+62
-106
lines changed

10 files changed

+62
-106
lines changed

.github/workflows/php.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ jobs:
5151
with:
5252
# Should be the higest supported version, so we can use the newest tools
5353
php-version: '8.3'
54-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
55-
# optional performance gain for psalm: opcache
56-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, opcache, openssl, pcre, posix, spl, xml
54+
tools: composer, composer-require-checker, composer-unused, phpcs
55+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, ldap, mbstring, openssl, pcre, posix, spl, xml
5756

5857
- name: Setup problem matchers for PHP
5958
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
@@ -85,27 +84,13 @@ jobs:
8584
- name: PHP Code Sniffer
8685
run: phpcs
8786

88-
- name: Psalm
89-
continue-on-error: true
90-
run: |
91-
psalm -c psalm.xml \
92-
--show-info=true \
93-
--shepherd \
94-
--php-version=${{ steps.setup-php.outputs.php-version }}
95-
96-
- name: Psalm (testsuite)
87+
- name: PHPStan
9788
run: |
98-
psalm -c psalm-dev.xml \
99-
--show-info=true \
100-
--shepherd \
101-
--php-version=${{ steps.setup-php.outputs.php-version }}
89+
vendor/bin/phpstan analyze -c phpstan.neon --debug
10290
103-
- name: Psalter
91+
- name: PHPStan (testsuite)
10492
run: |
105-
psalm --alter \
106-
--issues=UnnecessaryVarAnnotation \
107-
--dry-run \
108-
--php-version=${{ steps.setup-php.outputs.php-version }}
93+
vendor/bin/phpstan analyze -c phpstan-dev.neon --debug
10994
11095
security:
11196
name: Security checks

phpstan-dev.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- tests

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src

psalm-dev.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

psalm.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Auth/Process/BaseFilter.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@
1717

1818
abstract class BaseFilter extends Auth\ProcessingFilter
1919
{
20-
// TODO: Support ldap:LDAPMulti, if possible
20+
/**
21+
* TODO: Support ldap:LDAPMulti, if possible
22+
*
23+
* @var string[]
24+
*/
2125
protected static array $ldapsources = ['ldap:Ldap', 'authX509:X509userCert'];
2226

2327
/**
2428
* List of attribute "alias's" linked to the real attribute
2529
* name. Used for abstraction / configuration of the LDAP
2630
* attribute names, which may change between dir service.
2731
*
28-
* @var array
32+
* @var array<mixed>
2933
*/
3034
protected array $attribute_map;
3135

3236
/**
3337
* The base DN of the LDAP connection. Used when searching the LDAP server.
3438
*
35-
* @var array
39+
* @var array<mixed.
3640
*/
3741
protected array $searchBase;
3842

@@ -64,7 +68,7 @@ abstract class BaseFilter extends Auth\ProcessingFilter
6468
* List of LDAP object types, used to determine the type of
6569
* object that a DN references.
6670
*
67-
* @var array
71+
* @var array<mixed>
6872
*/
6973
protected array $type_map;
7074

src/Auth/Source/Ldap.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Ldap extends UserPassBase
4949
/**
5050
* Constructor for this authentication source.
5151
*
52-
* @param array $info Information about this authentication source.
53-
* @param array $config Configuration.
52+
* @param array<mixed> $info Information about this authentication source.
53+
* @param array<mixed> $config Configuration.
5454
*/
5555
public function __construct(array $info, array $config)
5656
{
@@ -71,11 +71,15 @@ public function __construct(array $info, array $config)
7171
*
7272
* @param string $username The username the user wrote.
7373
* @param string $password The password the user wrote.
74-
* @param array|null $sasl_args SASL options
75-
* @return array Associative array with the users attributes.
74+
* @param array<mixed>|null $sasl_args SASL options
75+
* @return array<mixed> Associative array with the users attributes.
7676
*/
77-
protected function loginSasl(string $username, #[\SensitiveParameter]string $password, array $sasl_args = []): array
78-
{
77+
protected function loginSasl(
78+
string $username,
79+
#[\SensitiveParameter]
80+
string $password,
81+
array $sasl_args = [],
82+
): array {
7983
if (preg_match('/^\s*$/', $password)) {
8084
// The empty string is considered an anonymous bind to Symfony
8185
throw new Error\Error('WRONGUSERPASS');
@@ -110,7 +114,7 @@ protected function loginSasl(string $username, #[\SensitiveParameter]string $pas
110114
Assert::nullOrNotWhitespaceOnly($searchUsername);
111115

112116
$searchPassword = $this->ldapConfig->getOptionalString('search.password', null);
113-
Assert::nullOrnotWhitespaceOnly($searchPassword);
117+
Assert::nullOrNotWhitespaceOnly($searchPassword);
114118

115119
try {
116120
$this->connector->bind($searchUsername, $searchPassword);
@@ -164,7 +168,7 @@ protected function loginSasl(string $username, #[\SensitiveParameter]string $pas
164168
*
165169
* @param string $username The username the user wrote.
166170
* @param string $password The password the user wrote.
167-
* @return array Associative array with the users attributes.
171+
* @return array<mixed> Associative array with the users attributes.
168172
*/
169173
protected function login(string $username, #[\SensitiveParameter]string $password): array
170174
{
@@ -176,15 +180,15 @@ protected function login(string $username, #[\SensitiveParameter]string $passwor
176180
* Attempt to find a user's attributes given its username.
177181
*
178182
* @param string $username The username who's attributes we want.
179-
* @return array Associative array with the users attributes.
183+
* @return array<mixed> Associative array with the users attributes.
180184
*/
181185
public function getAttributes(string $username): array
182186
{
183187
$searchUsername = $this->ldapConfig->getOptionalString('search.username', null);
184188
Assert::nullOrNotWhitespaceOnly($searchUsername);
185189

186190
$searchPassword = $this->ldapConfig->getOptionalString('search.password', null);
187-
Assert::nullOrnotWhitespaceOnly($searchPassword);
191+
Assert::nullOrNotWhitespaceOnly($searchPassword);
188192

189193
try {
190194
$this->connector->bind($searchUsername, $searchPassword);
@@ -232,7 +236,7 @@ public function getAttributes(string $username): array
232236

233237
/**
234238
* @param \Symfony\Component\Ldap\Entry $entry
235-
* @return array
239+
* @return array<mixed>
236240
*/
237241
private function processAttributes(Entry $entry): array
238242
{

src/Auth/Source/LdapMulti.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ class LdapMulti extends UserPassOrgBase
3333

3434
/**
3535
* An array with mappings for organization => authsource.
36+
*
37+
* @var array<mixed>
3638
*/
3739
private array $mapping;
3840

3941
/**
4042
* An array with descriptions for organizations.
43+
*
44+
* @var array<mixed>
4145
*/
4246
private array $orgs;
4347

4448
/**
4549
* An array of organization IDs to LDAP configuration objects.
50+
*
51+
* @var array<mixed>
4652
*/
4753
private array $ldapOrgs;
4854

@@ -55,8 +61,8 @@ class LdapMulti extends UserPassOrgBase
5561
/**
5662
* Constructor for this authentication source.
5763
*
58-
* @param array $info Information about this authentication source.
59-
* @param array $config Configuration.
64+
* @param array<mixed> $info Information about this authentication source.
65+
* @param array<mixed> $config Configuration.
6066
*/
6167
public function __construct(array $info, array $config)
6268
{
@@ -109,9 +115,9 @@ public function __construct(array $info, array $config)
109115
*
110116
* @param string $username The username the user wrote.
111117
* @param string $password The password the user wrote.
112-
* @param string $organizaion The organization the user chose.
113-
* @param array|null $sasl_args SASL options
114-
* @return array Associative array with the users attributes.
118+
* @param string $organization The organization the user chose.
119+
* @param array<mixed>|null $sasl_args SASL options
120+
* @return array<mixed> Associative array with the users attributes.
115121
*/
116122
protected function loginSasl(
117123
string $username,
@@ -134,6 +140,10 @@ protected function loginSasl(
134140

135141
$ldap = new class (['AuthId' => $authsource], $sourceConfig->toArray()) extends Ldap
136142
{
143+
/**
144+
* @param array<mixed> $sasl_args
145+
* @return array<mixed>
146+
*/
137147
public function loginOverload(
138148
string $username,
139149
#[\SensitiveParameter]string $password,
@@ -146,23 +156,25 @@ public function loginOverload(
146156
return $ldap->loginOverload($username, $password, $sasl_args);
147157
}
148158

159+
149160
/**
150161
* Attempt to log in using the given username and password.
151162
*
152163
* @param string $username The username the user wrote.
153164
* @param string $password The password the user wrote.
154-
* @param string $organizaion The organization the user chose.
155-
* @return array Associative array with the users attributes.
165+
* @param string $organization The organization the user chose.
166+
* @return array<mixed> Associative array with the users attributes.
156167
*/
157168
protected function login(string $username, #[\SensitiveParameter]string $password, string $organization): array
158169
{
159170
return $this->loginSasl($username, $password, $organization);
160171
}
161172

173+
162174
/**
163175
* Retrieve list of organizations.
164176
*
165-
* @return array Associative array with the organizations.
177+
* @return array<mixed> Associative array with the organizations.
166178
*/
167179
protected function getOrganizations(): array
168180
{

src/Connector/Ldap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Ldap implements ConnectorInterface
4444
* @param int $version
4545
* @param string $extension
4646
* @param bool $debug
47-
* @param array $options
47+
* @param array<mixed> $options
4848
*/
4949
public function __construct(
5050
string $connection_strings,

src/ConnectorInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public function whoami(): string;
6464
/**
6565
* Search the LDAP-directory for a specific object
6666
*
67-
* @param array $searchBase
67+
* @param string[] $searchBase
6868
* @param string $filter
69-
* @param array $options
69+
* @param array<mixed> $options
7070
* @param boolean $allowMissing
7171
* @return \Symfony\Component\Ldap\Entry|null The result of the search or null if none found
7272
* @psalm-return ($allowMissing is true ? \Symfony\Component\Ldap\Entry|null : \Symfony\Component\Ldap\Entry)
@@ -85,9 +85,9 @@ public function search(
8585
/**
8686
* Search the LDAP-directory for any object matching the search filter
8787
*
88-
* @param array $searchBase
88+
* @param string[] $searchBase
8989
* @param string $filter
90-
* @param array $options
90+
* @param array<mixed> $options
9191
* @param boolean $allowMissing
9292
* @return \Symfony\Component\Ldap\Entry[] The result of the search
9393
*

0 commit comments

Comments
 (0)