mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-28 08:10:51 +02:00
Require phlak/coding-standards for development and applied new coding standards
This commit is contained in:
29
.php_cs.dist
29
.php_cs.dist
@@ -1,33 +1,10 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/app/vendor/autoload.php';
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()->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);
|
||||
|
@@ -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);
|
||||
|
@@ -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')) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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')) {
|
||||
|
@@ -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 [
|
||||
|
@@ -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()):
|
||||
|
@@ -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'];
|
||||
|
@@ -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();
|
||||
|
@@ -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');
|
||||
|
@@ -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(
|
||||
|
@@ -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')) {
|
||||
|
@@ -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)) {
|
||||
|
@@ -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 {
|
||||
|
@@ -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(
|
||||
|
@@ -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');
|
||||
|
@@ -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(
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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));
|
||||
|
@@ -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);
|
||||
|
@@ -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';
|
||||
|
@@ -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'))
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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');
|
||||
|
@@ -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(
|
||||
|
@@ -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(
|
||||
|
@@ -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'];
|
||||
|
@@ -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);
|
||||
|
@@ -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(
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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",
|
||||
|
55
composer.lock
generated
55
composer.lock
generated
@@ -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",
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -32,7 +32,7 @@ class FileInfoControllerTest extends TestCase
|
||||
'md5' => '6e35c5c3bca40dfb96cbb449fd06df38',
|
||||
'sha1' => '7ea619032a992824fac30026d3df919939c7ebfb',
|
||||
'sha256' => '40adf7348820699ed3e72dc950ccd8d8d538065a91eba3c76263c44b1d12df9c',
|
||||
]
|
||||
],
|
||||
]), (string) $response->getBody());
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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(
|
||||
|
@@ -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',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user