Skip to content

Commit a1902e1

Browse files
committed
refactor: fix static code analysis problems
1 parent 628c41d commit a1902e1

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

app/Config/Encryption.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Encryption extends BaseConfig
2929
* --------------------------------------------------------------------------
3030
* If you want to enable decryption using previous keys, set them here.
3131
* See the user guide for more info.
32+
*
33+
* @var array<string>|string
3234
*/
3335
public array|string $previousKeys = '';
3436

system/Encryption/Handlers/OpenSSLHandler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class OpenSSLHandler extends BaseHandler
5858

5959
/**
6060
* List of previous keys for fallback decryption.
61+
*
62+
* @var array<string>|string
6163
*/
6264
protected array|string $previousKeys = '';
6365

@@ -135,7 +137,7 @@ public function decrypt($data, #[SensitiveParameter] $params = null)
135137
// Only use fallback keys if no custom key was provided in params
136138
$useFallback = ! isset($params['key']);
137139

138-
$attemptDecrypt = function ($key) use ($data) {
140+
$attemptDecrypt = function ($key) use ($data): array {
139141
try {
140142
$result = $this->decryptWithKey($data, $key);
141143

@@ -154,7 +156,7 @@ public function decrypt($data, #[SensitiveParameter] $params = null)
154156
$originalException = $result['exception'];
155157

156158
// If primary key failed and fallback is allowed, try previous keys
157-
if ($useFallback && ! empty($this->previousKeys)) {
159+
if ($useFallback && ! in_array($this->previousKeys, ['', '0', []], true)) {
158160
foreach ($this->previousKeys as $previousKey) {
159161
$fallbackResult = $attemptDecrypt($previousKey);
160162

system/Encryption/Handlers/SodiumHandler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class SodiumHandler extends BaseHandler
3333

3434
/**
3535
* List of previous keys for fallback decryption.
36+
*
37+
* @var array<string>|string
3638
*/
3739
protected array|string $previousKeys = '';
3840

@@ -88,7 +90,7 @@ public function decrypt($data, #[SensitiveParameter] $params = null)
8890
// Only use fallback keys if no custom key was provided in params
8991
$useFallback = ! isset($params['key']);
9092

91-
$attemptDecrypt = function ($key) use ($data) {
93+
$attemptDecrypt = function ($key) use ($data): array {
9294
try {
9395
$result = $this->decryptWithKey($data, $key);
9496
sodium_memzero($key);
@@ -110,7 +112,7 @@ public function decrypt($data, #[SensitiveParameter] $params = null)
110112
$originalException = $result['exception'];
111113

112114
// If primary key failed and fallback is allowed, try previous keys
113-
if ($useFallback && ! empty($this->previousKeys)) {
115+
if ($useFallback && ! in_array($this->previousKeys, ['', '0', []], true)) {
114116
foreach ($this->previousKeys as $previousKey) {
115117
$fallbackResult = $attemptDecrypt($previousKey);
116118

0 commit comments

Comments
 (0)