Skip to content

Commit ef269be

Browse files
authored
chore: clean files for PHP 8.4 (#259)
1 parent 7ae8440 commit ef269be

22 files changed

+95
-325
lines changed

src/ArrayManager.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Rancoud\Session;
66

7-
/**
8-
* Trait ArrayManager.
9-
*/
107
trait ArrayManager
118
{
129
protected static array $flashData = [];
@@ -17,9 +14,7 @@ abstract protected static function startSessionIfNotHasStarted();
1714
/** @throws SessionException */
1815
abstract protected static function startSessionIfNotHasStartedForceWrite();
1916

20-
/**
21-
* @throws SessionException
22-
*/
17+
/** @throws SessionException */
2318
public static function set(string $key, $value): void
2419
{
2520
static::startSessionIfNotHasStartedForceWrite();
@@ -35,9 +30,7 @@ public static function has(string $key): bool
3530
return \array_key_exists($key, $_SESSION);
3631
}
3732

38-
/**
39-
* @throws SessionException
40-
*/
33+
/** @throws SessionException */
4134
public static function hasKeyAndValue(string $key, $value): bool
4235
{
4336
static::startSessionIfNotHasStarted();

src/Database.php

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
use Rancoud\Database\Database as DB;
1111
use Rancoud\Database\DatabaseException;
1212

13-
/**
14-
* Class Database.
15-
*/
1613
class Database implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
1714
{
1815
protected DB $db;
@@ -21,12 +18,8 @@ class Database implements \SessionHandlerInterface, \SessionUpdateTimestampHandl
2118

2219
protected int $lengthSessionID = 127;
2320

24-
/**
25-
* @param array|Configurator $configuration
26-
*
27-
* @throws SessionException
28-
*/
29-
public function setNewDatabase($configuration): void
21+
/** @throws SessionException */
22+
public function setNewDatabase(array|Configurator $configuration): void
3023
{
3124
try {
3225
if ($configuration instanceof Configurator) {
@@ -64,11 +57,7 @@ public function getLengthSessionID(): int
6457
return $this->lengthSessionID;
6558
}
6659

67-
/**
68-
* @param string $path
69-
* @param string $name
70-
*/
71-
public function open($path, $name): bool
60+
public function open(string $path, string $name): bool
7261
{
7362
return true;
7463
}
@@ -78,12 +67,8 @@ public function close(): bool
7867
return true;
7968
}
8069

81-
/**
82-
* @param string $id
83-
*
84-
* @throws SessionException
85-
*/
86-
public function read($id): string
70+
/** @throws SessionException */
71+
public function read(string $id): string
8772
{
8873
try {
8974
$sql = 'SELECT content FROM sessions WHERE id = :id';
@@ -95,13 +80,8 @@ public function read($id): string
9580
}
9681
}
9782

98-
/**
99-
* @param string $id
100-
* @param string $data
101-
*
102-
* @throws SessionException
103-
*/
104-
public function write($id, $data): bool
83+
/** @throws SessionException */
84+
public function write(string $id, string $data): bool
10585
{
10686
try {
10787
$sql = 'REPLACE INTO sessions VALUES(:id, :id_user, UTC_TIMESTAMP(), :content)';
@@ -115,12 +95,8 @@ public function write($id, $data): bool
11595
}
11696
}
11797

118-
/**
119-
* @param string $id
120-
*
121-
* @throws SessionException
122-
*/
123-
public function destroy($id): bool
98+
/** @throws SessionException */
99+
public function destroy(string $id): bool
124100
{
125101
try {
126102
$sql = 'DELETE FROM sessions WHERE id = :id';
@@ -133,13 +109,9 @@ public function destroy($id): bool
133109
}
134110
}
135111

136-
/**
137-
* @param int $max_lifetime
138-
*
139-
* @throws SessionException
140-
*/
112+
/** @throws SessionException */
141113
#[\ReturnTypeWillChange]
142-
public function gc($max_lifetime): bool
114+
public function gc(int $max_lifetime): bool
143115
{
144116
try {
145117
$sql = 'DELETE FROM sessions WHERE DATE_ADD(last_access, INTERVAL :seconds second) < UTC_TIMESTAMP()';
@@ -155,13 +127,9 @@ public function gc($max_lifetime): bool
155127
/**
156128
* Checks format and id exists, if not session_id will be regenerate.
157129
*
158-
* @param string $id
159-
*
160130
* @throws SessionException
161-
*
162-
* @noinspection PhpMissingParamTypeInspection
163131
*/
164-
public function validateId($id): bool
132+
public function validateId(string $id): bool
165133
{
166134
try {
167135
if (\preg_match('/^[a-zA-Z0-9-]{' . $this->lengthSessionID . '}+$/', $id) !== 1) {
@@ -181,14 +149,9 @@ public function validateId($id): bool
181149
/**
182150
* Updates the timestamp of a session when its data didn't change.
183151
*
184-
* @param string $id
185-
* @param string $data
186-
*
187152
* @throws SessionException
188-
*
189-
* @noinspection PhpMissingParamTypeInspection
190153
*/
191-
public function updateTimestamp($id, $data): bool
154+
public function updateTimestamp(string $id, string $data): bool
192155
{
193156
return $this->write($id, $data);
194157
}

src/DatabaseEncryption.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,20 @@
44

55
namespace Rancoud\Session;
66

7-
/**
8-
* Class DatabaseEncryption.
9-
*/
107
class DatabaseEncryption extends Database
118
{
129
use Encryption;
1310

14-
/**
15-
* @param string $id
16-
*
17-
* @throws SessionException
18-
*/
19-
public function read($id): string
11+
/** @throws SessionException */
12+
public function read(string $id): string
2013
{
2114
$encryptedData = parent::read($id);
2215

2316
return $this->decrypt($encryptedData);
2417
}
2518

26-
/**
27-
* @param string $id
28-
* @param string $data
29-
*
30-
* @throws SessionException
31-
*/
32-
public function write($id, $data): bool
19+
/** @throws SessionException */
20+
public function write(string $id, string $data): bool
3321
{
3422
$cryptedData = $this->encrypt($data);
3523

src/DefaultEncryption.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,20 @@
44

55
namespace Rancoud\Session;
66

7-
/**
8-
* Class DefaultEncryption.
9-
*/
107
class DefaultEncryption extends \SessionHandler
118
{
129
use Encryption;
1310

14-
/**
15-
* @param string $id
16-
*
17-
* @throws SessionException
18-
*/
19-
public function read($id): string
11+
/** @throws SessionException */
12+
public function read(string $id): string
2013
{
2114
$encryptedData = parent::read($id);
2215

2316
return $this->decrypt($encryptedData);
2417
}
2518

26-
/**
27-
* @param string $id
28-
* @param string $data
29-
*
30-
* @throws SessionException
31-
*/
32-
public function write($id, $data): bool
19+
/** @throws SessionException */
20+
public function write(string $id, string $data): bool
3321
{
3422
$cryptedData = $this->encrypt($data);
3523

src/DriverManager.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use Rancoud\Database\Configurator;
99
use Rancoud\Database\Database as DB;
1010

11-
/**
12-
* Class DriverManager.
13-
*/
1411
abstract class DriverManager
1512
{
1613
protected static ?\SessionHandlerInterface $driver = null;
@@ -66,12 +63,8 @@ public static function useFileEncryptionDriver(string $key, ?string $method = nu
6663
static::$driver = $driver;
6764
}
6865

69-
/**
70-
* @param array|Configurator $configuration
71-
*
72-
* @throws SessionException
73-
*/
74-
public static function useNewDatabaseDriver($configuration): void
66+
/** @throws SessionException */
67+
public static function useNewDatabaseDriver(array|Configurator $configuration): void
7568
{
7669
static::throwExceptionIfHasStarted();
7770

@@ -92,12 +85,8 @@ public static function useCurrentDatabaseDriver(DB $databaseInstance): void
9285
static::$driver = $driver;
9386
}
9487

95-
/**
96-
* @param array|Configurator $configuration
97-
*
98-
* @throws SessionException
99-
*/
100-
public static function useNewDatabaseEncryptionDriver($configuration, string $key, ?string $method = null): void
88+
/** @throws SessionException */
89+
public static function useNewDatabaseEncryptionDriver(array|Configurator $configuration, string $key, ?string $method = null): void
10190
{
10291
static::throwExceptionIfHasStarted();
10392

@@ -120,12 +109,8 @@ public static function useCurrentDatabaseEncryptionDriver(DB $databaseInstance,
120109
static::$driver = $driver;
121110
}
122111

123-
/**
124-
* @param array|string $configuration
125-
*
126-
* @throws SessionException
127-
*/
128-
public static function useNewRedisDriver($configuration): void
112+
/** @throws SessionException */
113+
public static function useNewRedisDriver(array|string $configuration): void
129114
{
130115
static::throwExceptionIfHasStarted();
131116

@@ -148,12 +133,8 @@ public static function useCurrentRedisDriver(PredisClient $redisInstance): void
148133
static::$driver = $driver;
149134
}
150135

151-
/**
152-
* @param array|string $configuration
153-
*
154-
* @throws SessionException
155-
*/
156-
public static function useNewRedisEncryptionDriver($configuration, string $key, ?string $method = null): void
136+
/** @throws SessionException */
137+
public static function useNewRedisEncryptionDriver(array|string $configuration, string $key, ?string $method = null): void
157138
{
158139
static::throwExceptionIfHasStarted();
159140

@@ -182,10 +163,8 @@ public static function useCurrentRedisEncryptionDriver(PredisClient $redisInstan
182163
* @param Encryption $driver (use Encryption trait)
183164
*
184165
* @throws SessionException
185-
*
186-
* @noinspection PhpMissingParamTypeInspection
187166
*/
188-
private static function setKeyAndMethod($driver, string $key, ?string $method): void
167+
private static function setKeyAndMethod(mixed $driver, string $key, ?string $method): void
189168
{
190169
$driver->setKey($key);
191170
if ($method !== null) {

src/Encryption.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Rancoud\Session;
66

7-
/**
8-
* Trait Encryption.
9-
*/
107
trait Encryption
118
{
129
protected ?string $key = null;
@@ -66,11 +63,8 @@ public function getAvailableMethods(): array
6663

6764
return \array_filter($methods, static function ($c) {
6865
$forbiddenMethods = [
69-
'aes-128-cbc-hmac-sha1', 'aes-256-cbc-hmac-sha1'
70-
];
71-
72-
\array_push(
73-
$forbiddenMethods,
66+
'aes-128-cbc-hmac-sha1',
67+
'aes-256-cbc-hmac-sha1',
7468
'aes-128-cbc-cts',
7569
'aes-128-cbc-hmac-sha256',
7670
'aes-128-siv',
@@ -113,10 +107,9 @@ public function getAvailableMethods(): array
113107
'2.16.840.1.101.3.4.1.7',
114108
'1.2.156.10197.1.104.1',
115109
'1.2.156.10197.1.104.8',
116-
'1.2.156.10197.1.104.9'
117-
);
118-
119-
$forbiddenMethods[] = 'chacha20-poly1305';
110+
'1.2.156.10197.1.104.9',
111+
'chacha20-poly1305'
112+
];
120113

121114
return !\in_array(\mb_strtolower($c), $forbiddenMethods, true);
122115
});
@@ -154,7 +147,7 @@ public function encrypt(string $data): string
154147
if ($length === false || $length < 1) {
155148
throw new SessionException('IV generation failed');
156149
}
157-
} catch (\Exception $e) {
150+
} catch (\Exception) {
158151
throw new SessionException('IV generation failed');
159152
}
160153

0 commit comments

Comments
 (0)