Refactor old methods.

This commit is contained in:
James Cole
2021-04-06 13:30:09 +02:00
parent 5ceef2e9c3
commit 69b1769f22
54 changed files with 191 additions and 478 deletions

View File

@@ -23,9 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Cache;
use Carbon\Carbon;
use FireflyIII\Models\Category;
use Illuminate\Support\Collection;
use JsonException;
/**
* Class CacheProperties.
@@ -34,10 +33,8 @@ use Illuminate\Support\Collection;
*/
class CacheProperties
{
/** @var string */
protected $hash = '';
/** @var Collection */
protected $properties;
protected string $hash = '';
protected Collection $properties;
/**
*
@@ -52,8 +49,7 @@ class CacheProperties
}
/**
* @param $property
* @param Collection|Carbon|Category|array|int|string $property
* @param mixed $property
*/
public function addProperty($property): void
{
@@ -90,19 +86,24 @@ class CacheProperties
}
/**
* @throws JsonException
*/
private function hash(): void
{
$content = '';
foreach ($this->properties as $property) {
$content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
try {
$content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
} catch (JsonException $e) {
// @ignoreException
$content .= md5(time());
}
}
$this->hash = substr(hash('sha256', $content), 0, 16);
}
/**
* @param $data
* @param (array|mixed)[]|Collection|\Carbon\Carbon|string $data
* @param mixed $data
*/
public function store($data): void
{