php-cs-fixer

This commit is contained in:
Greyscale 2024-06-10 06:31:06 +02:00
parent 7a3b093cf7
commit c128b4bcce
No known key found for this signature in database
GPG key ID: 74BAFF55434DA4B2
8 changed files with 58 additions and 52 deletions

View file

@ -1,4 +1,7 @@
<?php <?php
use PhpCsFixer\Runner\Parallel\ParallelConfig;
$finder = PhpCsFixer\Finder::create(); $finder = PhpCsFixer\Finder::create();
if (!defined('__PHPCS_ROOT__')) { if (!defined('__PHPCS_ROOT__')) {

View file

@ -4,12 +4,11 @@ declare(strict_types=1);
namespace Benzine\Actions; namespace Benzine\Actions;
use App\Domain\DomainException\DomainRecordNotFoundException;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException; use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException; use Slim\Views\Twig;
abstract class Action abstract class Action
{ {
@ -19,8 +18,10 @@ abstract class Action
protected array $args; protected array $args;
public function __construct(protected LoggerInterface $logger) public function __construct(
{ protected LoggerInterface $logger,
protected Twig $twig,
) {
$this->response = new \Slim\Psr7\Response(); $this->response = new \Slim\Psr7\Response();
} }
@ -33,7 +34,6 @@ abstract class Action
} }
/** /**
* @return mixed
* @throws HttpBadRequestException * @throws HttpBadRequestException
*/ */
protected function resolveArg(string $name) protected function resolveArg(string $name)
@ -46,7 +46,7 @@ abstract class Action
} }
/** /**
* @param array|object|null $data * @param null|array|object $data
*/ */
protected function respondWithData($data = null, int $statusCode = 200): Response protected function respondWithData($data = null, int $statusCode = 200): Response
{ {
@ -62,13 +62,24 @@ abstract class Action
return $this->response return $this->response
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->withStatus($payload->getStatusCode()); ->withStatus($payload->getStatusCode())
;
} }
protected function redirect(string $redirectUrl): Response protected function redirect(string $redirectUrl): Response
{ {
return $this->response return $this->response
->withHeader('Location', $redirectUrl) ->withHeader('Location', $redirectUrl)
->withStatus(302); ->withStatus(302)
;
}
protected function render($response, string $template, array $data = []): Response
{
return $this->twig->render(
$response,
$template,
$data
)->withHeader('Content-Type', 'text/html');
} }
} }

View file

@ -4,9 +4,7 @@ declare(strict_types=1);
namespace Benzine\Actions; namespace Benzine\Actions;
use JsonSerializable; class ActionError implements \JsonSerializable
class ActionError implements JsonSerializable
{ {
public const BAD_REQUEST = 'BAD_REQUEST'; public const BAD_REQUEST = 'BAD_REQUEST';
public const INSUFFICIENT_PRIVILEGES = 'INSUFFICIENT_PRIVILEGES'; public const INSUFFICIENT_PRIVILEGES = 'INSUFFICIENT_PRIVILEGES';
@ -36,6 +34,7 @@ class ActionError implements JsonSerializable
public function setType(string $type): self public function setType(string $type): self
{ {
$this->type = $type; $this->type = $type;
return $this; return $this;
} }
@ -47,6 +46,7 @@ class ActionError implements JsonSerializable
public function setDescription(?string $description = null): self public function setDescription(?string $description = null): self
{ {
$this->description = $description; $this->description = $description;
return $this; return $this;
} }

View file

@ -4,14 +4,12 @@ declare(strict_types=1);
namespace Benzine\Actions; namespace Benzine\Actions;
use JsonSerializable; class ActionPayload implements \JsonSerializable
class ActionPayload implements JsonSerializable
{ {
private int $statusCode; private int $statusCode;
/** /**
* @var array|object|null * @var null|array|object
*/ */
private $data; private $data;
@ -33,7 +31,7 @@ class ActionPayload implements JsonSerializable
} }
/** /**
* @return array|null|object * @return null|array|object
*/ */
public function getData() public function getData()
{ {

View file

@ -74,7 +74,7 @@ class App
protected bool $isSessionsEnabled = true; protected bool $isSessionsEnabled = true;
protected bool $interrogateControllersComplete = false; protected bool $interrogateControllersComplete = false;
protected ?CachePoolChain $cachePoolChain = null; protected ?CachePoolChain $cachePoolChain = null;
private array $viewPaths = []; private array $viewPaths = [APP_ROOT . '/views'];
private string $cachePath = APP_ROOT . '/cache'; private string $cachePath = APP_ROOT . '/cache';
private string $logPath = APP_ROOT . '/logs'; private string $logPath = APP_ROOT . '/logs';
private array $supportedLanguages = ['en_US']; private array $supportedLanguages = ['en_US'];
@ -378,9 +378,7 @@ class App
return $monolog; return $monolog;
}); });
$container->set(LoggerInterface::class, function (Logger $logger) { $container->set(LoggerInterface::class, fn (Logger $logger) => $logger);
return $logger;
});
$container->set(Redis::class, function (ConfigurationService $configurationService, Logger $logger, EnvironmentService $environmentService) { $container->set(Redis::class, function (ConfigurationService $configurationService, Logger $logger, EnvironmentService $environmentService) {
return new Redis( return new Redis(
@ -638,12 +636,14 @@ class App
} }
protected static Timer $timer; protected static Timer $timer;
static public function Timing(){
public static function Timing(): void
{
$duration = self::$timer->stop(); $duration = self::$timer->stop();
# Get caller // Get caller
$caller = debug_backtrace()[0]; $caller = debug_backtrace()[0];
if ($duration->asSeconds() >= 1) { if ($duration->asSeconds() >= 1) {
$timingMessage = sprintf("%f seconds: (%s:%d)", $duration->asSeconds(), $caller['file'], $caller['line']); $timingMessage = sprintf('%f seconds: (%s:%d)', $duration->asSeconds(), $caller['file'], $caller['line']);
\Kint::dump($timingMessage); \Kint::dump($timingMessage);
} }

View file

@ -10,8 +10,6 @@ use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
use Monolog\Logger; use Monolog\Logger;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use PushToLive\Kernel;
use SebastianBergmann\Timer\Timer;
use Slim\App; use Slim\App;
class Router class Router
@ -53,7 +51,6 @@ class Router
'Benzine\\Controllers\\' . $fileClassName, 'Benzine\\Controllers\\' . $fileClassName,
]; ];
foreach ($expectedClasses as $expectedClass) { foreach ($expectedClasses as $expectedClass) {
if (!class_exists($expectedClass)) { if (!class_exists($expectedClass)) {
$this->logger->warning('While loading routes from annotations in {file}, expected class {expectedClass} does not exist.', [ $this->logger->warning('While loading routes from annotations in {file}, expected class {expectedClass} does not exist.', [

View file

@ -6,7 +6,6 @@ namespace Benzine\Services;
use Benzine\App; use Benzine\App;
use Benzine\Exceptions\BenzineConfigurationException; use Benzine\Exceptions\BenzineConfigurationException;
use SebastianBergmann\Timer\Timer;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;

View file

@ -25,7 +25,6 @@ class EnvironmentService
} }
ksort($this->environmentVariables); ksort($this->environmentVariables);
} }
public function has(string $key): bool public function has(string $key): bool
@ -82,5 +81,4 @@ class EnvironmentService
{ {
return $this->getPublicHostname() . $this->getPublicPath(); return $this->getPublicHostname() . $this->getPublicPath();
} }
} }