php-cs-fixer doing its thing.

This commit is contained in:
Greyscale 2021-01-22 05:20:21 +01:00
parent 229c98a91a
commit 74338e78a0
11 changed files with 36 additions and 18 deletions

View file

@ -4,12 +4,13 @@ function detectAndLoadVendor($path = __DIR__): void
{ {
$path = realpath($path); $path = realpath($path);
if ('/' == $path) { if ('/' == $path) {
die("Could not find a suitable /vendor directory! Maybe you need to run composer install!\n"); exit("Could not find a suitable /vendor directory! Maybe you need to run composer install!\n");
} }
foreach (new DirectoryIterator($path) as $fileInfo) { foreach (new DirectoryIterator($path) as $fileInfo) {
if ($fileInfo->isDir() && 'vendor' == $fileInfo->getFilename()) { if ($fileInfo->isDir() && 'vendor' == $fileInfo->getFilename()) {
define('VENDOR_PATH', $fileInfo->getRealPath()); define('VENDOR_PATH', $fileInfo->getRealPath());
require_once VENDOR_PATH.'/autoload.php'; require_once VENDOR_PATH.'/autoload.php';
return; return;

View file

@ -59,14 +59,14 @@ class App
protected Router $router; protected Router $router;
protected bool $isSessionsEnabled = true; protected bool $isSessionsEnabled = true;
protected bool $interrogateControllersComplete = false; protected bool $interrogateControllersComplete = false;
protected ?CachePoolChain $cachePoolChain = null;
private array $viewPaths = []; private array $viewPaths = [];
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'];
private bool $debugMode = false; private bool $debugMode = false;
private static bool $isInitialised = false; private static bool $isInitialised = false;
protected ?CachePoolChain $cachePoolChain = null;
public function __construct() public function __construct()
{ {
@ -134,11 +134,13 @@ class App
/** /**
* @param array $viewPaths * @param array $viewPaths
*
* @return App * @return App
*/ */
public function setViewPaths(array $viewPaths): App public function setViewPaths(array $viewPaths): App
{ {
$this->viewPaths = $viewPaths; $this->viewPaths = $viewPaths;
return $this; return $this;
} }
@ -152,11 +154,13 @@ class App
/** /**
* @param string $logPath * @param string $logPath
*
* @return App * @return App
*/ */
public function setLogPath(string $logPath): App public function setLogPath(string $logPath): App
{ {
$this->logPath = $logPath; $this->logPath = $logPath;
return $this; return $this;
} }
@ -319,8 +323,8 @@ class App
$caches[] = new ArrayCachePool(); $caches[] = new ArrayCachePool();
$this->cachePoolChain = new CachePoolChain($caches); $this->cachePoolChain = new CachePoolChain($caches);
} }
return $this->cachePoolChain; return $this->cachePoolChain;
}); });
@ -334,9 +338,9 @@ class App
$container->set(Logger::class, function (ConfigurationService $configurationService, EnvironmentService $environmentService) { $container->set(Logger::class, function (ConfigurationService $configurationService, EnvironmentService $environmentService) {
$appName = $configurationService->get(ConfigurationService::KEY_APP_NAME); $appName = $configurationService->get(ConfigurationService::KEY_APP_NAME);
$logName = $environmentService->has("REQUEST_URI") ? sprintf("%s(%s)", $appName, $environmentService->get("REQUEST_URI")) : $appName; $logName = $environmentService->has('REQUEST_URI') ? sprintf('%s(%s)', $appName, $environmentService->get('REQUEST_URI')) : $appName;
$monolog = new Logger($logName); $monolog = new Logger($logName);
$monolog->pushHandler(new StreamHandler(sprintf("%s/%s.log", $this->getLogPath(), strtolower($appName)))); $monolog->pushHandler(new StreamHandler(sprintf('%s/%s.log', $this->getLogPath(), strtolower($appName))));
$monolog->pushHandler(new ErrorLogHandler(), Logger::DEBUG); $monolog->pushHandler(new ErrorLogHandler(), Logger::DEBUG);
$monolog->pushProcessor(new PsrLogMessageProcessor()); $monolog->pushProcessor(new PsrLogMessageProcessor());
@ -393,7 +397,7 @@ class App
$this->router = $container->get(Router::class); $this->router = $container->get(Router::class);
#!\Kint::dump($this->environmentService->all());exit; //!\Kint::dump($this->environmentService->all());exit;
return $container; return $container;
} }
@ -539,7 +543,7 @@ class App
$timeToBootstrapMs = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000; $timeToBootstrapMs = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000;
$bootstrapTooLongThresholdMs = 300; $bootstrapTooLongThresholdMs = 300;
if($timeToBootstrapMs >= $bootstrapTooLongThresholdMs) { if ($timeToBootstrapMs >= $bootstrapTooLongThresholdMs) {
$this->logger->warning(sprintf('Bootstrap complete in %sms which is more than the threshold of %sms', number_format($timeToBootstrapMs, 2), $bootstrapTooLongThresholdMs)); $this->logger->warning(sprintf('Bootstrap complete in %sms which is more than the threshold of %sms', number_format($timeToBootstrapMs, 2), $bootstrapTooLongThresholdMs));
} }

View file

@ -23,7 +23,7 @@ abstract class AbstractController
public function __construct(Logger $logger, CacheProvider $cacheProvider) public function __construct(Logger $logger, CacheProvider $cacheProvider)
{ {
$this->logger = $logger; $this->logger = $logger;
#$this->logger->debug(sprintf('Entered Controller in %sms', number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2))); //$this->logger->debug(sprintf('Entered Controller in %sms', number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2)));
$this->cacheProvider = $cacheProvider; $this->cacheProvider = $cacheProvider;
} }

View file

@ -54,7 +54,7 @@ abstract class AbstractHTMLController extends AbstractController
$renderTimeLimitMs = 500; $renderTimeLimitMs = 500;
$renderTimeMs = (microtime(true) - $renderStart) * 1000; $renderTimeMs = (microtime(true) - $renderStart) * 1000;
if($renderTimeMs >= $renderTimeLimitMs) { if ($renderTimeMs >= $renderTimeLimitMs) {
$this->logger->debug(sprintf( $this->logger->debug(sprintf(
'Took %sms to render %s, which is over %sms limit', 'Took %sms to render %s, which is over %sms limit',
number_format($renderTimeMs, 2), number_format($renderTimeMs, 2),

View file

@ -46,18 +46,22 @@ class Filter
$this->setLimit($value); $this->setLimit($value);
break; break;
case 'offset': case 'offset':
$this->setOffset($value); $this->setOffset($value);
break; break;
case 'wheres': case 'wheres':
$this->setWheres($value); $this->setWheres($value);
break; break;
case 'order': case 'order':
$this->parseOrder($value); $this->parseOrder($value);
break; break;
default: default:
throw new FilterDecodeException("Failed to decode Filter, unknown key: {$key}"); throw new FilterDecodeException("Failed to decode Filter, unknown key: {$key}");
} }

View file

@ -2,7 +2,6 @@
namespace Benzine\Router; namespace Benzine\Router;
use Monolog\Logger;
use Slim\App; use Slim\App;
class Route class Route

View file

@ -142,7 +142,7 @@ class Router
$this->routes = $cacheItem->get(); $this->routes = $cacheItem->get();
$timeToLoadFromCacheMs = (microtime(true) - $time) * 1000; $timeToLoadFromCacheMs = (microtime(true) - $time) * 1000;
if($timeToLoadFromCacheMs >= 500) { if ($timeToLoadFromCacheMs >= 500) {
$this->logger->warning(sprintf('Loaded routes from Cache in %sms, which is slower than 500ms', number_format($timeToLoadFromCacheMs, 2))); $this->logger->warning(sprintf('Loaded routes from Cache in %sms, which is slower than 500ms', number_format($timeToLoadFromCacheMs, 2)));
} }
@ -159,9 +159,9 @@ class Router
try { try {
$this->cachePoolChain->save($routeItem); $this->cachePoolChain->save($routeItem);
$this->logger->info("Cached router to cache pool"); $this->logger->info('Cached router to cache pool');
} catch (CachePoolException $cachePoolException) { } catch (CachePoolException $cachePoolException) {
$this->logger->critical("Cache Pool Exception: " . $cachePoolException->getMessage()); $this->logger->critical('Cache Pool Exception: '.$cachePoolException->getMessage());
} }
return $this; return $this;

View file

@ -55,18 +55,23 @@ class TransformExtension extends AbstractExtension
case 'camel': case 'camel':
case 'camelcase': case 'camelcase':
return new Format\CamelCase(); return new Format\CamelCase();
case 'screaming': case 'screaming':
case 'screamingsnake': case 'screamingsnake':
case 'screamingsnakecase': case 'screamingsnakecase':
return new Format\ScreamingSnakeCase(); return new Format\ScreamingSnakeCase();
case 'snake': case 'snake':
case 'snakecase': case 'snakecase':
return new Format\SnakeCase(); return new Format\SnakeCase();
case 'spinal': case 'spinal':
case 'spinalcase': case 'spinalcase':
return new Format\SpinalCase(); return new Format\SpinalCase();
case 'studly': case 'studly':
return new Format\StudlyCaps(); return new Format\StudlyCaps();
default: default:
throw new TransformExtensionException("Unknown transformer: \"{$name}\"."); throw new TransformExtensionException("Unknown transformer: \"{$name}\".");
} }

View file

@ -108,6 +108,7 @@ abstract class AbstractQueueWorker extends AbstractWorker
if ($this->stopOnZero && 0 == $queueLength) { if ($this->stopOnZero && 0 == $queueLength) {
$this->logger->warning('--stop-on-zero is set, and the queue length is zero! Stopping!'); $this->logger->warning('--stop-on-zero is set, and the queue length is zero! Stopping!');
exit; exit;
} }

View file

@ -27,18 +27,19 @@ abstract class AbstractWorker implements WorkerInterface
); );
} }
protected function setUp(): void
{
}
/** /**
* @param bool $stopOnZero * @param bool $stopOnZero
*/ */
public function setStopOnZero(bool $stopOnZero): self public function setStopOnZero(bool $stopOnZero): self
{ {
$this->stopOnZero = $stopOnZero; $this->stopOnZero = $stopOnZero;
return $this; return $this;
} }
protected function setUp(): void
{
}
public function run(): void public function run(): void
{ {

View file

@ -13,13 +13,16 @@ class WorkerWorkItem implements \Serializable
{ {
$method = substr(strtolower($name), 0, 3); $method = substr(strtolower($name), 0, 3);
$field = substr(strtolower($name), 3); $field = substr(strtolower($name), 3);
switch ($method) { switch ($method) {
case 'set': case 'set':
$this->data[$field] = $arguments[0]; $this->data[$field] = $arguments[0];
return $this; return $this;
case 'get': case 'get':
return $this->data[$field]; return $this->data[$field];
default: default:
throw new WorkerException("Method {$name} doesn't exist"); throw new WorkerException("Method {$name} doesn't exist");
} }