diff --git a/composer.json b/composer.json index 5e34fe5..fe63b8d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "name": "arrayaccess/traydigita", "description": "Tray Digita System", - "version": "1.0.0", "type": "project", "license": "MIT", "authors": [ diff --git a/src/Bin.php b/src/Bin.php index 03ce0e4..b8bcb5a 100644 --- a/src/Bin.php +++ b/src/Bin.php @@ -14,6 +14,7 @@ use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use ReflectionClass; +use Throwable; use function chdir; use function class_exists; use function define; @@ -35,10 +36,11 @@ use function realpath; use function strlen; use function substr; -use function var_dump; use const DIRECTORY_SEPARATOR; use const PHP_SAPI; use const PHP_VERSION; +use const PHP_VERSION_ID; +use const TD_APP_DIRECTORY; use const TD_ROOT_COMPOSER_DIR; final class Bin @@ -48,7 +50,12 @@ final private function __construct() { } - /** @noinspection PhpMissingReturnTypeInspection */ + /** + * @noinspection PhpMissingReturnTypeInspection + * @noinspection PhpIssetCanBeReplacedWithCoalesceInspection + * @noinspection DuplicatedCode + * @throws Throwable + */ final public static function run() { static $run = false; @@ -66,7 +73,7 @@ final public static function run() exit(255); } - if (\PHP_VERSION_ID < 80200) { + if (PHP_VERSION_ID < 80200) { echo "\n\033[0;31mPhp version is not meet requirements.\033[0m\n"; printf( "\033[0;34mMinimum required php version is:\033[0m \033[0;33m%s\033[0m\n", @@ -94,14 +101,15 @@ final public static function run() if (class_exists(ClassLoader::class)) { $classLoaderExists = true; + $exists = false; $ref = new ReflectionClass(ClassLoader::class); - $vendor ??= dirname($ref->getFileName(), 2); + $vendor = $vendor?:dirname($ref->getFileName(), 2); $v = $vendor; $c = 3; do { $v = dirname($v); } while (--$c > 0 && !($exists = file_exists($v . '/composer.json'))); - $root = ($exists ?? false) ? $v : dirname($vendor); + $root = $exists ? $v : dirname($vendor); $vendor = substr($vendor, strlen($root) + 1); } else { $root = dirname(__DIR__); @@ -110,8 +118,8 @@ final public static function run() if (is_file($root . '/composer.json')) { $config = json_decode(file_get_contents($root . '/composer.json'), true); $config = is_array($config) ? $config : []; - $config = $config['config'] ?? []; - $vendorDir = $config['vendor-dir'] ?? null; + $config = isset($config['config']) ? $config['config'] : []; + $vendorDir = isset($config['vendor-dir']) ? $config['vendor-dir'] : null; if ($vendorDir && is_dir("$root/$vendorDir")) { $vendor = $vendorDir; } @@ -153,14 +161,14 @@ final public static function run() ); } - $appDir = $appDir ?? TD_ROOT_COMPOSER_DIR . DIRECTORY_SEPARATOR . 'app'; + $appDir = isset($appDir) ? $appDir : TD_ROOT_COMPOSER_DIR . DIRECTORY_SEPARATOR . 'app'; /*if (!is_dir($appDir)) { echo "\n\033[0;31mCould not detect application directory\033[0m\n"; echo "\n"; exit(255); }*/ define('TD_APP_DIRECTORY', $appDir); - } elseif (!is_string(\TD_APP_DIRECTORY)) { + } elseif (!is_string(TD_APP_DIRECTORY)) { echo "\n\033[0;31mConstant \033[0;0m`TD_APP_DIRECTORY`\033[0;31m is invalid\033[0m\n"; echo "\n"; exit(255); diff --git a/src/HttpKernel/Traits/HttpKernelServiceTrait.php b/src/HttpKernel/Traits/HttpKernelServiceTrait.php index 5286673..92b360b 100644 --- a/src/HttpKernel/Traits/HttpKernelServiceTrait.php +++ b/src/HttpKernel/Traits/HttpKernelServiceTrait.php @@ -429,7 +429,7 @@ private function internalLoadController( $kernel, $this, $router, - $route ?? null + $route ?? null ); } } @@ -516,7 +516,6 @@ private function internalLoadMiddleware( $kernel, $this ); - } finally { $manager?->dispatch( 'kernel.afterResolveMiddlewares', diff --git a/src/Web.php b/src/Web.php index 26ef7c5..4dc2c03 100644 --- a/src/Web.php +++ b/src/Web.php @@ -48,6 +48,7 @@ use function substr; use const DIRECTORY_SEPARATOR; use const PHP_SAPI; +use const PHP_VERSION_ID; use const TD_INDEX_FILE; // phpcs:disable PSR1.Files.SideEffects @@ -68,6 +69,8 @@ final private function __construct() /** * @return ResponseInterface|false * @noinspection PhpMissingReturnTypeInspection + * @noinspection PhpIssetCanBeReplacedWithCoalesceInspection + * @noinspection DuplicatedCode */ final public static function serve() { @@ -90,7 +93,7 @@ final public static function serve() // START INIT EXCEPTION LISTENER try { // PHP VERSION MUST BE 8.2 OR LATER - if (\PHP_VERSION_ID < 80200) { + if (PHP_VERSION_ID < 80200) { throw new RuntimeException( "Php version is not meet requirement. Minimum required php version is: 8.2" ); @@ -110,14 +113,15 @@ final public static function serve() if (class_exists(ClassLoader::class)) { $classLoaderExists = true; + $exists = false; $ref = new ReflectionClass(ClassLoader::class); - $vendor ??= dirname($ref->getFileName(), 2); + $vendor = $vendor?:dirname($ref->getFileName(), 2); $v = $vendor; $c = 3; do { $v = dirname($v); } while (--$c > 0 && !($exists = file_exists($v . '/composer.json'))); - $root = ($exists ?? false) ? $v : dirname($vendor); + $root = $exists ? $v : dirname($vendor); $vendor = substr($vendor, strlen($root) + 1); } else { $root = dirname(__DIR__); @@ -126,8 +130,8 @@ final public static function serve() if (is_file($root . '/composer.json')) { $config = json_decode(file_get_contents($root . '/composer.json'), true); $config = is_array($config) ? $config : []; - $config = $config['config'] ?? []; - $vendorDir = $config['vendor-dir'] ?? null; + $config = isset($config['config']) ? $config['config'] : []; + $vendorDir = isset($config['vendor-dir']) ? $config['vendor-dir'] : null; if ($vendorDir && is_dir("$root/$vendorDir")) { $vendor = $vendorDir; } @@ -142,8 +146,8 @@ final public static function serve() ); } + $publicFile = null; if (!defined('TD_INDEX_FILE')) { - $publicFile = null; if (isset($_SERVER['SCRIPT_FILENAME'])) { $publicFile = realpath($_SERVER['SCRIPT_FILENAME']); } @@ -164,7 +168,7 @@ final public static function serve() 'Public file does not exists!' ); } - $publicFile ??= realpath(TD_INDEX_FILE); + $publicFile = $publicFile ?: realpath(TD_INDEX_FILE); $publicDir = dirname($publicFile); // HANDLE CLI-SERVER if (php_sapi_name() === 'cli-server') {