diff --git a/.php_cs.dist b/.php_cs.dist index 87b6018..d174572 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,33 +1,10 @@ in([ __DIR__ . DIRECTORY_SEPARATOR . 'app', __DIR__ . DIRECTORY_SEPARATOR . 'tests', ])->notPath(['cache', 'vendor']); -return PhpCsFixer\Config::create()->setRules([ - '@PSR1' => true, - '@PSR2' => true, - '@Symfony' => true, - 'array_indentation' => true, - 'array_syntax' => [ - 'syntax' => 'short' - ], - 'concat_space' => [ - 'spacing' => 'one' - ], - 'linebreak_after_opening_tag' => true, - 'new_with_braces' => false, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_superfluous_phpdoc_tags' => false, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'not_operator_with_successor_space' => true, - 'phpdoc_to_comment' => false, - 'phpdoc_no_empty_return' => false, - 'phpdoc_order' => true, - 'semicolon_after_instruction' => true, - 'single_trait_insert_per_statement' => false, - 'trailing_comma_in_multiline_array' => false, - 'yoda_style' => null -])->setFinder($finder); +return PHLAK\CodingStandards\ConfigFactory::make($finder); diff --git a/app/src/Bootstrap/AppManager.php b/app/src/Bootstrap/AppManager.php index 1dba29b..63d3da3 100644 --- a/app/src/Bootstrap/AppManager.php +++ b/app/src/Bootstrap/AppManager.php @@ -11,21 +11,13 @@ class AppManager /** @var Container The applicaiton container */ protected $container; - /** - * Create a new AppManager object. - * - * @param \DI\Container $container - */ + /** Create a new AppManager object. */ public function __construct(Container $container) { $this->container = $container; } - /** - * Setup and configure the application. - * - * @return \Slim\App - */ + /** Setup and configure the application. */ public function __invoke(): App { $app = Bridge::create($this->container); diff --git a/app/src/Bootstrap/ExceptionManager.php b/app/src/Bootstrap/ExceptionManager.php index 6b19455..d50ee1a 100644 --- a/app/src/Bootstrap/ExceptionManager.php +++ b/app/src/Bootstrap/ExceptionManager.php @@ -14,23 +14,14 @@ class ExceptionManager /** @var Config The application configuration */ protected $config; - /** - * Create a new ExceptionManager object. - * - * @param \Slim\App $app - * @param \App\Config $config - */ + /** Create a new ExceptionManager object. */ public function __construct(App $app, Config $config) { $this->app = $app; $this->config = $config; } - /** - * Set up and configure exception handling. - * - * @return void - */ + /** Set up and configure exception handling. */ public function __invoke(): void { if ($this->config->get('debug')) { diff --git a/app/src/Bootstrap/MiddlewareManager.php b/app/src/Bootstrap/MiddlewareManager.php index 19ff6ad..05eec57 100644 --- a/app/src/Bootstrap/MiddlewareManager.php +++ b/app/src/Bootstrap/MiddlewareManager.php @@ -13,23 +13,14 @@ class MiddlewareManager /** @var Config The application configuration */ protected $config; - /** - * Create a new MiddlwareManager object. - * - * @param \Slim\App $app - * @param \App\Config $config - */ + /** Create a new MiddlwareManager object. */ public function __construct(App $app, Config $config) { $this->app = $app; $this->config = $config; } - /** - * Register application middlewares. - * - * @return void - */ + /** Register application middlewares. */ public function __invoke(): void { foreach ($this->config->get('middlewares') as $middleware) { diff --git a/app/src/Bootstrap/RouteManager.php b/app/src/Bootstrap/RouteManager.php index 1f55416..909f5cc 100644 --- a/app/src/Bootstrap/RouteManager.php +++ b/app/src/Bootstrap/RouteManager.php @@ -10,21 +10,13 @@ class RouteManager /** @var App The application */ protected $app; - /** - * Create a new RouteManager object. - * - * @param \Slim\App $app - */ + /** Create a new RouteManager object. */ public function __construct(App $app) { $this->app = $app; } - /** - * Register the application routes. - * - * @return void - */ + /** Register the application routes. */ public function __invoke(): void { $this->app->get('/[{path:.*}]', Controllers\IndexController::class); diff --git a/app/src/Config.php b/app/src/Config.php index 7807c8e..6151760 100644 --- a/app/src/Config.php +++ b/app/src/Config.php @@ -10,20 +10,14 @@ class Config /** @var Container The application container */ protected $container; + /** Create a new Config object. */ public function __construct(Container $container) { $this->container = $container; } - /** - * Get the value of a configuration variable. - * - * @param string $key The unique configuration variable ID - * @param mixed $default Default value to return if no environment variable is set - * - * @return mixed - */ - public function get($key, $default = null) + /** Get the value of a configuration variable. */ + public function get(string $key, $default = null) { try { $value = $this->container->get($key); diff --git a/app/src/Controllers/DirectoryController.php b/app/src/Controllers/DirectoryController.php index aff50f1..b2d1d01 100644 --- a/app/src/Controllers/DirectoryController.php +++ b/app/src/Controllers/DirectoryController.php @@ -26,14 +26,7 @@ class DirectoryController /** @var TranslatorInterface Translator component */ protected $translator; - /** - * Create a new IndexController object. - * - * @param \App\Config $config - * @param \Symfony\Component\Finder\Finder $finder - * @param \Slim\Views\Twig $view - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new IndexController object. */ public function __construct( Config $config, Finder $finder, @@ -46,14 +39,7 @@ class DirectoryController $this->translator = $translator; } - /** - * Invoke the IndexController. - * - * @param \Slim\Psr7\Request $request - * @param \Slim\Psr7\Response $response - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the IndexController. */ public function __invoke(Request $request, Response $response): ResponseInterface { $path = $request->getQueryParams()['dir'] ?? '.'; @@ -62,7 +48,7 @@ class DirectoryController $files = $this->finder->in($path)->depth(0); } catch (Exception $exception) { return $this->view->render($response->withStatus(404), 'error.twig', [ - 'message' => $this->translator->trans('error.directory_not_found') + 'message' => $this->translator->trans('error.directory_not_found'), ]); } @@ -74,13 +60,7 @@ class DirectoryController ]); } - /** - * Return the README file within a finder object. - * - * @param \Symfony\Component\Finder\Finder $files - * - * @return \Symfony\Component\Finder\SplFileInfo|null - */ + /** Return the README file within a finder object. */ protected function readme(Finder $files): ?SplFileInfo { if (! $this->config->get('display_readmes')) { diff --git a/app/src/Controllers/FileInfoController.php b/app/src/Controllers/FileInfoController.php index 58c09fb..8f13188 100644 --- a/app/src/Controllers/FileInfoController.php +++ b/app/src/Controllers/FileInfoController.php @@ -21,13 +21,7 @@ class FileInfoController /** @var TranslatorInterface Translator component */ protected $translator; - /** - * Create a new FileInfoHandler object. - * - * @param \App\Config $config - * @param \Symfony\Contracts\Cache\CacheInterface $cache - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new FileInfoHandler object. */ public function __construct( Config $config, CacheInterface $cache, @@ -38,14 +32,7 @@ class FileInfoController $this->translator = $translator; } - /** - * Invoke the FileInfoHandler. - * - * @param \Slim\Psr7\Request $request - * @param \Slim\Psr7\Response $response - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the FileInfoHandler. */ public function __invoke(Request $request, Response $response): ResponseInterface { $path = $request->getQueryParams()['info']; @@ -72,13 +59,7 @@ class FileInfoController return $response->withHeader('Content-Type', 'application/json'); } - /** - * Get an array of hashes for a file. - * - * @param \SplFileInfo $file - * - * @return array - */ + /** Get an array of hashes for a file. */ protected function calculateHashes(SplFileInfo $file): array { return [ diff --git a/app/src/Controllers/IndexController.php b/app/src/Controllers/IndexController.php index 6f85825..2789f1f 100644 --- a/app/src/Controllers/IndexController.php +++ b/app/src/Controllers/IndexController.php @@ -3,6 +3,7 @@ namespace App\Controllers; use DI\Container; +use Psr\Http\Message\ResponseInterface; use Slim\Psr7\Request; use Slim\Psr7\Response; @@ -11,25 +12,14 @@ class IndexController /** @var Container Application container */ protected $container; - /** - * Create a new IndexController object. - * - * @param \DI\Container $container - */ + /** Create a new IndexController object. */ public function __construct(Container $container) { $this->container = $container; } - /** - * Invoke the IndexController. - * - * @param \Slim\Psr7\Request $request - * @param \Slim\Psr7\Response $response - * - * @return \Psr\Http\Message\ResponseInterface - */ - public function __invoke(Request $request, Response $response) + /** Invoke the IndexController. */ + public function __invoke(Request $request, Response $response): ResponseInterface { switch (true) { case array_key_exists('info', $request->getQueryParams()): diff --git a/app/src/Controllers/SearchController.php b/app/src/Controllers/SearchController.php index ab503a9..46ea15f 100644 --- a/app/src/Controllers/SearchController.php +++ b/app/src/Controllers/SearchController.php @@ -20,13 +20,7 @@ class SearchController /** @var TranslatorInterface Translator component */ protected $translator; - /** - * Create a new SearchHandler object. - * - * @param \Symfony\Component\Finder\Finder $finder - * @param \Slim\Views\Twig $view - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new SearchHandler object. */ public function __construct(Finder $finder, Twig $view, TranslatorInterface $translator) { $this->finder = $finder; @@ -34,14 +28,7 @@ class SearchController $this->translator = $translator; } - /** - * Invoke the SearchHandler. - * - * @param \Slim\Psr7\Request $request - * @param \Slim\Psr7\Response $response - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the SearchHandler. */ public function __invoke(Request $request, Response $response): ResponseInterface { $search = $request->getQueryParams()['search']; diff --git a/app/src/Controllers/ZipController.php b/app/src/Controllers/ZipController.php index 837a45c..13c6edb 100644 --- a/app/src/Controllers/ZipController.php +++ b/app/src/Controllers/ZipController.php @@ -28,14 +28,7 @@ class ZipController /** @var TranslatorInterface Translator component */ protected $translator; - /** - * Create a new ZipHandler object. - * - * @param \App\Config $config - * @param \Symfony\Contracts\Cache\CacheInterface $cache - * @param \PhpCsFixer\Finder $finder - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new ZipHandler object. */ public function __construct( Config $config, CacheInterface $cache, @@ -48,14 +41,7 @@ class ZipController $this->translator = $translator; } - /** - * Invoke the ZipHandler. - * - * @param \Slim\Psr7\Request $request - * @param \Slim\Psr7\Response $response - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the ZipHandler. */ public function __invoke(Request $request, Response $response): ResponseInterface { $path = $request->getQueryParams()['zip']; @@ -77,13 +63,7 @@ class ZipController )); } - /** - * Create a zip file from a directory. - * - * @param string $path - * - * @return \App\TemporaryFile - */ + /** Create a zip file from a directory. */ protected function createZip(string $path): TemporaryFile { $zip = new ZipArchive; @@ -100,14 +80,7 @@ class ZipController return $tempFile; } - /** - * Return the path to a file with the preceding root path stripped. - * - * @param \Symfony\Component\Finder\SplFileInfo $file - * @param string $path - * - * @return string - */ + /** Return the path to a file with the preceding root path stripped. */ protected function stripPath(SplFileInfo $file, string $path): string { $pattern = sprintf( @@ -117,13 +90,7 @@ class ZipController return preg_replace($pattern, '', $file->getPathname()); } - /** - * Generate the file name for a path. - * - * @param string $path - * - * @return string - */ + /** Generate the file name for a path. */ protected function generateFileName(string $path): string { $filename = Str::explode($path, DIRECTORY_SEPARATOR)->last(); diff --git a/app/src/Exceptions/ErrorHandler.php b/app/src/Exceptions/ErrorHandler.php index d93bd76..8fd4f41 100644 --- a/app/src/Exceptions/ErrorHandler.php +++ b/app/src/Exceptions/ErrorHandler.php @@ -18,29 +18,14 @@ class ErrorHandler implements ErrorHandlerInterface /** @var TranslatorInterface Translation component */ protected $translator; - /** - * Create a new ErrorHandler object. - * - * @param \Slim\Views\Twig $view - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new ErrorHandler object. */ public function __construct(Twig $view, TranslatorInterface $translator) { $this->view = $view; $this->translator = $translator; } - /** - * Invoke the ErrorHandler class. - * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Throwable $exception - * @param bool $displayErrorDetails - * @param bool $logErrors - * @param bool $logErrorDetails - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the ErrorHandler class. */ public function __invoke( ServerRequestInterface $request, Throwable $exception, @@ -52,7 +37,7 @@ class ErrorHandler implements ErrorHandlerInterface if (in_array('application/json', explode(',', $request->getHeaderLine('Accept')))) { $response->getBody()->write(json_encode([ - 'error' => ['message' => $this->translator->trans('error.unexpected')] + 'error' => ['message' => $this->translator->trans('error.unexpected')], ])); return $response->withHeader('Content-Type', 'application/json'); diff --git a/app/src/Exceptions/InvalidConfiguration.php b/app/src/Exceptions/InvalidConfiguration.php index cba7a24..01673bc 100644 --- a/app/src/Exceptions/InvalidConfiguration.php +++ b/app/src/Exceptions/InvalidConfiguration.php @@ -6,14 +6,7 @@ use RuntimeException; class InvalidConfiguration extends RuntimeException { - /** - * Create an exception from a configuration option and value. - * - * @param string $option - * @param mixed $value - * - * @return self - */ + /** Create an exception from a configuration option and value. */ public static function fromConfig(string $option, $value): self { return new static( diff --git a/app/src/Factories/CacheFactory.php b/app/src/Factories/CacheFactory.php index 1e4fe3a..0daeb6c 100644 --- a/app/src/Factories/CacheFactory.php +++ b/app/src/Factories/CacheFactory.php @@ -27,23 +27,14 @@ class CacheFactory /** @var Config The application configuration */ protected $config; - /** - * Create a new CacheFactory object. - * - * @param \DI\Container $container - * @param Config $config - */ + /** Create a new CacheFactory object. */ public function __construct(Container $container, Config $config) { $this->container = $container; $this->config = $config; } - /** - * Initialize and return a CacheInterface. - * - * @return \Symfony\Contracts\Cache\CacheInterface - */ + /** Initialize and return a CacheInterface. */ public function __invoke(): CacheInterface { switch ($this->config->get('cache_driver')) { diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 2bbf4fd..f7727d6 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -25,13 +25,7 @@ class FinderFactory /** @var Config The application configuration */ protected $config; - /** - * Create a new FinderFactory object. - * - * @param \DI\Container $container - * @param \App\Config $config - * @param \App\HiddenFiles $hiddenFiles - */ + /** Create a new FinderFactory object. */ public function __construct( Container $container, Config $config, @@ -42,11 +36,7 @@ class FinderFactory $this->hiddenFiles = $hiddenFiles; } - /** - * Initialize and return the Finder component. - * - * @return \Symfony\Component\Finder\Finder - */ + /** Initialize and return the Finder component. */ public function __invoke(): Finder { $finder = Finder::create()->followLinks(); @@ -76,13 +66,7 @@ class FinderFactory return $finder; } - /** - * Determine if a file should be hidden. - * - * @param \Symfony\Component\Finder\SplFileInfo $file - * - * @return bool - */ + /** Determine if a file should be hidden. */ protected function isHidden(SplFileInfo $file): bool { if (! isset($this->pattern)) { diff --git a/app/src/Factories/TranslationFactory.php b/app/src/Factories/TranslationFactory.php index 1f19ec2..f8be6e6 100644 --- a/app/src/Factories/TranslationFactory.php +++ b/app/src/Factories/TranslationFactory.php @@ -19,22 +19,14 @@ class TranslationFactory /** @var CacheInterface The application cache */ protected $cache; - /** - * Create a new TranslationFactory object. - * - * @param \App\Config $config - */ + /** Create a new TranslationFactory object. */ public function __construct(Config $config, CacheInterface $cache) { $this->config = $config; $this->cache = $cache; } - /** - * Initialize and return the translation component. - * - * @return \Symfony\Contracts\Translation\TranslatorInterface - */ + /** Initialize and return the translation component. */ public function __invoke(): TranslatorInterface { if (! in_array( @@ -56,11 +48,7 @@ class TranslationFactory return $translator; } - /** - * Get an array of available translation languages. - * - * @return array - */ + /** Get an array of available translation languages. */ protected function translations(): array { return $this->cache->get('translations', function (): array { diff --git a/app/src/Factories/TwigFactory.php b/app/src/Factories/TwigFactory.php index 235c32e..d0807dc 100644 --- a/app/src/Factories/TwigFactory.php +++ b/app/src/Factories/TwigFactory.php @@ -17,12 +17,7 @@ class TwigFactory /** @var CallableResolver The callable resolver */ protected $callableResolver; - /** - * Create a new TwigFactory object. - * - * @param \App\Config $config - * @param \Invoker\CallableResolver $callableResolver - */ + /** Create a new TwigFactory object. */ public function __construct( Config $config, CallableResolver $callableResolver @@ -31,11 +26,7 @@ class TwigFactory $this->callableResolver = $callableResolver; } - /** - * Initialize and return the Twig component. - * - * @return \Slim\Views\Twig - */ + /** Initialize and return the Twig component. */ public function __invoke(): Twig { $twig = new Twig(new FilesystemLoader( diff --git a/app/src/HiddenFiles.php b/app/src/HiddenFiles.php index 3f64c41..6a995a1 100644 --- a/app/src/HiddenFiles.php +++ b/app/src/HiddenFiles.php @@ -12,11 +12,7 @@ class HiddenFiles extends Collection $this->items = $this->getArrayableItems($items); } - /** - * Create a new HiddenFiles collection object. - * - * @param \App\Config $config - */ + /** Create a new HiddenFiles collection object. */ public static function fromConfig(Config $config): self { $items = $config->get('hidden_files'); diff --git a/app/src/Middlewares/WhoopsMiddleware.php b/app/src/Middlewares/WhoopsMiddleware.php index d0157f0..d8cee5c 100644 --- a/app/src/Middlewares/WhoopsMiddleware.php +++ b/app/src/Middlewares/WhoopsMiddleware.php @@ -20,13 +20,7 @@ class WhoopsMiddleware /** @var JsonResponseHandler The JSON response handler */ protected $jsonHandler; - /** - * Create a new WhoopseMiddleware object. - * - * @param \Whoops\RunInterface $whoops - * @param \Whoops\Handler\PrettyPageHandler $pageHandler - * @param \Whoops\Handler\JsonResponseHandler $jsonHandler - */ + /** Create a new WhoopseMiddleware object. */ public function __construct( RunInterface $whoops, PrettyPageHandler $pageHandler, @@ -37,14 +31,7 @@ class WhoopsMiddleware $this->jsonHandler = $jsonHandler; } - /** - * Invoke the WhoopseMiddleware class. - * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Psr\Http\Server\RequestHandlerInterface $handler - * - * @return \Psr\Http\Message\ResponseInterface - */ + /** Invoke the WhoopseMiddleware class. */ public function __invoke(Request $request, RequestHandler $handler): ResponseInterface { $this->pageHandler->setPageTitle( diff --git a/app/src/SortMethods/Accessed.php b/app/src/SortMethods/Accessed.php index 13bf928..001ef14 100644 --- a/app/src/SortMethods/Accessed.php +++ b/app/src/SortMethods/Accessed.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Accessed extends SortMethod { - /** - * Sort by file accessed time. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sort by file accessed time. */ public function __invoke(Finder $finder): void { $finder->sortByAccessedTime(); diff --git a/app/src/SortMethods/Changed.php b/app/src/SortMethods/Changed.php index 03bb960..977c40f 100644 --- a/app/src/SortMethods/Changed.php +++ b/app/src/SortMethods/Changed.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Changed extends SortMethod { - /** - * Sory by file changed time. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sory by file changed time. */ public function __invoke(Finder $finder): void { $finder->sortByChangedTime(); diff --git a/app/src/SortMethods/Modified.php b/app/src/SortMethods/Modified.php index 3cc43a9..ebf4f38 100644 --- a/app/src/SortMethods/Modified.php +++ b/app/src/SortMethods/Modified.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Modified extends SortMethod { - /** - * Sort by file modified time. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sort by file modified time. */ public function __invoke(Finder $finder): void { $finder->sortByModifiedTime(); diff --git a/app/src/SortMethods/Name.php b/app/src/SortMethods/Name.php index aa430d9..c78b607 100644 --- a/app/src/SortMethods/Name.php +++ b/app/src/SortMethods/Name.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Name extends SortMethod { - /** - * Sort by file name. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sort by file name. */ public function __invoke(Finder $finder): void { $finder->sortByName(); diff --git a/app/src/SortMethods/Natural.php b/app/src/SortMethods/Natural.php index 4d8c328..8db0276 100644 --- a/app/src/SortMethods/Natural.php +++ b/app/src/SortMethods/Natural.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Natural extends SortMethod { - /** - * Sort by (natural) file name. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sort by (natural) file name. */ public function __invoke(Finder $finder): void { $finder->sortByName(true); diff --git a/app/src/SortMethods/SortMethod.php b/app/src/SortMethods/SortMethod.php index a1ca583..e5d1025 100644 --- a/app/src/SortMethods/SortMethod.php +++ b/app/src/SortMethods/SortMethod.php @@ -6,12 +6,6 @@ use Symfony\Component\Finder\Finder; abstract class SortMethod { - /** - * Run the sort method. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Run the sort method. */ abstract public function __invoke(Finder $finder): void; } diff --git a/app/src/SortMethods/Type.php b/app/src/SortMethods/Type.php index 7e51a0f..18e3a7a 100644 --- a/app/src/SortMethods/Type.php +++ b/app/src/SortMethods/Type.php @@ -6,13 +6,7 @@ use Symfony\Component\Finder\Finder; class Type extends SortMethod { - /** - * Sory by file type. - * - * @param \Symfony\Component\Finder\Finder $finder - * - * @return void - */ + /** Sory by file type. */ public function __invoke(Finder $finder): void { $finder->sortByType(); diff --git a/app/src/Support/Str.php b/app/src/Support/Str.php index 7a5f04e..36024e1 100644 --- a/app/src/Support/Str.php +++ b/app/src/Support/Str.php @@ -6,14 +6,7 @@ use Tightenco\Collect\Support\Collection; class Str { - /** - * Explode a string by a string into a collection. - * - * @param string $string - * @param string $delimiter - * - * @return \Tightenco\Collect\Support\Collection - */ + /** Explode a string by a string into a collection. */ public static function explode(string $string, string $delimiter): Collection { return Collection::make(explode($delimiter, $string)); diff --git a/app/src/TemporaryFile.php b/app/src/TemporaryFile.php index 1b9c02b..8f1ed49 100644 --- a/app/src/TemporaryFile.php +++ b/app/src/TemporaryFile.php @@ -7,12 +7,7 @@ class TemporaryFile /** @var string Path to the temporary file */ protected $path; - /** - * Create a new TemporaryFile object. - * - * @param string $dir - * @param string $prefix - */ + /** Create a new TemporaryFile object. */ public function __construct(string $dir, string $prefix = '') { $this->path = tempnam($dir, $prefix); @@ -24,21 +19,13 @@ class TemporaryFile unlink($this->path); } - /** - * Get the path to the temporary file. - * - * @return string - */ + /** Get the path to the temporary file. */ public function __toString(): string { return $this->path; } - /** - * Get the raw contents of the file. - * - * @return string - */ + /** Get the raw contents of the file. */ public function getContents(): string { return file_get_contents($this->path); diff --git a/app/src/ViewFunctions/Asset.php b/app/src/ViewFunctions/Asset.php index cb183a5..0f1d807 100644 --- a/app/src/ViewFunctions/Asset.php +++ b/app/src/ViewFunctions/Asset.php @@ -13,23 +13,13 @@ class Asset extends ViewFunction /** @var Config The application configuration */ protected $config; - /** - * Create a new Asset object. - * - * @param \App\Config $container - */ + /** Create a new Asset object. */ public function __construct(Config $container) { $this->config = $container; } - /** - * Return the path to an asset. - * - * @param string $path - * - * @return string - */ + /** Return the path to an asset. */ public function __invoke(string $path): string { $path = '/' . ltrim($path, '/'); @@ -41,11 +31,7 @@ class Asset extends ViewFunction return 'app/assets/' . ltrim($path, '/'); } - /** - * Return the mix manifest collection. - * - * @return \Tightenco\Collect\Support\Collection - */ + /** Return the mix manifest collection. */ protected function mixManifest(): Collection { $mixManifest = $this->config->get('asset_path') . '/mix-manifest.json'; diff --git a/app/src/ViewFunctions/Breadcrumbs.php b/app/src/ViewFunctions/Breadcrumbs.php index d56adc3..1077b9a 100644 --- a/app/src/ViewFunctions/Breadcrumbs.php +++ b/app/src/ViewFunctions/Breadcrumbs.php @@ -17,11 +17,7 @@ class Breadcrumbs extends ViewFunction /** @var string The directory separator */ protected $directorySeparator; - /** - * Create a new Breadcrumbs object. - * - * @param \App\Config $config - */ + /** Create a new Breadcrumbs object. */ public function __construct( Config $config, string $directorySeparator = DIRECTORY_SEPARATOR @@ -30,14 +26,8 @@ class Breadcrumbs extends ViewFunction $this->directorySeparator = $directorySeparator; } - /** - * Build an array of breadcrumbs for a given path. - * - * @param string $path - * - * @return array - */ - public function __invoke(string $path) + /** Build a collection of breadcrumbs for a given path. */ + public function __invoke(string $path): Collection { return Str::explode($path, $this->directorySeparator)->diff( explode($this->directorySeparator, $this->config->get('base_path')) diff --git a/app/src/ViewFunctions/Config.php b/app/src/ViewFunctions/Config.php index 83e0fe5..eb5cafd 100644 --- a/app/src/ViewFunctions/Config.php +++ b/app/src/ViewFunctions/Config.php @@ -12,22 +12,13 @@ class Config extends ViewFunction /** @var AppConfig The application configuration */ protected $config; - /** - * Create a new Config object. - */ + /** Create a new Config object. */ public function __construct(AppConfig $config) { $this->config = $config; } - /** - * Retrieve an item from the view config. - * - * @param string $key - * @param mixed $default - * - * @return mixed - */ + /** Retrieve an item from the view config. */ public function __invoke(string $key, $default = null) { return $this->config->get($key, $default); diff --git a/app/src/ViewFunctions/FileUrl.php b/app/src/ViewFunctions/FileUrl.php index 85c5252..f42a9dc 100644 --- a/app/src/ViewFunctions/FileUrl.php +++ b/app/src/ViewFunctions/FileUrl.php @@ -7,13 +7,7 @@ class FileUrl extends Url /** @var string The function name */ protected $name = 'file_url'; - /** - * Return the URL for a given path and action. - * - * @param string $path - * - * @return string - */ + /** Return the URL for a given path and action. */ public function __invoke(string $path = '/'): string { $path = $this->stripLeadingSlashes($path); diff --git a/app/src/ViewFunctions/Icon.php b/app/src/ViewFunctions/Icon.php index afa6874..f16006b 100644 --- a/app/src/ViewFunctions/Icon.php +++ b/app/src/ViewFunctions/Icon.php @@ -13,23 +13,13 @@ class Icon extends ViewFunction /** @var Config The application configuration */ protected $config; - /** - * Create a new Config object. - * - * @param \App\Config $config - */ + /** Create a new Config object. */ public function __construct(Config $config) { $this->config = $config; } - /** - * Retrieve the icon markup for a file. - * - * @param \Symfony\Component\Finder\SplFileInfo $file - * - * @return string - */ + /** Retrieve the icon markup for a file. */ public function __invoke(SplFileInfo $file): string { $icons = $this->config->get('icons'); diff --git a/app/src/ViewFunctions/Markdown.php b/app/src/ViewFunctions/Markdown.php index 0587c40..0b62b33 100644 --- a/app/src/ViewFunctions/Markdown.php +++ b/app/src/ViewFunctions/Markdown.php @@ -22,13 +22,7 @@ class Markdown extends ViewFunction $this->cache = $cache; } - /** - * Parses a string of markdown into HTML. - * - * @param string $string - * - * @return string - */ + /** Parses a string of markdown into HTML. */ public function __invoke(string $string): string { return $this->cache->get( diff --git a/app/src/ViewFunctions/ParentUrl.php b/app/src/ViewFunctions/ParentUrl.php index 8cccd3b..2add788 100644 --- a/app/src/ViewFunctions/ParentUrl.php +++ b/app/src/ViewFunctions/ParentUrl.php @@ -12,23 +12,13 @@ class ParentUrl extends ViewFunction /** @var string The directory separator */ protected $directorySeparator; - /** - * Create a new ParentUrl object. - * - * @param string $directorySeparator - */ + /** Create a new ParentUrl object. */ public function __construct(string $directorySeparator = DIRECTORY_SEPARATOR) { $this->directorySeparator = $directorySeparator; } - /** - * Get the parent directory for a given path. - * - * @param string $path - * - * @return string - */ + /** Get the parent directory for a given path. */ public function __invoke(string $path): string { $parentDir = Str::explode($path, $this->directorySeparator)->map( diff --git a/app/src/ViewFunctions/SizeForHumans.php b/app/src/ViewFunctions/SizeForHumans.php index 24a2cdb..6648458 100644 --- a/app/src/ViewFunctions/SizeForHumans.php +++ b/app/src/ViewFunctions/SizeForHumans.php @@ -9,13 +9,7 @@ class SizeForHumans extends ViewFunction /** @var string The function name */ protected $name = 'size_for_humans'; - /** - * Get the human readable file size from a file object. - * - * @param SplFileInfo $file A file object - * - * @return string - */ + /** Get the human readable file size from a file object. */ public function __invoke(SplFileInfo $file): string { $sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; diff --git a/app/src/ViewFunctions/Translate.php b/app/src/ViewFunctions/Translate.php index 9998991..e5322ae 100644 --- a/app/src/ViewFunctions/Translate.php +++ b/app/src/ViewFunctions/Translate.php @@ -12,23 +12,13 @@ class Translate extends ViewFunction /** @var TranslatorInterface The application translator */ protected $translator; - /** - * Create a new Translate object. - * - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ + /** Create a new Translate object. */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } - /** - * Retrieve a translated string by ID. - * - * @param string $id - * - * @return string - */ + /** Retrieve a translated string by ID. */ public function __invoke(string $id): string { return $this->translator->trans($id); diff --git a/app/src/ViewFunctions/Url.php b/app/src/ViewFunctions/Url.php index 20cdfab..37a1d46 100644 --- a/app/src/ViewFunctions/Url.php +++ b/app/src/ViewFunctions/Url.php @@ -12,47 +12,25 @@ class Url extends ViewFunction /** @var string The directory separator */ protected $directorySeparator; - /** - * Create a new Url object. - * - * @param string The directory separator - */ + /** Create a new Url object. */ public function __construct(string $directorySeparator = DIRECTORY_SEPARATOR) { $this->directorySeparator = $directorySeparator; } - /** - * Return the URL for a given path. - * - * @param string $path - * - * @return string - */ + /** Return the URL for a given path. */ public function __invoke(string $path = '/'): string { return $this->escape($this->stripLeadingSlashes($path)); } - /** - * Strip all leading slashes (and a single dot) from a path. - * - * @param string $path - * - * @return string - */ + /** Strip all leading slashes (and a single dot) from a path. */ protected function stripLeadingSlashes(string $path): string { return preg_replace('/^\.?(\/|\\\)+/', '', $path); } - /** - * Escape URL characters in path segments. - * - * @param string $path - * - * @return string - */ + /** Escape URL characters in path segments. */ protected function escape(string $path): string { return Str::explode($path, $this->directorySeparator)->map( diff --git a/app/src/ViewFunctions/ViewFunction.php b/app/src/ViewFunctions/ViewFunction.php index 99dd404..39535fc 100644 --- a/app/src/ViewFunctions/ViewFunction.php +++ b/app/src/ViewFunctions/ViewFunction.php @@ -7,11 +7,7 @@ abstract class ViewFunction /** @var string The function name */ protected $name = ''; - /** - * Get the function name. - * - * @return string - */ + /** Get the function name. */ public function name(): string { return $this->name; diff --git a/app/src/ViewFunctions/ZipUrl.php b/app/src/ViewFunctions/ZipUrl.php index 0487b51..9763369 100644 --- a/app/src/ViewFunctions/ZipUrl.php +++ b/app/src/ViewFunctions/ZipUrl.php @@ -7,13 +7,7 @@ class ZipUrl extends Url /** @var string The function name */ protected $name = 'zip_url'; - /** - * Return the URL for a given path and action. - * - * @param string $path - * - * @return string - */ + /** Return the URL for a given path and action. */ public function __invoke(string $path = '/'): string { $path = $this->stripLeadingSlashes($path); diff --git a/composer.json b/composer.json index 26819ec..d247c05 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "php": ">=7.4", "friendsofphp/php-cs-fixer": "^2.3", "johnkary/phpunit-speedtrap": "^3.2", + "phlak/coding-standards": "^1.0", "phpunit/phpunit": "^9.1", "psy/psysh": "^0.10", "symfony/var-dumper": "^5.0", diff --git a/composer.lock b/composer.lock index 81eb8a4..1664df5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "16d97309e81fc053a80d199efc8c07ae", + "content-hash": "c28463536e91138a491cb17979727aa8", "packages": [ { "name": "erusev/parsedown", @@ -3846,6 +3846,59 @@ "description": "Library for handling version information and constraints", "time": "2020-06-27T14:39:04+00:00" }, + { + "name": "phlak/coding-standards", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHLAK/CodingStandards.git", + "reference": "a9c9c51718c138b1785dbb301df176f9ee11617a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHLAK/CodingStandards/zipball/a9c9c51718c138b1785dbb301df176f9ee11617a", + "reference": "a9c9c51718c138b1785dbb301df176f9ee11617a", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "php": ">=7.2", + "phpunit/phpunit": "^9.3", + "symfony/var-dumper": "^5.1", + "vimeo/psalm": "^3.14" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHLAK\\CodingStandards\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Kankiewicz", + "email": "Chris@ChrisKankiewicz.com" + } + ], + "description": "A pre-defined set of coding standards for PHP CS Fixer.", + "funding": [ + { + "url": "https://github.com/sponsors/PHLAK", + "type": "github" + }, + { + "url": "https://paypal.me/ChrisKankiewicz", + "type": "paypal" + } + ], + "time": "2020-09-07T15:53:50+00:00" + }, { "name": "php-cs-fixer/diff", "version": "v1.3.0", diff --git a/tests/Bootstrap/MiddlewareManagerTest.php b/tests/Bootstrap/MiddlewareManagerTest.php index 4db9a28..ea7c7f2 100644 --- a/tests/Bootstrap/MiddlewareManagerTest.php +++ b/tests/Bootstrap/MiddlewareManagerTest.php @@ -12,7 +12,7 @@ class MiddlewareManagerTest extends TestCase { /** @const Array of application middlewares */ protected const MIDDLEWARES = [ - Middlewares\WhoopsMiddleware::class + Middlewares\WhoopsMiddleware::class, ]; public function test_it_registers_application_middlewares(): void diff --git a/tests/Controllers/DirectoryControllerTest.php b/tests/Controllers/DirectoryControllerTest.php index dd2713e..7c5297d 100644 --- a/tests/Controllers/DirectoryControllerTest.php +++ b/tests/Controllers/DirectoryControllerTest.php @@ -86,8 +86,6 @@ class DirectoryControllerTest extends TestCase /** * Provide config options in the following order: * [ app.hide_app_files, app.hide_vcs_files, app.display_readmes ]. - * - * @return array */ public function configOptions(): array { diff --git a/tests/Controllers/FileInfoControllerTest.php b/tests/Controllers/FileInfoControllerTest.php index 2274d79..12ad09d 100644 --- a/tests/Controllers/FileInfoControllerTest.php +++ b/tests/Controllers/FileInfoControllerTest.php @@ -32,7 +32,7 @@ class FileInfoControllerTest extends TestCase 'md5' => '6e35c5c3bca40dfb96cbb449fd06df38', 'sha1' => '7ea619032a992824fac30026d3df919939c7ebfb', 'sha256' => '40adf7348820699ed3e72dc950ccd8d8d538065a91eba3c76263c44b1d12df9c', - ] + ], ]), (string) $response->getBody()); } diff --git a/tests/Controllers/IndexControllerTest.php b/tests/Controllers/IndexControllerTest.php index f8649e3..51b8602 100644 --- a/tests/Controllers/IndexControllerTest.php +++ b/tests/Controllers/IndexControllerTest.php @@ -4,6 +4,8 @@ namespace Tests\Controllers; use App\Controllers; use DI\Container; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\ResponseInterface; use Slim\Psr7\Request; use Slim\Psr7\Response; use Tests\TestCase; @@ -11,80 +13,100 @@ use Tests\TestCase; /** @covers \App\Controllers\IndexController */ class IndexControllerTest extends TestCase { + /** @var Request&MockObject */ + protected $request; + + /** @var Response&MockObject */ + protected $response; + + /** @var Container&MockObject */ + protected $container; + + public function setUp(): void + { + parent::setUp(); + + $this->request = $this->createMock(Request::class); + $this->response = $this->createMock(Response::class); + $this->container = $this->createMock(Container::class); + } + public function test_it_handles_a_file_info_request(): void { - $request = $this->createMock(Request::class); - $request->method('getQueryParams')->willReturn(['info' => 'file.test']); + $this->request->method('getQueryParams')->willReturn(['info' => 'file.test']); + $this->response = $this->createMock(ResponseInterface::class); - $container = $this->createMock(Container::class); - $container->expects($this->once())->method('call')->with( + $this->container->expects($this->once())->method('call')->with( Controllers\FileInfoController::class, - [$request, $response = new Response] - ); + [$this->request, $this->response = new Response] + )->willReturn($this->response); - $controller = new Controllers\IndexController($container); + $controller = new Controllers\IndexController($this->container); - $controller($request, $response); + $response = $controller($this->request, $this->response); + + $this->assertInstanceOf(ResponseInterface::class, $response); } public function test_it_handles_a_search_request(): void { - $request = $this->createMock(Request::class); - $request->method('getQueryParams')->willReturn(['search' => 'file.test']); + $this->request->method('getQueryParams')->willReturn(['search' => 'file.test']); - $container = $this->createMock(Container::class); - $container->expects($this->once())->method('call')->with( + $this->container->expects($this->once())->method('call')->with( Controllers\SearchController::class, - [$request, $response = new Response] - ); + [$this->request, $this->response] + )->willReturn($this->response); - $controller = new Controllers\IndexController($container); + $controller = new Controllers\IndexController($this->container); - $controller($request, $response); + $response = $controller($this->request, $this->response); + + $this->assertInstanceOf(ResponseInterface::class, $response); } public function test_it_handles_a_zip_request(): void { - $request = $this->createMock(Request::class); - $request->method('getQueryParams')->willReturn(['zip' => 'subdir']); + $this->request->method('getQueryParams')->willReturn(['zip' => 'subdir']); - $container = $this->createMock(Container::class); - $container->expects($this->once())->method('call')->with( + $this->container->expects($this->once())->method('call')->with( Controllers\ZipController::class, - [$request, $response = new Response] - ); + [$this->request, $this->response] + )->willReturn($this->response); - $controller = new Controllers\IndexController($container); + $controller = new Controllers\IndexController($this->container); - $controller($request, $response); + $response = $controller($this->request, $this->response); + + $this->assertInstanceOf(ResponseInterface::class, $response); } public function test_it_handles_a_directory_request(): void { - $request = $this->createMock(Request::class); - $request->method('getQueryParams')->willReturn(['dir' => 'some/directory']); + $this->request->method('getQueryParams')->willReturn(['dir' => 'some/directory']); - $container = $this->createMock(Container::class); - $container->expects($this->once())->method('call')->with( + $this->container->expects($this->once())->method('call')->with( Controllers\DirectoryController::class, - [$request, $response = new Response] - ); + [$this->request, $this->response] + )->willReturn($this->response); - $controller = new Controllers\IndexController($container); + $controller = new Controllers\IndexController($this->container); - $controller($request, $response); + $response = $controller($this->request, $this->response); + + $this->assertInstanceOf(ResponseInterface::class, $response); } public function test_it_handles_a_directory_request_by_default(): void { - $container = $this->createMock(Container::class); - $container->expects($this->once())->method('call')->with( + $this->container->expects($this->once())->method('call')->with( Controllers\DirectoryController::class, - [$request = $this->createMock(Request::class), $response = new Response] - ); + [$this->request, $this->response] + )->willReturn($this->response); - $controller = new Controllers\IndexController($container); + $controller = new Controllers\IndexController($this->container); - $controller($request, $response); + $response = $controller($this->request, $this->response); + + $this->assertInstanceOf(ResponseInterface::class, $response); } } diff --git a/tests/Factories/FinderFactoryTest.php b/tests/Factories/FinderFactoryTest.php index e7c994c..16c3129 100644 --- a/tests/Factories/FinderFactoryTest.php +++ b/tests/Factories/FinderFactoryTest.php @@ -80,7 +80,7 @@ class FinderFactoryTest extends TestCase public function test_it_does_not_return_hidden_files(): void { $this->container->set('hidden_files', [ - 'subdir/alpha.scss', 'subdir/charlie.bash', '**/*.yaml' + 'subdir/alpha.scss', 'subdir/charlie.bash', '**/*.yaml', ]); $finder = (new FinderFactory( diff --git a/tests/HiddenFilesTest.php b/tests/HiddenFilesTest.php index e77ad83..18a03f3 100644 --- a/tests/HiddenFilesTest.php +++ b/tests/HiddenFilesTest.php @@ -29,24 +29,24 @@ class HiddenFilesTest extends TestCase { return [ 'None' => [ - [], 'NOT_A_REAL_FILE', false, [] + [], 'NOT_A_REAL_FILE', false, [], ], 'Hidden files array' => [ - ['foo', 'bar', 'baz'], 'NOT_A_REAL_FILE', false, ['foo', 'bar', 'baz'] + ['foo', 'bar', 'baz'], 'NOT_A_REAL_FILE', false, ['foo', 'bar', 'baz'], ], 'Hidden files array with duplicates' => [ - ['foo', 'bar', 'foo'], 'NOT_A_REAL_FILE', false, ['foo', 'bar'] + ['foo', 'bar', 'foo'], 'NOT_A_REAL_FILE', false, ['foo', 'bar'], ], 'Hidden files list' => [ - [], $this->filePath('.hidden'), false, ['alpha', 'bravo'] + [], $this->filePath('.hidden'), false, ['alpha', 'bravo'], ], 'App files' => [ - [], 'NOT_A_REAL_FILE', true, ['app', 'index.php', '.hidden'] + [], 'NOT_A_REAL_FILE', true, ['app', 'index.php', '.hidden'], ], 'All' => [ ['foo', 'alpha'], $this->filePath('.hidden'), true, [ - 'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden' - ] + 'foo', 'alpha', 'bravo', 'app', 'index.php', '.hidden', + ], ], ]; } diff --git a/tests/TestCase.php b/tests/TestCase.php index dfaded0..2fbb4c0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,11 +21,7 @@ class TestCase extends PHPUnitTestCase /** @var string Path to test files directory */ protected $testFilesPath = __DIR__ . '/_files'; - /** - * This method is called before each test. - * - * @return void - */ + /** This method is called before each test. */ public function setUp(): void { Dotenv::createUnsafeImmutable(__DIR__)->safeLoad(); @@ -42,13 +38,7 @@ class TestCase extends PHPUnitTestCase $this->container->set('cache_path', $this->filePath('app/cache')); } - /** - * Get the file path to a test file. - * - * @param string $filePath - * - * @return string - */ + /** Get the file path to a test file. */ protected function filePath(string $filePath): string { return realpath($this->testFilesPath . '/' . $filePath);