Skip to content

Commit f7a945f

Browse files
authored
Replaced get_called_class with static::class. (hyperf#7276)
1 parent 241e77e commit f7a945f

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

CHANGELOG-3.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
## Optimized
1717

1818
- [#7258](https://github.com/hyperf/hyperf/pull/7258) Optimized code for reading package data from `composer.lock`.
19+
- [#7276](https://github.com/hyperf/hyperf/pull/7276) Replaced `get_called_class` with `static::class`.
1920

2021
# v3.1.50 - 2025-01-09
2122

src/model-cache/src/Cacheable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function deleteCache(): bool
5656
{
5757
$manager = $this->getContainer()->get(Manager::class);
5858

59-
return $manager->destroy([$this->getKey()], get_called_class());
59+
return $manager->destroy([$this->getKey()], static::class);
6060
}
6161

6262
/**
@@ -83,7 +83,7 @@ public function increment($column, $amount = 1, array $extra = [])
8383
// Only increment a column's value.
8484
/** @var Manager $manager */
8585
$manager = $this->getContainer()->get(Manager::class);
86-
$manager->increment($this->getKey(), $column, $amount, get_called_class());
86+
$manager->increment($this->getKey(), $column, $amount, static::class);
8787
} else {
8888
// Update other columns, when increment a column's value.
8989
$this->deleteCache();
@@ -108,7 +108,7 @@ public function decrement($column, $amount = 1, array $extra = [])
108108
// Only decrement a column's value.
109109
/** @var Manager $manager */
110110
$manager = $this->getContainer()->get(Manager::class);
111-
$manager->increment($this->getKey(), $column, -$amount, get_called_class());
111+
$manager->increment($this->getKey(), $column, -$amount, static::class);
112112
} else {
113113
// Update other columns, when decrement a column's value.
114114
$this->deleteCache();

src/scout/src/Searchable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ public function getScoutModelsByIds(Builder $builder, array $ids)
174174
*/
175175
public static function enableSearchSyncing(): void
176176
{
177-
ModelObserver::enableSyncingFor(get_called_class());
177+
ModelObserver::enableSyncingFor(static::class);
178178
}
179179

180180
/**
181181
* Disable search syncing for this model.
182182
*/
183183
public static function disableSearchSyncing(): void
184184
{
185-
ModelObserver::disableSyncingFor(get_called_class());
185+
ModelObserver::disableSyncingFor(static::class);
186186
}
187187

188188
/**
@@ -308,6 +308,6 @@ protected static function dispatchSearchableJob(callable $job): void
308308
*/
309309
protected static function usesSoftDelete(): bool
310310
{
311-
return in_array(SoftDeletes::class, class_uses_recursive(get_called_class()));
311+
return in_array(SoftDeletes::class, class_uses_recursive(static::class));
312312
}
313313
}

src/support/src/Traits/StaticInstance.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ trait StaticInstance
1818
{
1919
public static function instance(array $params = [], bool $refresh = false, string $suffix = ''): static
2020
{
21-
$key = get_called_class() . $suffix;
21+
$key = static::class . $suffix;
2222
$instance = null;
23+
2324
if (Context::has($key)) {
2425
$instance = Context::get($key);
2526
}

0 commit comments

Comments
 (0)