Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -23,23 +23,16 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Cache;
use Illuminate\Support\Collection;
use JsonException;
/**
* Class CacheProperties.
*
*/
class CacheProperties
{
protected string $hash = '';
protected Collection $properties;
/**
*
*/
public function __construct()
{
$this->properties = new Collection();
@@ -62,20 +55,14 @@ class CacheProperties
*/
public function get()
{
return Cache::get($this->hash);
return \Cache::get($this->hash);
}
/**
* @return string
*/
public function getHash(): string
{
return $this->hash;
}
/**
* @return bool
*/
public function has(): bool
{
if ('testing' === config('app.env')) {
@@ -83,23 +70,7 @@ class CacheProperties
}
$this->hash();
return Cache::has($this->hash);
}
/**
*/
private function hash(): void
{
$content = '';
foreach ($this->properties as $property) {
try {
$content .= json_encode($property, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
// @ignoreException
$content .= hash('sha256', (string)time());
}
}
$this->hash = substr(hash('sha256', $content), 0, 16);
return \Cache::has($this->hash);
}
/**
@@ -107,6 +78,20 @@ class CacheProperties
*/
public function store($data): void
{
Cache::forever($this->hash, $data);
\Cache::forever($this->hash, $data);
}
private function hash(): void
{
$content = '';
foreach ($this->properties as $property) {
try {
$content .= json_encode($property, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
// @ignoreException
$content .= hash('sha256', (string)time());
}
}
$this->hash = substr(hash('sha256', $content), 0, 16);
}
}