From c128b4bcce916d9ca424ee8c86ea72eb12fd2ccf Mon Sep 17 00:00:00 2001
From: Matthew Baggett <matthew@baggett.me>
Date: Mon, 10 Jun 2024 06:31:06 +0200
Subject: [PATCH] php-cs-fixer

---
 .php-cs-fixer.php                     |  3 +++
 src/Actions/Action.php                | 29 ++++++++++++++++++---------
 src/Actions/ActionError.php           | 26 ++++++++++++------------
 src/Actions/ActionPayload.php         | 14 ++++++-------
 src/App.php                           | 16 +++++++--------
 src/Router/Router.php                 |  9 +++------
 src/Services/ConfigurationService.php |  1 -
 src/Services/EnvironmentService.php   | 12 +++++------
 8 files changed, 58 insertions(+), 52 deletions(-)

diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
index 960d804..b8d86ee 100644
--- a/.php-cs-fixer.php
+++ b/.php-cs-fixer.php
@@ -1,4 +1,7 @@
 <?php
+
+use PhpCsFixer\Runner\Parallel\ParallelConfig;
+
 $finder = PhpCsFixer\Finder::create();
 
 if (!defined('__PHPCS_ROOT__')) {
diff --git a/src/Actions/Action.php b/src/Actions/Action.php
index 826b31c..f043fce 100644
--- a/src/Actions/Action.php
+++ b/src/Actions/Action.php
@@ -4,12 +4,11 @@ declare(strict_types=1);
 
 namespace Benzine\Actions;
 
-use App\Domain\DomainException\DomainRecordNotFoundException;
 use Psr\Http\Message\ResponseInterface as Response;
 use Psr\Http\Message\ServerRequestInterface as Request;
 use Psr\Log\LoggerInterface;
 use Slim\Exception\HttpBadRequestException;
-use Slim\Exception\HttpNotFoundException;
+use Slim\Views\Twig;
 
 abstract class Action
 {
@@ -19,8 +18,10 @@ abstract class Action
 
     protected array $args;
 
-    public function __construct(protected LoggerInterface $logger)
-    {
+    public function __construct(
+        protected LoggerInterface $logger,
+        protected Twig $twig,
+    ) {
         $this->response = new \Slim\Psr7\Response();
     }
 
@@ -33,7 +34,6 @@ abstract class Action
     }
 
     /**
-     * @return mixed
      * @throws HttpBadRequestException
      */
     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
     {
@@ -62,13 +62,24 @@ abstract class Action
 
         return $this->response
             ->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
             ->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');
     }
 }
diff --git a/src/Actions/ActionError.php b/src/Actions/ActionError.php
index 72dac2c..4023374 100644
--- a/src/Actions/ActionError.php
+++ b/src/Actions/ActionError.php
@@ -4,19 +4,17 @@ declare(strict_types=1);
 
 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 NOT_ALLOWED = 'NOT_ALLOWED';
-    public const NOT_IMPLEMENTED = 'NOT_IMPLEMENTED';
-    public const RESOURCE_NOT_FOUND = 'RESOURCE_NOT_FOUND';
-    public const SERVER_ERROR = 'SERVER_ERROR';
-    public const UNAUTHENTICATED = 'UNAUTHENTICATED';
-    public const VALIDATION_ERROR = 'VALIDATION_ERROR';
-    public const VERIFICATION_ERROR = 'VERIFICATION_ERROR';
+    public const NOT_ALLOWED             = 'NOT_ALLOWED';
+    public const NOT_IMPLEMENTED         = 'NOT_IMPLEMENTED';
+    public const RESOURCE_NOT_FOUND      = 'RESOURCE_NOT_FOUND';
+    public const SERVER_ERROR            = 'SERVER_ERROR';
+    public const UNAUTHENTICATED         = 'UNAUTHENTICATED';
+    public const VALIDATION_ERROR        = 'VALIDATION_ERROR';
+    public const VERIFICATION_ERROR      = 'VERIFICATION_ERROR';
 
     private string $type;
 
@@ -24,7 +22,7 @@ class ActionError implements JsonSerializable
 
     public function __construct(string $type, ?string $description = null)
     {
-        $this->type = $type;
+        $this->type        = $type;
         $this->description = $description;
     }
 
@@ -36,6 +34,7 @@ class ActionError implements JsonSerializable
     public function setType(string $type): self
     {
         $this->type = $type;
+
         return $this;
     }
 
@@ -47,6 +46,7 @@ class ActionError implements JsonSerializable
     public function setDescription(?string $description = null): self
     {
         $this->description = $description;
+
         return $this;
     }
 
@@ -54,7 +54,7 @@ class ActionError implements JsonSerializable
     public function jsonSerialize(): array
     {
         return [
-            'type' => $this->type,
+            'type'        => $this->type,
             'description' => $this->description,
         ];
     }
diff --git a/src/Actions/ActionPayload.php b/src/Actions/ActionPayload.php
index de60bb3..ce2a19e 100644
--- a/src/Actions/ActionPayload.php
+++ b/src/Actions/ActionPayload.php
@@ -4,14 +4,12 @@ declare(strict_types=1);
 
 namespace Benzine\Actions;
 
-use JsonSerializable;
-
-class ActionPayload implements JsonSerializable
+class ActionPayload implements \JsonSerializable
 {
     private int $statusCode;
 
     /**
-     * @var array|object|null
+     * @var null|array|object
      */
     private $data;
 
@@ -19,12 +17,12 @@ class ActionPayload implements JsonSerializable
 
     public function __construct(
         int $statusCode = 200,
-            $data = null,
+        $data = null,
         ?ActionError $error = null
     ) {
         $this->statusCode = $statusCode;
-        $this->data = $data;
-        $this->error = $error;
+        $this->data       = $data;
+        $this->error      = $error;
     }
 
     public function getStatusCode(): int
@@ -33,7 +31,7 @@ class ActionPayload implements JsonSerializable
     }
 
     /**
-     * @return array|null|object
+     * @return null|array|object
      */
     public function getData()
     {
diff --git a/src/App.php b/src/App.php
index 61ca4a1..00e5656 100644
--- a/src/App.php
+++ b/src/App.php
@@ -74,7 +74,7 @@ class App
     protected bool $isSessionsEnabled              = true;
     protected bool $interrogateControllersComplete = false;
     protected ?CachePoolChain $cachePoolChain      = null;
-    private array $viewPaths                       = [];
+    private array $viewPaths                       = [APP_ROOT . '/views'];
     private string $cachePath                      = APP_ROOT . '/cache';
     private string $logPath                        = APP_ROOT . '/logs';
     private array $supportedLanguages              = ['en_US'];
@@ -378,9 +378,7 @@ class App
             return $monolog;
         });
 
-        $container->set(LoggerInterface::class, function (Logger $logger) {
-            return $logger;
-        });
+        $container->set(LoggerInterface::class, fn (Logger $logger) => $logger);
 
         $container->set(Redis::class, function (ConfigurationService $configurationService, Logger $logger, EnvironmentService $environmentService) {
             return new Redis(
@@ -638,12 +636,14 @@ class App
     }
 
     protected static Timer $timer;
-    static public function Timing(){
+
+    public static function Timing(): void
+    {
         $duration = self::$timer->stop();
-        # Get caller
+        // Get caller
         $caller = debug_backtrace()[0];
-        if($duration->asSeconds() >= 1) {
-            $timingMessage = sprintf("%f seconds: (%s:%d)", $duration->asSeconds(), $caller['file'], $caller['line']);
+        if ($duration->asSeconds() >= 1) {
+            $timingMessage = sprintf('%f seconds: (%s:%d)', $duration->asSeconds(), $caller['file'], $caller['line']);
             \Kint::dump($timingMessage);
         }
 
diff --git a/src/Router/Router.php b/src/Router/Router.php
index 80bd72a..69d7ce7 100644
--- a/src/Router/Router.php
+++ b/src/Router/Router.php
@@ -10,8 +10,6 @@ use Doctrine\Common\Annotations\AnnotationReader;
 use Doctrine\Common\Annotations\AnnotationRegistry;
 use Monolog\Logger;
 use Psr\Http\Message\ServerRequestInterface;
-use PushToLive\Kernel;
-use SebastianBergmann\Timer\Timer;
 use Slim\App;
 
 class Router
@@ -53,7 +51,6 @@ class Router
                     'Benzine\\Controllers\\' . $fileClassName,
                 ];
 
-
                 foreach ($expectedClasses as $expectedClass) {
                     if (!class_exists($expectedClass)) {
                         $this->logger->warning('While loading routes from annotations in {file}, expected class {expectedClass} does not exist.', [
@@ -81,15 +78,15 @@ class Router
                         }
 
                         $routeAttibutes = $method->getAttributes(\Benzine\Annotations\Route::class);
-                        foreach($routeAttibutes as $routeAttibute){
-                            foreach($routeAttibute->getArguments()['methods'] as $httpMethod){
+                        foreach ($routeAttibutes as $routeAttibute) {
+                            foreach ($routeAttibute->getArguments()['methods'] as $httpMethod) {
                                 $newRoute = (new Route())
                                     ->setHttpMethod($httpMethod)
                                     ->setRouterPattern('/' . ltrim($routeAttibute->getArguments()['path'], '/'))
                                     ->setCallback($expectedClass . ':' . $method->name)
                                     ->setWeight($routeAttibute->getArguments()['weight'] ?? 100)
                                 ;
-                                if(isset($routeAttibute->getArguments()['domains']) && is_array($routeAttibute->getArguments()['domains'])){
+                                if (isset($routeAttibute->getArguments()['domains']) && is_array($routeAttibute->getArguments()['domains'])) {
                                     foreach ($routeAttibute->getArguments()['domains'] as $domain) {
                                         $newRoute->addValidDomain($domain);
                                     }
diff --git a/src/Services/ConfigurationService.php b/src/Services/ConfigurationService.php
index 63cdebd..6f03113 100644
--- a/src/Services/ConfigurationService.php
+++ b/src/Services/ConfigurationService.php
@@ -6,7 +6,6 @@ namespace Benzine\Services;
 
 use Benzine\App;
 use Benzine\Exceptions\BenzineConfigurationException;
-use SebastianBergmann\Timer\Timer;
 use Symfony\Component\Filesystem\Filesystem;
 use Symfony\Component\Yaml\Yaml;
 
diff --git a/src/Services/EnvironmentService.php b/src/Services/EnvironmentService.php
index f045e36..a9744ff 100644
--- a/src/Services/EnvironmentService.php
+++ b/src/Services/EnvironmentService.php
@@ -11,21 +11,20 @@ class EnvironmentService
     public function __construct()
     {
         $this->environmentVariables = array_merge($_SERVER, $_ENV);
-        if(file_exists(APP_ROOT . '/.env')){
-            $env = file_get_contents(APP_ROOT . '/.env');
+        if (file_exists(APP_ROOT . '/.env')) {
+            $env   = file_get_contents(APP_ROOT . '/.env');
             $lines = explode("\n", $env);
-            foreach($lines as $line){
+            foreach ($lines as $line) {
                 $line = trim($line);
-                if($line == ''){
+                if ($line == '') {
                     continue;
                 }
-                $parts = explode('=', $line);
+                $parts                                 = explode('=', $line);
                 $this->environmentVariables[$parts[0]] = $parts[1];
             }
         }
 
         ksort($this->environmentVariables);
-
     }
 
     public function has(string $key): bool
@@ -82,5 +81,4 @@ class EnvironmentService
     {
         return $this->getPublicHostname() . $this->getPublicPath();
     }
-
 }