Skip to content

Commit acd51de

Browse files
authored
Merge pull request #16709 from noone-silent/T16705-remove-has-check
[#16705] - refactor: remove has() check in doGet().
2 parents 68861d7 + e737caa commit acd51de

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

CHANGELOG-5.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22

33
## [5.9.1](https://github.com/phalcon/cphalcon/releases/tag/v5.9.1) (2025-XX-XX)
44

5+
### Changed
6+
7+
- Changed `Phalcon\Storage\Adapter\AbstractAdapter` and dropped `has()` check before receiving the value. [#16705](https://github.com/phalcon/cphalcon/issues/16705)
8+
9+
### Added
10+
511
### Fixed
612

713
- Fixed `Phalcon\Mvc\Micro\LazyLoader::callMethod` to prevent `Unknown named parameter` error [#16724](https://github.com/phalcon/cphalcon/issues/16724)
814

15+
### Removed
16+
917
## [5.9.0](https://github.com/phalcon/cphalcon/releases/tag/v5.9.0) (2025-03-08)
1018

1119
### Changed

phalcon/Storage/Adapter/AbstractAdapter.zep

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,13 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
163163

164164
this->fire(this->eventType . ":beforeGet", key);
165165

166-
if (true !== this->has(key)) {
166+
let content = this->doGet(key);
167+
if (content === false) {
167168
this->fire(this->eventType . ":afterGet", key);
168169

169170
return defaultValue;
170171
}
171172

172-
let content = this->doGet(key);
173-
174173
let result = this->getUnserializedData(content, defaultValue);
175174

176175
this->fire(this->eventType . ":afterGet", key);

tests/integration/Cache/Adapter/Memory/EventsCest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function cacheCacheEventTriggers(IntegrationTester $I, Example $example):
7272
$manager = new Manager();
7373
$adapter->setEventsManager(new Manager());
7474

75+
// Avoid unset warning
76+
$adapter->set('test', 'test');
77+
7578
$manager->attach(
7679
'cache:' . $example->offsetGet(0),
7780
static function (Event $event) use (&$counter, $example): void {

tests/integration/Cache/Cache/GetEventsManagerCest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ static function () use (&$counter) {
8888

8989
$adapter->setEventsManager($manager);
9090

91+
// Avoid unset warning.
92+
if ($example->offsetGet(1) !== 'set' && $example->offsetGet(1) !== 'setMultiple') {
93+
$adapter->set('test', 'test');
94+
$adapter->set('test2', 'test2');
95+
}
96+
9197
$I->assertInstanceOf($manager::class, $adapter->getEventsManager());
9298

9399
call_user_func_array([$adapter, $example->offsetGet(1)], $example->offsetGet(2));

tests/integration/Storage/Adapter/EventsCest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function storageAdapterEventsBeforeGet(IntegrationTester $I, Example $exa
6161
)
6262
);
6363

64+
$adapter->set('test', 'test');
65+
6466
$manager->attach(
6567
'storage:beforeGet',
6668
static function (Event $event) use (&$counter, $example): void {
@@ -109,6 +111,8 @@ public function storageAdapterEventsAfterGet(IntegrationTester $I, Example $exam
109111
)
110112
);
111113

114+
$adapter->set('test', 'test');
115+
112116
$manager->attach(
113117
'storage:afterGet',
114118
static function (Event $event) use (&$counter, $example): void {
@@ -157,6 +161,8 @@ public function storageAdapterEventsBeforeHas(IntegrationTester $I, Example $exa
157161
)
158162
);
159163

164+
$adapter->set('test', 'test');
165+
160166
$manager->attach(
161167
'storage:beforeHas',
162168
static function (Event $event) use (&$counter, $example): void {
@@ -205,6 +211,8 @@ public function storageAdapterEventsAfterHas(IntegrationTester $I, Example $exam
205211
)
206212
);
207213

214+
$adapter->set('test', 'test');
215+
208216
$manager->attach(
209217
'storage:afterHas',
210218
static function (Event $event) use (&$counter, $example): void {
@@ -253,6 +261,8 @@ public function storageAdapterEventsBeforeDelete(IntegrationTester $I, Example $
253261
)
254262
);
255263

264+
$adapter->set('test', 'test');
265+
256266
$manager->attach(
257267
'storage:beforeDelete',
258268
static function (Event $event) use (&$counter, $example): void {
@@ -301,6 +311,8 @@ public function storageAdapterEventsAfterDelete(IntegrationTester $I, Example $e
301311
)
302312
);
303313

314+
$adapter->set('test', 'test');
315+
304316
$manager->attach(
305317
'storage:afterDelete',
306318
static function (Event $event) use (&$counter, $example): void {
@@ -349,6 +361,8 @@ public function storageAdapterEventsBeforeIncrement(IntegrationTester $I, Exampl
349361
)
350362
);
351363

364+
$adapter->set('test', 'test');
365+
352366
$manager->attach(
353367
'storage:beforeIncrement',
354368
static function (Event $event) use (&$counter, $example): void {
@@ -397,6 +411,8 @@ public function storageAdapterEventsAfterIncrement(IntegrationTester $I, Example
397411
)
398412
);
399413

414+
$adapter->set('test', 'test');
415+
400416
$manager->attach(
401417
'storage:afterIncrement',
402418
static function (Event $event) use (&$counter, $example): void {
@@ -445,6 +461,8 @@ public function storageAdapterEventsBeforeDecrement(IntegrationTester $I, Exampl
445461
)
446462
);
447463

464+
$adapter->set('test', 'test');
465+
448466
$manager->attach(
449467
'storage:beforeDecrement',
450468
static function (Event $event) use (&$counter, $example): void {
@@ -493,6 +511,8 @@ public function storageAdapterEventsAfterDecrement(IntegrationTester $I, Example
493511
)
494512
);
495513

514+
$adapter->set('test', 'test');
515+
496516
$manager->attach(
497517
'storage:afterDecrement',
498518
static function (Event $event) use (&$counter, $example): void {
@@ -541,6 +561,8 @@ public function storageAdapterEventsBeforeSet(IntegrationTester $I, Example $exa
541561
)
542562
);
543563

564+
$adapter->set('test', 'test');
565+
544566
$manager->attach(
545567
'storage:beforeSet',
546568
static function (Event $event) use (&$counter, $example): void {
@@ -589,6 +611,8 @@ public function storageAdapterEventsAfterSet(IntegrationTester $I, Example $exam
589611
)
590612
);
591613

614+
$adapter->set('test', 'test');
615+
592616
$manager->attach(
593617
'storage:afterSet',
594618
static function (Event $event) use (&$counter, $example): void {

0 commit comments

Comments
 (0)