Skip to content

Commit

Permalink
Merge pull request #241 from eliashaeussler/task/php-cs-fixer-config
Browse files Browse the repository at this point in the history
[TASK] Use eliashaeussler/php-cs-fixer-config
  • Loading branch information
eliashaeussler committed Jun 6, 2024
2 parents c58997a + b84937d commit eb3c611
Show file tree
Hide file tree
Showing 115 changed files with 4,194 additions and 4,341 deletions.
25 changes: 9 additions & 16 deletions Classes/Authentication/StreamAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -27,14 +27,7 @@
use Symfony\Component\Filesystem;
use TYPO3\CMS\Core;

use function array_search;
use function array_unshift;
use function file;
use function file_exists;
use function file_put_contents;
use function implode;
use function sha1;
use function uniqid;

/**
* StreamAuthentication
Expand All @@ -58,15 +51,15 @@ public function __construct()
*/
public function authenticate(string $hash): void
{
$registeredHashes = @file($this->storagePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$registeredHashes = @\file($this->storagePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

// Throw exception if file cannot be read
if ($registeredHashes === false) {
throw Exception\AuthenticationFailureException::create();
}

// Throw exception if hash is not registered
if (($line = array_search($hash, $registeredHashes, true)) === false) {
if (($line = \array_search($hash, $registeredHashes, true)) === false) {
throw Exception\AuthenticationFailureException::create();
}

Expand All @@ -78,7 +71,7 @@ public function authenticate(string $hash): void

public function register(): string
{
$hash = sha1(uniqid('tx_solver_stream_hash_'));
$hash = \sha1(\uniqid('tx_solver_stream_hash_'));

$this->write([$hash], true);

Expand All @@ -92,7 +85,7 @@ private function initializeStorage(): void
'transient/tx_solver/stream_auth.txt',
);

if (!file_exists($this->storagePath)) {
if (!\file_exists($this->storagePath)) {
Core\Utility\GeneralUtility::mkdir_deep(dirname($this->storagePath));
$this->write([]);
}
Expand All @@ -104,11 +97,11 @@ private function initializeStorage(): void
private function write(array $hashes, bool $append = false): void
{
if ($append) {
array_unshift($hashes, '');
\array_unshift($hashes, '');
}

$content = implode(PHP_EOL, $hashes);
$content = \implode(PHP_EOL, $hashes);

file_put_contents($this->storagePath, $content, $append ? FILE_APPEND : LOCK_EX);
\file_put_contents($this->storagePath, $content, $append ? FILE_APPEND : LOCK_EX);
}
}
17 changes: 8 additions & 9 deletions Classes/Cache/ExceptionsCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -24,7 +24,6 @@
namespace EliasHaeussler\Typo3Solver\Cache;

use Symfony\Component\Filesystem;
use Throwable;
use TYPO3\CMS\Core;

/**
Expand All @@ -49,7 +48,7 @@ public function __construct()
$this->initializeCache();
}

public function get(string $entryIdentifier): ?Throwable
public function get(string $entryIdentifier): ?\Throwable
{
/** @var array{exceptions: array<string, ExceptionArray>} $cacheData */
$cacheData = require $this->cachePath;
Expand All @@ -61,12 +60,12 @@ public function get(string $entryIdentifier): ?Throwable
return $this->serializer->deserialize($cacheData['exceptions'][$entryIdentifier]);
}

public function getIdentifier(Throwable $exception): string
public function getIdentifier(\Throwable $exception): string
{
return $this->calculateCacheIdentifier($exception);
}

public function set(Throwable $exception): string
public function set(\Throwable $exception): string
{
$cacheData = require $this->cachePath;
$entryIdentifier = $this->calculateCacheIdentifier($exception);
Expand All @@ -85,11 +84,11 @@ public function flush(): void
/**
* @internal
*/
public function remove(Throwable|string $entry): void
public function remove(\Throwable|string $entry): void
{
$cacheData = require $this->cachePath;

if ($entry instanceof Throwable) {
if ($entry instanceof \Throwable) {
$entry = $this->calculateCacheIdentifier($entry);
}

Expand All @@ -98,7 +97,7 @@ public function remove(Throwable|string $entry): void
$this->write($cacheData);
}

private function calculateCacheIdentifier(Throwable $exception): string
private function calculateCacheIdentifier(\Throwable $exception): string
{
return sha1(
implode('-', [
Expand Down
11 changes: 5 additions & 6 deletions Classes/Cache/Serializer/ExceptionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -23,7 +23,6 @@

namespace EliasHaeussler\Typo3Solver\Cache\Serializer;

use ReflectionClass;
use Throwable;

/**
Expand Down Expand Up @@ -51,7 +50,7 @@ final class ExceptionSerializer
* @phpstan-param T $exception
* @phpstan-return ExceptionArray
*/
public function serialize(Throwable $exception): array
public function serialize(\Throwable $exception): array
{
return [
'className' => $exception::class,
Expand All @@ -67,13 +66,13 @@ public function serialize(Throwable $exception): array
/**
* @phpstan-param ExceptionArray $exceptionArray
*/
public function deserialize(array $exceptionArray): Throwable
public function deserialize(array $exceptionArray): \Throwable
{
$className = $exceptionArray['className'];
$properties = $exceptionArray['exception'];

// Create exception class
$reflectionClass = new ReflectionClass($className);
$reflectionClass = new \ReflectionClass($className);
$exception = $reflectionClass->newInstanceWithoutConstructor();

// Restore exception properties
Expand Down
7 changes: 3 additions & 4 deletions Classes/Cache/Serializer/SolutionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -23,7 +23,6 @@

namespace EliasHaeussler\Typo3Solver\Cache\Serializer;

use DateTimeImmutable;
use EliasHaeussler\Typo3Solver\Configuration;
use EliasHaeussler\Typo3Solver\ProblemSolving;

Expand Down Expand Up @@ -81,7 +80,7 @@ public function deserialize(array $solutionArray): ?ProblemSolving\Solution\Solu
}

return ProblemSolving\Solution\Solution::fromArray($solution)
->setCreateDate(new DateTimeImmutable('@' . $createdAt))
->setCreateDate(new \DateTimeImmutable('@' . $createdAt))
;
}
}
18 changes: 6 additions & 12 deletions Classes/Cache/SolutionsCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -28,12 +28,6 @@
use Symfony\Component\Filesystem;
use TYPO3\CMS\Core;

use function dirname;
use function implode;
use function is_array;
use function sprintf;
use function var_export;

/**
* SolutionsCache.
*
Expand Down Expand Up @@ -69,7 +63,7 @@ public function get(ProblemSolving\Problem\Problem $problem): ?ProblemSolving\So
$cacheData = require $this->cachePath;
$entryIdentifier = $this->calculateCacheIdentifier($problem);

if (!is_array($cacheData['solutions'][$entryIdentifier] ?? null)) {
if (!\is_array($cacheData['solutions'][$entryIdentifier] ?? null)) {
return null;
}

Expand Down Expand Up @@ -123,7 +117,7 @@ public function remove(ProblemSolving\Problem\Problem|string $entry): void
private function calculateCacheIdentifier(ProblemSolving\Problem\Problem $problem): string
{
return sha1(
implode('-', [
\implode('-', [
$problem->getSolutionProvider()::class,
$this->configuration->getModel(),
$this->configuration->getTemperature(),
Expand All @@ -142,7 +136,7 @@ private function initializeCache(): void
);

if (!$this->filesystem->exists($this->cachePath)) {
Core\Utility\GeneralUtility::mkdir_deep(dirname($this->cachePath));
Core\Utility\GeneralUtility::mkdir_deep(\dirname($this->cachePath));
$this->write([]);
}
}
Expand All @@ -154,7 +148,7 @@ private function write(array $cacheData): void
{
$this->filesystem->dumpFile(
$this->cachePath,
sprintf('<?php return %s;', var_export($cacheData, true)),
\sprintf('<?php return %s;', \var_export($cacheData, true)),
);
}
}
8 changes: 3 additions & 5 deletions Classes/Command/CacheFlushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of the TYPO3 CMS extension "solver".
*
* Copyright (C) 2024 Elias H盲u脽ler <elias@haeussler.dev>
* Copyright (C) 2023-2024 Elias H盲u脽ler <elias@haeussler.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -14,7 +14,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
Expand All @@ -26,8 +26,6 @@
use EliasHaeussler\Typo3Solver\Cache;
use Symfony\Component\Console;

use function sprintf;

/**
* CacheFlushCommand
*
Expand Down Expand Up @@ -61,7 +59,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
// Remove single cache entry
$this->cache->remove($identifier);
$io->success(
sprintf('Cache entry with identifier "%s" successfully removed.', $identifier),
\sprintf('Cache entry with identifier "%s" successfully removed.', $identifier),
);
} else {
// Flush all caches
Expand Down
Loading

0 comments on commit eb3c611

Please sign in to comment.