Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [8.1, 8.0]
php: [8.1, 8.0, 7.4]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]

Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^8.0"
"php": "^7.4 || ^8.0"
},
"require-dev": {
"pestphp/pest": "^1.21",
Expand All @@ -42,6 +42,9 @@
"test": "vendor/bin/pest"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
4 changes: 2 additions & 2 deletions src/Backtrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getObjectName(): ?string
return $this->trace['class'] ?? null;
}

public function getObject(): mixed
public function getObject()
{
if ($this->globalFunction()) {
return $this->zeroStack['file'];
Expand All @@ -46,7 +46,7 @@ public function getHash(): string
}, $this->getArguments());

$prefix = $this->getObjectName() . $this->getFunctionName();
if (str_contains($prefix, '{closure}')) {
if (strpos($prefix, '{closure}') !== false) {
$prefix = $this->zeroStack['line'];
}

Expand Down
16 changes: 8 additions & 8 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
namespace Spatie\Once;

use Countable;
use WeakMap;
use SplObjectStorage;

class Cache implements Countable
{
protected static self $cache;

public WeakMap $values;
public SplObjectStorage $values;

protected bool $enabled = true;

public static function getInstance(): static
public static function getInstance(): self
{
return static::$cache ??= new static;
return static::$cache ??= new self;
}

protected function __construct()
{
$this->values = new WeakMap();
$this->values = new SplObjectStorage();
}

public function has(object $object, string $backtraceHash): bool
Expand All @@ -33,12 +33,12 @@ public function has(object $object, string $backtraceHash): bool
return array_key_exists($backtraceHash, $this->values[$object]);
}

public function get($object, string $backtraceHash): mixed
public function get($object, string $backtraceHash)
{
return $this->values[$object][$backtraceHash];
}

public function set(object $object, string $backtraceHash, mixed $value): void
public function set(object $object, string $backtraceHash, $value): void
{
$cached = $this->values[$object] ?? [];

Expand All @@ -54,7 +54,7 @@ public function forget(object $object): void

public function flush(): self
{
$this->values = new WeakMap();
$this->values = new SplObjectStorage();

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @param (callable(): T) $callback
* @return T
*/
function once(callable $callback): mixed
function once(callable $callback)
{
$trace = debug_backtrace(
DEBUG_BACKTRACE_PROVIDE_OBJECT, 2
Expand Down