Skip to content

Commit 2a0d555

Browse files
committed
Fix phpstan-issues
1 parent 92a71ae commit 2a0d555

7 files changed

Lines changed: 32 additions & 28 deletions

File tree

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
}
2323
},
2424
"require": {
25-
"php": "^8.3"
26-
},
27-
"require-dev": {
2825
"php": "^8.3",
2926
"ext-curl": "*",
3027

src/ArrayLogger.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use SimpleSAML\Configuration;
88
use SimpleSAML\Logger\LoggingHandlerInterface;
99

10+
use function array_merge;
11+
1012
/**
1113
*/
1214
class ArrayLogger implements LoggingHandlerInterface
1315
{
1416
/**
15-
* @var array List of log entries by level
17+
* @var array<int, array<string>> List of log entries by level
1618
*/
1719
public array $logs = [];
1820

@@ -24,9 +26,9 @@ public function __construct(Configuration $config)
2426
}
2527

2628

27-
public function log(int $level, string $string): void
29+
public function log(int $level, string $str): void
2830
{
29-
$this->logs[$level][] = $string;
31+
$this->logs[$level] = array_merge($this->logs[$level], [$str]);
3032
}
3133

3234

src/BuiltInServer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ public function setRouter(string $router): void
206206
* This function performs an HTTP GET request to the built-in server.
207207
*
208208
* @param string $query The query to perform.
209-
* @param array $parameters An array (can be empty) with parameters for the requested URI.
210-
* @param array $curlopts An array (can be empty) with options for cURL.
209+
* @param array<mixed> $parameters An array (can be empty) with parameters for the requested URI.
210+
* @param array<mixed> $curlopts An array (can be empty) with options for cURL.
211211
*
212-
* @return array The response obtained from the built-in server.
212+
* @return array<mixed> The response obtained from the built-in server.
213213
*/
214214
public function get(string $query, array $parameters, array $curlopts = []): array
215215
{
@@ -218,12 +218,12 @@ public function get(string $query, array $parameters, array $curlopts = []): arr
218218
$url .= (!empty($parameters)) ? '?' . http_build_query($parameters) : '';
219219
curl_setopt_array($ch, [
220220
CURLOPT_URL => $url,
221-
CURLOPT_RETURNTRANSFER => 1,
222-
CURLOPT_HEADER => 1,
221+
CURLOPT_RETURNTRANSFER => true,
222+
CURLOPT_HEADER => true,
223223
]);
224224
curl_setopt_array($ch, $curlopts);
225225

226-
/** @var mixed $resp */
226+
/** @var string|bool $resp */
227227
$resp = curl_exec($ch);
228228
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
229229
list($header, $body) = explode("\r\n\r\n", $resp, 2);

src/InMemoryStore.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
class InMemoryStore implements ClearableState, StoreInterface
1818
{
19+
/** @var array<mixed> */
1920
private static array $store = [];
2021

2122

src/SigningTestCase.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,7 @@ class SigningTestCase extends TestCase
4444

4545

4646
/**
47-
* Constructor
48-
*/
49-
public function __construct()
50-
{
51-
$this->root_directory = dirname(dirname(__FILE__));
52-
$base = $this->root_directory . DIRECTORY_SEPARATOR . $this->cert_directory;
53-
$this->ca_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_private_key_file);
54-
$this->ca_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_certificate_file);
55-
$this->good_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_private_key_file);
56-
$this->good_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_certificate_file);
57-
}
58-
59-
60-
/**
47+
* @return array<mixed>
6148
*/
6249
public function getCertDirContent(): array
6350
{
@@ -74,6 +61,13 @@ public function getCertDirContent(): array
7461
*/
7562
public function setUp(): void
7663
{
64+
$this->root_directory = dirname(dirname(__FILE__));
65+
$base = $this->root_directory . DIRECTORY_SEPARATOR . $this->cert_directory;
66+
$this->ca_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_private_key_file);
67+
$this->ca_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_certificate_file);
68+
$this->good_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_private_key_file);
69+
$this->good_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_certificate_file);
70+
7771
$this->config = Configuration::loadFromArray([
7872
'certdir' => $this->cert_directory,
7973
], '[ARRAY]', 'simplesaml');

src/SimpleTestLogger.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
final class SimpleTestLogger extends AbstractLogger
1919
{
2020
/**
21+
* @var array<string>
2122
*/
2223
private array $messages = [];
2324

@@ -41,10 +42,12 @@ public function log($level, string|Stringable $message, array $context = []): vo
4142
* Get all the messages logged at the specified level
4243
*
4344
* @param mixed $level
45+
* @return array<mixed> $level
4446
*/
4547
public function getMessagesForLevel($level): array
4648
{
47-
return array_filter($this->messages, function (string $message) use ($level) {
49+
// @phpstan-ignore argument.type
50+
return array_filter($this->messages, function (array $message) use ($level) {
4851
return $message['level'] === $level;
4952
});
5053
}
@@ -57,7 +60,8 @@ public function getMessagesForLevel($level): array
5760
*/
5861
public function hasMessage(string|Stringable $messageToFind): bool
5962
{
60-
$count = array_filter($this->messages, function ($message) use ($messageToFind) {
63+
// @phpstan-ignore argument.type
64+
$count = array_filter($this->messages, function (array $message) use ($messageToFind) {
6165
return $message['message'] === $messageToFind;
6266
});
6367

src/StateClearer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ class StateClearer
1616
{
1717
/**
1818
* Global state to restore between test runs
19+
*
20+
* @var array<mixed>
1921
*/
2022
private array $backups = [];
2123

2224
/**
2325
* Class that implement \SimpleSAML\Utils\ClearableState and should have clearInternalState called between tests
26+
*
27+
* @var array<mixed>
2428
*/
2529
private array $clearableState = [
2630
Configuration::class,
@@ -31,6 +35,8 @@ class StateClearer
3135

3236
/**
3337
* Environmental variables to unset
38+
*
39+
* @var array<mixed>
3440
*/
3541
private array $vars_to_unset = ['SIMPLESAMLPHP_CONFIG_DIR'];
3642

0 commit comments

Comments
 (0)