From eae6ca8daf8ab3572c0e01c25e7f20f61802801f Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 2 Aug 2019 00:17:23 +0300 Subject: [PATCH] Flextype Core and Plugins: Doctrine Coding Standard #200 #186 - next round of code improvements --- flextype/bootstrap.php | 106 ++++++++++++---------- flextype/middlewares.php | 11 ++- flextype/parsers/JsonParser.php | 48 +++++----- flextype/routes/web.php | 7 +- flextype/twig/AssetsTwigExtension.php | 11 ++- flextype/twig/CsrfTwigExtension.php | 43 +++++---- flextype/twig/EmitterTwigExtension.php | 12 ++- flextype/twig/EntriesTwigExtension.php | 12 ++- flextype/twig/FilesystemTwigExtension.php | 24 +++-- flextype/twig/FlashTwigExtension.php | 17 ++-- flextype/twig/GlobalVarsTwigExtension.php | 13 ++- flextype/twig/I18nTwigExtension.php | 15 +-- flextype/twig/JsonParserTwigExtension.php | 16 ++-- flextype/twig/ShortcodesTwigExtension.php | 15 +-- flextype/twig/SnippetsTwigExtension.php | 12 ++- index.php | 40 +++++--- 16 files changed, 222 insertions(+), 180 deletions(-) diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index a898b11f..0deb44b5 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,9 +11,20 @@ namespace Flextype; -use Flextype\Component\Session\Session; -use Flextype\Component\Registry\Registry; use Flextype\Component\Filesystem\Filesystem; +use Flextype\Component\Registry\Registry; +use Flextype\Component\Session\Session; +use RuntimeException; +use Slim\App; +use Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware; +use function array_replace_recursive; +use function date_default_timezone_set; +use function define; +use function error_reporting; +use function function_exists; +use function mb_internal_encoding; +use function mb_language; +use function mb_regex_encoding; /** * The version of Flextype @@ -45,52 +55,53 @@ $default_settings_file_path = PATH['config']['default'] . '/settings.json'; $site_settings_file_path = PATH['config']['site'] . '/settings.json'; // Set settings if Flextype settings and Site settings config files exist -if (Filesystem::has($default_settings_file_path) && Filesystem::has($site_settings_file_path)) { - if (($content = Filesystem::read($default_settings_file_path)) === false) { - throw new \RuntimeException('Load file: ' . $default_settings_file_path . ' - failed!'); - } else { - $default_settings = JsonParser::decode($content); - } - - if (($content = Filesystem::read($site_settings_file_path)) === false) { - throw new \RuntimeException('Load file: ' . $site_settings_file_path . ' - failed!'); - } else { - $site_settings = JsonParser::decode($content); - } - - // Merge settings - $settings = array_replace_recursive($default_settings, $site_settings); - - // Set settings - $registry->set('settings', $settings); -} else { - throw new \RuntimeException("Flextype settings and Site settings config files does not exist."); +if (! Filesystem::has($default_settings_file_path) || ! Filesystem::has($site_settings_file_path)) { + throw new RuntimeException('Flextype settings and Site settings config files does not exist.'); } +if (($content = Filesystem::read($default_settings_file_path)) === false) { + throw new RuntimeException('Load file: ' . $default_settings_file_path . ' - failed!'); +} else { + $default_settings = JsonParser::decode($content); +} + +if (($content = Filesystem::read($site_settings_file_path)) === false) { + throw new RuntimeException('Load file: ' . $site_settings_file_path . ' - failed!'); +} else { + $site_settings = JsonParser::decode($content); +} + +// Merge settings +$settings = array_replace_recursive($default_settings, $site_settings); + +// Set settings +$registry->set('settings', $settings); + /** * Create new application */ -$app = new \Slim\App(['settings' => [ - 'debug' => $registry->get('settings.errors.display'), - 'whoops.editor' => $registry->get('settings.whoops.editor'), - 'whoops.page_title' => $registry->get('settings.whoops.page_title'), - 'displayErrorDetails' => $registry->get('settings.display_error_details'), - 'addContentLengthHeader' => $registry->get('settings.add_content_length_header'), - 'routerCacheFile' => $registry->get('settings.router_cache_file'), - 'determineRouteBeforeAppMiddleware' => $registry->get('settings.determine_route_before_app_middleware'), - 'outputBuffering' => $registry->get('settings.output_buffering'), - 'responseChunkSize' => $registry->get('settings.response_chunk_size'), - 'httpVersion' => $registry->get('settings.http_version'), - 'twig' => [ - 'debug' => $registry->get('settings.errors.display'), - 'cache' => PATH['cache'] . '/twig', - 'auto_reload' => $registry->get('settings.twig.auto_reload'), - ], - 'images' => [ - 'driver' => $registry->get('settings.image.driver'), - ] - ] - ]); +$app = new App([ + 'settings' => [ + 'debug' => $registry->get('settings.errors.display'), + 'whoops.editor' => $registry->get('settings.whoops.editor'), + 'whoops.page_title' => $registry->get('settings.whoops.page_title'), + 'displayErrorDetails' => $registry->get('settings.display_error_details'), + 'addContentLengthHeader' => $registry->get('settings.add_content_length_header'), + 'routerCacheFile' => $registry->get('settings.router_cache_file'), + 'determineRouteBeforeAppMiddleware' => $registry->get('settings.determine_route_before_app_middleware'), + 'outputBuffering' => $registry->get('settings.output_buffering'), + 'responseChunkSize' => $registry->get('settings.response_chunk_size'), + 'httpVersion' => $registry->get('settings.http_version'), + 'twig' => [ + 'debug' => $registry->get('settings.errors.display'), + 'cache' => PATH['cache'] . '/twig', + 'auto_reload' => $registry->get('settings.twig.auto_reload'), + ], + 'images' => [ + 'driver' => $registry->get('settings.image.driver'), + ], + ], +]); /** * Set Flextype Dependency Injection Container @@ -128,8 +139,7 @@ if ($flextype['registry']->get('settings.errors.display')) { /** * Add WhoopsMiddleware */ - $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware($app)); - + $app->add(new WhoopsMiddleware($app)); } else { error_reporting(0); } diff --git a/flextype/middlewares.php b/flextype/middlewares.php index 9a1cab8e..d1ce7ccf 100644 --- a/flextype/middlewares.php +++ b/flextype/middlewares.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,9 +11,8 @@ namespace Flextype; -use Psr7Middlewares\Middleware; -use Psr7Middlewares\Middleware\TrailingSlash; use Psr7Middlewares\Middleware\ResponseTime; +use Psr7Middlewares\Middleware\TrailingSlash; /** * Add middleware CSRF (cross-site request forgery) protection for all routes @@ -26,4 +24,7 @@ $app->add($flextype->get('csrf')); */ $app->add((new TrailingSlash(false))->redirect(301)); +/** + * Add middleware ResponseTime for all routes + */ $app->add((new ResponseTime())); diff --git a/flextype/parsers/JsonParser.php b/flextype/parsers/JsonParser.php index 9077a4fd..3bc72eaf 100644 --- a/flextype/parsers/JsonParser.php +++ b/flextype/parsers/JsonParser.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,9 +11,15 @@ namespace Flextype; +use RuntimeException; +use const JSON_PRETTY_PRINT; +use const JSON_UNESCAPED_SLASHES; +use const JSON_UNESCAPED_UNICODE; +use function json_decode; +use function json_encode; + class JsonParser { - /** * Encode options * @@ -67,22 +72,22 @@ class JsonParser * * $result = JsonParser::encode($json_content); * - * @param mixed $input A string containing JSON - * @param int $encode_depth User specified recursion depth. - * @param int $encode_options Bitmask consisting of encode options. - * @return mixed The JSON converted to a PHP value + * @param mixed $input A string containing JSON + * @param int $encode_depth User specified recursion depth. + * @param int $encode_options Bitmask consisting of encode options. * + * @return mixed The JSON converted to a PHP value */ public static function encode($input, int $encode_options = 0, int $encode_depth = 512) : string { $encoded = @json_encode( $input, - $encode_options ? $encode_options : JsonParser::$encode_options, - $encode_depth ? $encode_depth : JsonParser::$encode_depth - ); + $encode_options ? $encode_options : self::$encode_options, + $encode_depth ? $encode_depth : self::$encode_depth + ); if ($encoded === false) { - throw new \RuntimeException('Encoding JSON failed'); + throw new RuntimeException('Encoding JSON failed'); } return $encoded; @@ -93,10 +98,11 @@ class JsonParser * * $array = JsonParser::decode($json_file_content); * - * @param string $input A string containing JSON - * @param bool $decode_assoc When TRUE, returned objects will be converted into associative arrays. - * @param int $decode_depth User specified recursion depth. - * @param int $decode_options Bitmask consisting of decode options. + * @param string $input A string containing JSON + * @param bool $decode_assoc When TRUE, returned objects will be converted into associative arrays. + * @param int $decode_depth User specified recursion depth. + * @param int $decode_options Bitmask consisting of decode options. + * * @return mixed The JSON converted to a PHP value * * @throws ParseException If the JSON is not valid @@ -105,13 +111,13 @@ class JsonParser { $decoded = @json_decode( $input, - $decode_assoc ? $decode_assoc : JsonParser::$decode_assoc, - $decode_depth ? $decode_depth : JsonParser::$decode_depth, - $decode_options ? $decode_options : JsonParser::$decode_options - ); + $decode_assoc ? $decode_assoc : self::$decode_assoc, + $decode_depth ? $decode_depth : self::$decode_depth, + $decode_options ? $decode_options : self::$decode_options + ); if ($decoded === false) { - throw new \RuntimeException('Decoding JSON failed'); + throw new RuntimeException('Decoding JSON failed'); } return $decoded; diff --git a/flextype/routes/web.php b/flextype/routes/web.php index 112bd494..f303c04c 100644 --- a/flextype/routes/web.php +++ b/flextype/routes/web.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -18,6 +17,6 @@ use Psr\Http\Message\ServerRequestInterface as Request; /** * Generates and returns the image response */ -$app->get('/image/{path:.+}', function (Request $request, Response $response, array $args) use ($flextype) { +$app->get('/image/{path:.+}', static function (Request $request, Response $response, array $args) use ($flextype) { return $flextype['images']->getImageResponse($args['path'], $_GET); }); diff --git a/flextype/twig/AssetsTwigExtension.php b/flextype/twig/AssetsTwigExtension.php index 526078fc..bd7dea10 100644 --- a/flextype/twig/AssetsTwigExtension.php +++ b/flextype/twig/AssetsTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -13,8 +12,10 @@ namespace Flextype; use Flextype\Component\Assets\Assets; +use Twig_Extension; +use Twig_Extension_GlobalsInterface; -class AssetsTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +class AssetsTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { /** * Register Global variables in an extension @@ -22,7 +23,7 @@ class AssetsTwigExtension extends \Twig_Extension implements \Twig_Extension_Glo public function getGlobals() { return [ - 'assets' => new AssetsTwig() + 'assets' => new AssetsTwig(), ]; } } diff --git a/flextype/twig/CsrfTwigExtension.php b/flextype/twig/CsrfTwigExtension.php index 99984041..616c9dc7 100644 --- a/flextype/twig/CsrfTwigExtension.php +++ b/flextype/twig/CsrfTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,18 +11,20 @@ namespace Flextype; -class CsrfTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface -{ +use Slim\Csrf\Guard; +use Twig_Extension; +use Twig_Extension_GlobalsInterface; +use Twig_SimpleFunction; - /** - * @var \Slim\Csrf\Guard - */ +class CsrfTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface +{ + /** @var Guard */ protected $csrf; /** * Constructor */ - public function __construct(\Slim\Csrf\Guard $csrf) + public function __construct(Guard $csrf) { $this->csrf = $csrf; } @@ -34,20 +35,20 @@ class CsrfTwigExtension extends \Twig_Extension implements \Twig_Extension_Globa public function getGlobals() { // CSRF token name and value - $csrfNameKey = $this->csrf->getTokenNameKey(); + $csrfNameKey = $this->csrf->getTokenNameKey(); $csrfValueKey = $this->csrf->getTokenValueKey(); - $csrfName = $this->csrf->getTokenName(); - $csrfValue = $this->csrf->getTokenValue(); + $csrfName = $this->csrf->getTokenName(); + $csrfValue = $this->csrf->getTokenValue(); return [ 'csrf' => [ 'keys' => [ 'name' => $csrfNameKey, - 'value' => $csrfValueKey + 'value' => $csrfValueKey, ], 'name' => $csrfName, - 'value' => $csrfValue - ] + 'value' => $csrfValue, + ], ]; } @@ -61,21 +62,19 @@ class CsrfTwigExtension extends \Twig_Extension implements \Twig_Extension_Globa * * @return array */ - public function getFunctions() + public function getFunctions() : array { return [ - new \Twig_SimpleFunction('csrf', [$this, 'csrf'], ['is_safe' => ['html']]), + new Twig_SimpleFunction('csrf', [$this, 'csrf'], ['is_safe' => ['html']]), ]; } /** * CSRF - * - * @return string */ - public function csrf() + public function csrf() : string { - return ''. - ''; + return '' . + ''; } } diff --git a/flextype/twig/EmitterTwigExtension.php b/flextype/twig/EmitterTwigExtension.php index 92e985db..b0c43125 100644 --- a/flextype/twig/EmitterTwigExtension.php +++ b/flextype/twig/EmitterTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,7 +11,10 @@ namespace Flextype; -class EmitterTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +use Twig_Extension; +use Twig_Extension_GlobalsInterface; + +class EmitterTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { /** * Flextype Dependency Container @@ -33,7 +35,7 @@ class EmitterTwigExtension extends \Twig_Extension implements \Twig_Extension_Gl public function getGlobals() { return [ - 'emmiter' => new EmitterTwig($this->flextype) + 'emmiter' => new EmitterTwig($this->flextype), ]; } } diff --git a/flextype/twig/EntriesTwigExtension.php b/flextype/twig/EntriesTwigExtension.php index 53471335..5a1f1f39 100644 --- a/flextype/twig/EntriesTwigExtension.php +++ b/flextype/twig/EntriesTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,7 +11,10 @@ namespace Flextype; -class EntriesTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +use Twig_Extension; +use Twig_Extension_GlobalsInterface; + +class EntriesTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { /** * Flextype Dependency Container @@ -33,7 +35,7 @@ class EntriesTwigExtension extends \Twig_Extension implements \Twig_Extension_Gl public function getGlobals() { return [ - 'entries' => new EntriesTwig($this->flextype) + 'entries' => new EntriesTwig($this->flextype), ]; } } diff --git a/flextype/twig/FilesystemTwigExtension.php b/flextype/twig/FilesystemTwigExtension.php index c83c2931..3cfad2d0 100644 --- a/flextype/twig/FilesystemTwigExtension.php +++ b/flextype/twig/FilesystemTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -13,22 +12,27 @@ namespace Flextype; use Flextype\Component\Filesystem\Filesystem; +use Twig_Extension; +use Twig_SimpleFunction; +use function basename; +use function strrchr; +use function substr; -class FilesystemTwigExtension extends \Twig_Extension +class FilesystemTwigExtension extends Twig_Extension { /** * Callback for twig. * * @return array */ - public function getFunctions() + public function getFunctions() : array { return [ - new \Twig_SimpleFunction('filesystem_list_contents', [$this, 'list_contents']), - new \Twig_SimpleFunction('filesystem_has', [$this, 'has']), - new \Twig_SimpleFunction('filesystem_read', [$this, 'read']), - new \Twig_SimpleFunction('filesystem_ext', [$this, 'ext']), - new \Twig_SimpleFunction('filesystem_basename', [$this, 'basename']), + new Twig_SimpleFunction('filesystem_list_contents', [$this, 'list_contents']), + new Twig_SimpleFunction('filesystem_has', [$this, 'has']), + new Twig_SimpleFunction('filesystem_read', [$this, 'read']), + new Twig_SimpleFunction('filesystem_ext', [$this, 'ext']), + new Twig_SimpleFunction('filesystem_basename', [$this, 'basename']), ]; } diff --git a/flextype/twig/FlashTwigExtension.php b/flextype/twig/FlashTwigExtension.php index f60b0973..2d5d3eb1 100644 --- a/flextype/twig/FlashTwigExtension.php +++ b/flextype/twig/FlashTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,9 +11,10 @@ namespace Flextype; -use Slim\Flash\Messages; +use Twig_Extension; +use Twig_SimpleFunction; -class FlashTwigExtension extends \Twig_Extension +class FlashTwigExtension extends Twig_Extension { /** * Flextype Dependency Container @@ -37,7 +37,7 @@ class FlashTwigExtension extends \Twig_Extension public function getFunctions() : array { return [ - new \Twig_SimpleFunction('flash', [$this, 'getMessages']), + new Twig_SimpleFunction('flash', [$this, 'getMessages']), ]; } @@ -45,12 +45,11 @@ class FlashTwigExtension extends \Twig_Extension * Returns Flash messages; If key is provided then returns messages * for that key. * - * @param string $key * @return array */ - public function getMessages($key = null) : array + public function getMessages(?string $key = null) : array { - if (null !== $key) { + if ($key !== null) { return $this->flextype['flash']->getMessage($key); } diff --git a/flextype/twig/GlobalVarsTwigExtension.php b/flextype/twig/GlobalVarsTwigExtension.php index 0a341f2f..3caa0cff 100644 --- a/flextype/twig/GlobalVarsTwigExtension.php +++ b/flextype/twig/GlobalVarsTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,7 +11,11 @@ namespace Flextype; -class GlobalVarsTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +use Twig_Extension; +use Twig_Extension_GlobalsInterface; +use const PHP_VERSION; + +class GlobalVarsTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { /** * Flextype Dependency Container @@ -44,7 +47,7 @@ class GlobalVarsTwigExtension extends \Twig_Extension implements \Twig_Extension 'PATH_CACHE' => PATH['cache'], 'FLEXTYPE_VERSION' => FLEXTYPE_VERSION, 'PHP_VERSION' => PHP_VERSION, - 'registry' => $this->flextype['registry']->dump() + 'registry' => $this->flextype['registry']->dump(), ]; } } diff --git a/flextype/twig/I18nTwigExtension.php b/flextype/twig/I18nTwigExtension.php index ee394944..bbe66c57 100644 --- a/flextype/twig/I18nTwigExtension.php +++ b/flextype/twig/I18nTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -13,25 +12,27 @@ namespace Flextype; use Flextype\Component\I18n\I18n; +use Twig_Extension; +use Twig_SimpleFunction; -class I18nTwigExtension extends \Twig_Extension +class I18nTwigExtension extends Twig_Extension { /** * Returns a list of functions to add to the existing list. * * @return array */ - public function getFunctions() + public function getFunctions() : array { return [ - new \Twig_SimpleFunction('tr', [$this, 'tr']), + new Twig_SimpleFunction('tr', [$this, 'tr']), ]; } /** * Translate string */ - public function tr(string $translate, string $locale = null, array $values = []) : string + public function tr(string $translate, ?string $locale = null, array $values = []) : string { return I18n::find($translate, $locale, $values); } diff --git a/flextype/twig/JsonParserTwigExtension.php b/flextype/twig/JsonParserTwigExtension.php index 27449f59..484c0479 100644 --- a/flextype/twig/JsonParserTwigExtension.php +++ b/flextype/twig/JsonParserTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,18 +11,21 @@ namespace Flextype; -class JsonParserTwigExtension extends \Twig_Extension +use Twig_Extension; +use Twig_SimpleFunction; + +class JsonParserTwigExtension extends Twig_Extension { /** * Returns a list of functions to add to the existing list. * * @return array */ - public function getFunctions() + public function getFunctions() : array { return [ - new \Twig_SimpleFunction('json_parser_decode', [$this, 'decode']), - new \Twig_SimpleFunction('json_parser_encode', [$this, 'encode']) + new Twig_SimpleFunction('json_parser_decode', [$this, 'decode']), + new Twig_SimpleFunction('json_parser_encode', [$this, 'encode']), ]; } diff --git a/flextype/twig/ShortcodesTwigExtension.php b/flextype/twig/ShortcodesTwigExtension.php index b2d3c099..f8651fbc 100644 --- a/flextype/twig/ShortcodesTwigExtension.php +++ b/flextype/twig/ShortcodesTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,9 +11,11 @@ namespace Flextype; -class ShortcodesTwigExtension extends \Twig_Extension -{ +use Twig_Extension; +use Twig_SimpleFilter; +class ShortcodesTwigExtension extends Twig_Extension +{ /** * Flextype Dependency Container */ @@ -33,10 +34,10 @@ class ShortcodesTwigExtension extends \Twig_Extension * * @return array */ - public function getFilters() + public function getFilters() : array { return [ - new \Twig_SimpleFilter('shortcode', [$this, 'shortcode']), + new Twig_SimpleFilter('shortcode', [$this, 'shortcode']), ]; } diff --git a/flextype/twig/SnippetsTwigExtension.php b/flextype/twig/SnippetsTwigExtension.php index 0e27890b..21d6e20c 100644 --- a/flextype/twig/SnippetsTwigExtension.php +++ b/flextype/twig/SnippetsTwigExtension.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,7 +11,10 @@ namespace Flextype; -class SnippetsTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +use Twig_Extension; +use Twig_Extension_GlobalsInterface; + +class SnippetsTwigExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface { /** * Flextype Dependency Container @@ -33,7 +35,7 @@ class SnippetsTwigExtension extends \Twig_Extension implements \Twig_Extension_G public function getGlobals() { return [ - 'snippets' => new SnippetsTwig($this->flextype) + 'snippets' => new SnippetsTwig($this->flextype), ]; } } diff --git a/index.php b/index.php index 5b3e062a..2120b783 100755 --- a/index.php +++ b/index.php @@ -1,9 +1,8 @@ * @link http://romanenko.digital * * For the full copyright and license information, please view the LICENSE @@ -12,6 +11,15 @@ namespace Flextype; +use const DIRECTORY_SEPARATOR; +use const PHP_VERSION; +use function define; +use function getcwd; +use function is_file; +use function sprintf; +use function str_replace; +use function version_compare; + /** * Define the application minimum supported PHP version. */ @@ -25,17 +33,19 @@ define('ROOT_DIR', str_replace(DIRECTORY_SEPARATOR, '/', getcwd())); /** * Define the PATH (without trailing slash). */ -define('PATH', ['site' => ROOT_DIR . '/site', - 'plugins' => ROOT_DIR . '/site/plugins', - 'themes' => ROOT_DIR . '/site/themes', - 'entries' => ROOT_DIR . '/site/entries', - 'snippets' => ROOT_DIR . '/site/snippets', - 'fieldsets' => ROOT_DIR . '/site/fieldsets', - 'config' => [ - 'default' => ROOT_DIR . '/flextype/config', - 'site' => ROOT_DIR . '/site/config' - ], - 'cache' => ROOT_DIR . '/site/cache']); +define('PATH', [ + 'site' => ROOT_DIR . '/site', + 'plugins' => ROOT_DIR . '/site/plugins', + 'themes' => ROOT_DIR . '/site/themes', + 'entries' => ROOT_DIR . '/site/entries', + 'snippets' => ROOT_DIR . '/site/snippets', + 'fieldsets' => ROOT_DIR . '/site/fieldsets', + 'config' => [ + 'default' => ROOT_DIR . '/flextype/config', + 'site' => ROOT_DIR . '/site/config', + ], + 'cache' => ROOT_DIR . '/site/cache', +]); /** * Check PHP Version @@ -45,7 +55,7 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s /** * Ensure vendor libraries exist */ -!is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: composer install"); +! is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: composer install'); /** * Register The Auto Loader