Skip to content

Commit 7ef1f3e

Browse files
committed
refactor(Utils): Simplify array merging in defined and required properties
- Refactored the return statement to directly merge defined and required properties without unnecessary array conversion. - Improved code readability and performance by eliminating redundant calls. - Updated MemoryCacheTest to use toBeEmpty() for clearer intent. - Adjusted composer.json to update dependency versions for peststan and cognitive-complexity.
1 parent e0b31ad commit 7ef1f3e

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"illuminate/support": "^12.56 || ^13.0",
104104
"jbelien/phpstan-sarif-formatter": "^1.2",
105105
"mockery/mockery": "^1.6",
106-
"mrpunyapal/peststan": "^0.1 || ^0.2",
106+
"mrpunyapal/peststan": "^0.2",
107107
"mrpunyapal/rector-pest": "^0.2",
108108
"nette/utils": "^4.1",
109109
"nicksdot/phpstan-phpstorm-error-identifiers": "^0.3",
@@ -141,7 +141,7 @@
141141
"symplify/easy-coding-standard": "^13.0",
142142
"symplify/phpstan-rules": "^14.9",
143143
"tomasvotruba/class-leak": "^2.1",
144-
"tomasvotruba/cognitive-complexity": "^1.0",
144+
"tomasvotruba/cognitive-complexity": "^1.1",
145145
"tomasvotruba/ctor": "^2.2",
146146
"tomasvotruba/type-coverage": "^2.1",
147147
"tomasvotruba/unused-public": "^2.2",

src/Foundation/Support/Utils.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,21 @@ class Utils
3030
/**
3131
* Return an array of defined properties for the given object.
3232
*
33-
* @param class-string<\Guanguans\Notify\Foundation\Message>|\Guanguans\Notify\Foundation\Message $object
33+
* @param class-string<\Guanguans\Notify\Foundation\Message>|\Guanguans\Notify\Foundation\Message $message
3434
*
3535
* @throws \ReflectionException
3636
*
3737
* @return list<string>
3838
*/
39-
public static function definedFor(Message|string $object): array
39+
public static function definedFor(Message|string $message): array
4040
{
41-
if (\is_string($object)) {
42-
$properties = (new \ReflectionClass($object))->getDefaultProperties();
43-
44-
return array_unique([...(array) ($properties['defined'] ?? []), ...(array) ($properties['required'] ?? [])]);
41+
if (\is_object($message)) {
42+
return array_unique((fn (): array => [...$this->defined, ...$this->required])->call($message));
4543
}
4644

47-
return array_unique(
48-
(fn (): array => [...$this->defined ?? [], ...$this->required ?? []])->call($object)
49-
);
45+
$properties = (new \ReflectionClass($message))->getDefaultProperties();
46+
47+
return array_unique([...(array) ($properties['defined'] ?? []), ...(array) ($properties['required'] ?? [])]);
5048
}
5149

5250
/**

tests/Foundation/Caches/MemoryCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
expect($this->memoryCache->getKeys())->toHaveCount(2);
102102
$this->memoryCache->clear();
103-
expect($this->memoryCache->getKeys())->toHaveCount(0);
103+
expect($this->memoryCache->getKeys())->toBeEmpty();
104104
})->group(__DIR__, __FILE__);
105105

106106
it('get multiple', function (): void {

0 commit comments

Comments
 (0)