mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 23:34:58 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -15,19 +15,11 @@ use Base64Url\Base64Url;
|
||||
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Exception\StoredObjectManagerException;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
use Throwable;
|
||||
use function array_key_exists;
|
||||
use const OPENSSL_RAW_DATA;
|
||||
|
||||
final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
{
|
||||
@@ -37,7 +29,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
|
||||
public function __construct(private readonly HttpClientInterface $client, private readonly TempUrlGeneratorInterface $tempUrlGenerator) {}
|
||||
|
||||
public function getLastModified(StoredObject $document): DateTimeInterface
|
||||
public function getLastModified(StoredObject $document): \DateTimeInterface
|
||||
{
|
||||
if ($this->hasCache($document)) {
|
||||
$response = $this->getResponseFromCache($document);
|
||||
@@ -69,7 +61,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
|
||||
try {
|
||||
$data = $response->getContent();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
throw StoredObjectManagerException::unableToGetResponseContent($e);
|
||||
}
|
||||
|
||||
@@ -82,7 +74,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
self::ALGORITHM,
|
||||
// TODO: Why using this library and not use base64_decode() ?
|
||||
Base64Url::decode($document->getKeyInfos()['k']),
|
||||
OPENSSL_RAW_DATA,
|
||||
\OPENSSL_RAW_DATA,
|
||||
pack('C*', ...$document->getIv())
|
||||
);
|
||||
|
||||
@@ -105,7 +97,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
self::ALGORITHM,
|
||||
// TODO: Why using this library and not use base64_decode() ?
|
||||
Base64Url::decode($document->getKeyInfos()['k']),
|
||||
OPENSSL_RAW_DATA,
|
||||
\OPENSSL_RAW_DATA,
|
||||
pack('C*', ...$document->getIv())
|
||||
)
|
||||
: $clearContent;
|
||||
@@ -130,24 +122,23 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
throw StoredObjectManagerException::errorDuringHttpRequest($exception);
|
||||
}
|
||||
|
||||
if ($response->getStatusCode() !== Response::HTTP_CREATED) {
|
||||
if (Response::HTTP_CREATED !== $response->getStatusCode()) {
|
||||
throw StoredObjectManagerException::invalidStatusCode($response->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
private function extractLastModifiedFromResponse(ResponseInterface $response): DateTimeImmutable
|
||||
private function extractLastModifiedFromResponse(ResponseInterface $response): \DateTimeImmutable
|
||||
{
|
||||
$lastModifiedString = (($response->getHeaders()['last-modified'] ?? [])[0] ?? '');
|
||||
|
||||
$date = DateTimeImmutable::createFromFormat(
|
||||
DateTimeImmutable::RFC7231,
|
||||
$date = \DateTimeImmutable::createFromFormat(
|
||||
\DateTimeImmutable::RFC7231,
|
||||
$lastModifiedString,
|
||||
new DateTimeZone('GMT')
|
||||
new \DateTimeZone('GMT')
|
||||
);
|
||||
|
||||
if (false === $date) {
|
||||
throw new RuntimeException('the date from remote storage could not be parsed: '
|
||||
. $lastModifiedString);
|
||||
throw new \RuntimeException('the date from remote storage could not be parsed: '.$lastModifiedString);
|
||||
}
|
||||
|
||||
return $date;
|
||||
@@ -168,11 +159,11 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
)
|
||||
->url
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
throw StoredObjectManagerException::errorDuringHttpRequest($e);
|
||||
}
|
||||
|
||||
if ($response->getStatusCode() !== Response::HTTP_OK) {
|
||||
if (Response::HTTP_OK !== $response->getStatusCode()) {
|
||||
throw StoredObjectManagerException::invalidStatusCode($response->getStatusCode());
|
||||
}
|
||||
|
||||
@@ -190,7 +181,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
|
||||
|
||||
private function hasCache(StoredObject $document): bool
|
||||
{
|
||||
return array_key_exists($document->getUuid()->toString(), $this->inMemory);
|
||||
return \array_key_exists($document->getUuid()->toString(), $this->inMemory);
|
||||
}
|
||||
|
||||
private function hasKeysAndIv(StoredObject $storedObject): bool
|
||||
|
@@ -12,26 +12,25 @@ declare(strict_types=1);
|
||||
namespace Chill\DocStoreBundle\Service;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use DateTimeInterface;
|
||||
|
||||
interface StoredObjectManagerInterface
|
||||
{
|
||||
public function getLastModified(StoredObject $document): DateTimeInterface;
|
||||
public function getLastModified(StoredObject $document): \DateTimeInterface;
|
||||
|
||||
/**
|
||||
* Get the content of a StoredObject.
|
||||
*
|
||||
* @param StoredObject $document The document.
|
||||
* @param StoredObject $document the document
|
||||
*
|
||||
* @return string The retrieved content in clear.
|
||||
* @return string the retrieved content in clear
|
||||
*/
|
||||
public function read(StoredObject $document): string;
|
||||
|
||||
/**
|
||||
* Set the content of a StoredObject.
|
||||
*
|
||||
* @param StoredObject $document The document.
|
||||
* @param $clearContent The content to store in clear.
|
||||
* @param StoredObject $document the document
|
||||
* @param $clearContent The content to store in clear
|
||||
*/
|
||||
public function write(StoredObject $document, string $clearContent): void;
|
||||
}
|
||||
|
Reference in New Issue
Block a user