diff --git a/bin/console b/bin/console index 5addc4fd..7e907f2f 100755 --- a/bin/console +++ b/bin/console @@ -55,7 +55,7 @@ try { $app = (new App\Libs\Initializer())->boot(); } catch (Throwable $e) { $message = sprintf( - 'Unhandled Exception [%s] was thrown. With message [%s] in [%s:%d].', + 'Unhandled Exception [%s] was thrown in CLI boot context. With message [%s] in [%s:%d].', $e::class, $e->getMessage(), array_reverse(explode(ROOT_PATH, $e->getFile(), 2))[0], diff --git a/container/files/init-container.sh b/container/files/init-container.sh index 60104de7..e05db96a 100755 --- a/container/files/init-container.sh +++ b/container/files/init-container.sh @@ -55,7 +55,7 @@ if [ 0 = "${WS_DISABLE_HTTP}" ]; then caddy start --config /opt/config/Caddyfile fi -echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Caching tool Routes." +echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Caching tool routes." /opt/bin/console system:routes echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Running database migrations." @@ -64,7 +64,7 @@ echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Running database migrations." echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Running database maintenance tasks." /opt/bin/console system:db:maintenance -echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Ensuring State table has correct indexes." +echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Ensuring state table has correct indexes." /opt/bin/console system:index if [ 0 = "${WS_DISABLE_CRON}" ]; then @@ -73,7 +73,7 @@ if [ 0 = "${WS_DISABLE_CRON}" ]; then rm -f "/tmp/job-runner.pid" fi - echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Starting Tasks Scheduler." + echo "[$(date +"%Y-%m-%dT%H:%M:%S%z")] Starting tasks scheduler." /opt/bin/job-runner & fi diff --git a/public/index.php b/public/index.php index 5641b20a..89fe1ff6 100644 --- a/public/index.php +++ b/public/index.php @@ -47,7 +47,15 @@ try { } catch (Throwable $e) { fwrite( STDERR, - trim(sprintf("PANIC: %s: %s (%s:%d).", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())) + trim( + sprintf( + 'Unhandled Exception [%s] was thrown at HTTP boot context. With message [%s] in [%s:%d].', + $e::class, + $e->getMessage(), + array_reverse(explode(ROOT_PATH, $e->getFile(), 2))[0], + $e->getLine() + ) + ) ); if (!headers_sent()) { diff --git a/src/Command.php b/src/Command.php index bf2a8a54..fdb7ca04 100644 --- a/src/Command.php +++ b/src/Command.php @@ -171,42 +171,54 @@ class Command extends BaseCommand protected function displayContent(array $content, OutputInterface $output, string $mode = 'json'): void { - if ('json' === $mode) { - $output->writeln( - json_encode( - value: $content, - flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_IGNORE - ) - ); - } elseif ('table' === $mode) { - $list = []; + switch ($mode) { + case 'json': + $output->writeln( + json_encode( + value: $content, + flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_IGNORE + ) + ); + break; + case 'table': + $list = []; - foreach ($content as $_ => $item) { - if (false === is_array($item)) { - $item = [$_ => $item]; - } - - $subItem = []; - - foreach ($item as $key => $leaf) { - if (true === is_array($leaf)) { - continue; + foreach ($content as $_ => $item) { + if (false === is_array($item)) { + $item = [$_ => $item]; } - $subItem[$key] = $leaf; + + $subItem = []; + + foreach ($item as $key => $leaf) { + if (true === is_array($leaf)) { + continue; + } + $subItem[$key] = $leaf; + } + + $list[] = $subItem; + $list[] = new TableSeparator(); } - $list[] = $subItem; - $list[] = new TableSeparator(); - } - - if (!empty($list)) { - array_pop($list); - (new Table($output))->setStyle('box')->setHeaders( - array_map(fn($title) => is_string($title) ? ucfirst($title) : $title, array_keys($list[0])) - )->setRows($list)->render(); - } - } else { - $output->writeln(Yaml::dump($content, 8, 2)); + if (!empty($list)) { + array_pop($list); + (new Table($output)) + ->setStyle(name: 'box') + ->setHeaders( + array_map( + callback: fn($title) => is_string($title) ? ucfirst($title) : $title, + array: array_keys($list[0]) + ) + ) + ->setRows(rows: $list) + ->render(); + } + break; + case 'yaml': + default: + $output->writeln(Yaml::dump(input: $content, inline: 8, indent: 2)); + break; } } diff --git a/src/Libs/Guid.php b/src/Libs/Guid.php index 43519d25..7d73d3ac 100644 --- a/src/Libs/Guid.php +++ b/src/Libs/Guid.php @@ -61,9 +61,9 @@ final class Guid implements JsonSerializable, Stringable private static LoggerInterface|null $logger = null; /** - * Create List of db => external id list. + * Create list of db => external id list. * - * @param array $guids A Key/value pair of db => external id. For example, [ "guid_imdb" => "tt123456789" ] + * @param array $guids A key/value a pair of db => external id. For example, [ "guid_imdb" => "tt123456789" ] * @param array $context */ public function __construct(array $guids, array $context = []) @@ -135,7 +135,7 @@ final class Guid implements JsonSerializable, Stringable } /** - * Set Logger. + * Set logger. * * @param LoggerInterface $logger * @return void @@ -146,7 +146,7 @@ final class Guid implements JsonSerializable, Stringable } /** - * Get Supported External ids sources. + * Get supported external ids sources. * * @return array */ @@ -171,7 +171,7 @@ final class Guid implements JsonSerializable, Stringable /** * Validate id value against expected format. * - * @param string $db guid source + * @param string $db guid source. * @param string|int $id guid source id. * * @return bool @@ -238,7 +238,7 @@ final class Guid implements JsonSerializable, Stringable } /** - * Get Instance of logger. + * Get instance of logger. * * @return LoggerInterface */ diff --git a/src/Libs/Mappers/ImportInterface.php b/src/Libs/Mappers/ImportInterface.php index ce0ddeee..982df74e 100644 --- a/src/Libs/Mappers/ImportInterface.php +++ b/src/Libs/Mappers/ImportInterface.php @@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface; interface ImportInterface extends Countable { /** - * Initiate Mapper. + * Initiate mapper. * * @param array $options * @@ -31,7 +31,7 @@ interface ImportInterface extends Countable public function loadData(DateTimeInterface|null $date = null): self; /** - * Add Entity. it has to search for + * Add entity. it has to search for * existing entity, and if found update it. * * @param StateInterface $entity Refers to the item state from backend. @@ -42,7 +42,7 @@ interface ImportInterface extends Countable public function add(StateInterface $entity, array $opts = []): self; /** - * Get Entity. + * Get entity. * * @param StateInterface $entity * @@ -51,7 +51,7 @@ interface ImportInterface extends Countable public function get(StateInterface $entity): null|StateInterface; /** - * Remove Entity. + * Remove entity. * * @param StateInterface $entity * @@ -67,7 +67,7 @@ interface ImportInterface extends Countable public function commit(): mixed; /** - * Has Entity. + * Has entity. * * @param StateInterface $entity * @@ -76,7 +76,7 @@ interface ImportInterface extends Countable public function has(StateInterface $entity): bool; /** - * Reset Mapper State. + * Reset mapper state. * * @return ImportInterface */ @@ -99,7 +99,7 @@ interface ImportInterface extends Countable public function getObjectsCount(): int; /** - * Inject Logger. + * Inject logger. * * @param LoggerInterface $logger * @@ -130,14 +130,14 @@ interface ImportInterface extends Countable public function inTraceMode(): bool; /** - * Get List Of registered pointers. + * Get list of registered pointers. * * @return array */ public function getPointersList(): array; /** - * Get List of changed items that changed. + * Get list of changed items that changed. * * @return array */ diff --git a/src/Libs/Message.php b/src/Libs/Message.php index 8dcf75f3..7c604022 100644 --- a/src/Libs/Message.php +++ b/src/Libs/Message.php @@ -7,16 +7,15 @@ namespace App\Libs; /** * Volatile messaging between classes. * This should not be used for anything important. - * Data is mutable, and can be change by anything. - * Messages are not persistent and will be removed - * once the execution is done. + * Data is mutable, and can be changed by anything. + * Messages are not persistent and will be removed once the execution is done. */ final class Message { private static array $data = []; /** - * Add Message to Store. + * Add message to store. * * @param string $key Message key. * @param mixed $value value. diff --git a/src/Libs/QueueRequests.php b/src/Libs/QueueRequests.php index a109ce9e..8e0fb5cc 100644 --- a/src/Libs/QueueRequests.php +++ b/src/Libs/QueueRequests.php @@ -5,9 +5,10 @@ declare(strict_types=1); namespace App\Libs; use Countable; +use Iterator; use Symfony\Contracts\HttpClient\ResponseInterface; -final class QueueRequests implements Countable, \Iterator +final class QueueRequests implements Countable, Iterator { /** * @var array Queued Requests. diff --git a/src/Libs/Router.php b/src/Libs/Router.php index 744eacd8..290c5add 100644 --- a/src/Libs/Router.php +++ b/src/Libs/Router.php @@ -107,22 +107,22 @@ final class Router $count = count($tokens); foreach ($tokens as $i => $iValue) { - if ($iValue->getTokenName() === 'T_NAMESPACE') { + if ('T_NAMESPACE' === $iValue->getTokenName()) { for ($j = $i + 1; $j < $count; $j++) { - if ($tokens[$j]->getTokenName() === 'T_NAME_QUALIFIED') { + if ('T_NAME_QUALIFIED' === $tokens[$j]->getTokenName()) { $namespace = $tokens[$j]->text; break; } } } - if ($iValue->getTokenName() === 'T_CLASS') { + if ('T_CLASS' === $iValue->getTokenName()) { for ($j = $i + 1; $j < $count; $j++) { - if ($tokens[$j]->getTokenName() === 'T_WHITESPACE') { + if ('T_WHITESPACE' === $tokens[$j]->getTokenName()) { continue; } - if ($tokens[$j]->getTokenName() === 'T_STRING') { + if ('T_STRING' === $tokens[$j]->getTokenName()) { $classes[] = $namespace . '\\' . $tokens[$j]->text; } else { break;