From f8fea63c010f058c684ce8351d2109a8f2dd185a Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 21 Aug 2024 20:49:15 +0400 Subject: [PATCH] General cleanup --- helpers/functions.php | 11 ++-------- modules/.gitkeep | 1 + shared/Commands/DemoCommand.php | 23 +++++++++++++++++--- shared/Commands/PostCreateCommand.php | 4 ++++ shared/Commands/PostDeleteCommand.php | 4 ++++ shared/Commands/PostShowCommand.php | 4 ++++ shared/Commands/PostUpdateCommand.php | 4 ++++ shared/Commands/UserCreateCommand.php | 4 ++++ shared/Commands/UserShowCommand.php | 4 ++++ shared/Services/AuthService.php | 22 +++++++++++++++---- shared/Services/PostService.php | 31 ++++++++++++++++++++++++--- shared/config/cache.php | 2 +- shared/config/database.php | 14 ++++++------ shared/config/dependencies.php | 5 +++++ shared/config/mailer.php | 2 +- shared/config/modules.php | 2 +- shared/config/session.php | 5 +++++ 17 files changed, 113 insertions(+), 29 deletions(-) create mode 100644 modules/.gitkeep diff --git a/helpers/functions.php b/helpers/functions.php index 63026a6..aa3a568 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -13,6 +13,7 @@ */ use Quantum\Libraries\Storage\FileSystem; +use Quantum\Exceptions\LangException; use Quantum\Exceptions\DiException; use Quantum\Di\Di; @@ -20,6 +21,7 @@ * Gets the url with selected language * @param string $lang * @return string + * @throws LangException */ function url_with_lang(string $lang): string { @@ -76,12 +78,3 @@ function save_remote_image(string $imageUrl, string $userDirectory, string $imag return $imageName; } - -function getRecaptcha() -{ - if (env('RECAPTCHA_SITE_KEY_V2')) { - echo partial('partials/recaptchaVersions/recaptchaCheckbox'); - } elseif (env('RECAPTCHA_SITE_KEY_V3')) { - echo partial('partials/recaptchaVersions/recaptchaInvisibleV3'); - } -} \ No newline at end of file diff --git a/modules/.gitkeep b/modules/.gitkeep new file mode 100644 index 0000000..256c7f2 --- /dev/null +++ b/modules/.gitkeep @@ -0,0 +1 @@ +#qt diff --git a/shared/Commands/DemoCommand.php b/shared/Commands/DemoCommand.php index 9cffe84..e7e77e5 100644 --- a/shared/Commands/DemoCommand.php +++ b/shared/Commands/DemoCommand.php @@ -14,11 +14,14 @@ namespace Shared\Commands; +use Symfony\Component\Console\Exception\ExceptionInterface; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Input\ArrayInput; use Quantum\Libraries\Storage\FileSystem; use Quantum\Exceptions\DatabaseException; +use Quantum\Exceptions\ConfigException; use Bluemmb\Faker\PicsumPhotosProvider; +use Quantum\Exceptions\ModelException; use Quantum\Migration\MigrationTable; use Quantum\Factory\ServiceFactory; use Quantum\Exceptions\DiException; @@ -96,19 +99,23 @@ class DemoCommand extends QtCommand const DEFAULT_PASSWORD = 'password'; /** - * Command name of run migration + * Command name to run migrations */ const COMMAND_MIGRATE = 'migration:migrate'; /** - * Command name of create user + * Command name to create users */ const COMMAND_USER_CREATE = 'user:create'; /** - * Command name of create post + * Command name to create posts */ const COMMAND_POST_CREATE = 'post:create'; + + /** + * Command name to generate modules + */ const COMMAND_CREATE_MODULE = 'module:generate'; /** @@ -125,7 +132,13 @@ public function __construct() /** * Executes the command + * @throws DatabaseException * @throws DiException + * @throws ReflectionException + * @throws ConfigException + * @throws ModelException + * @throws Exception + * @throws ExceptionInterface */ public function exec() { @@ -175,6 +188,7 @@ public function exec() /** * Runs an external command * @throws Exception + * @throws ExceptionInterface */ protected function runExternalCommand($commandName, $arguments) { @@ -226,6 +240,9 @@ private function newPostData($user): array /** * Cleanups the database * @throws DatabaseException + * @throws DiException + * @throws ExceptionInterface + * @throws ReflectionException */ private function cleanUp() { diff --git a/shared/Commands/PostCreateCommand.php b/shared/Commands/PostCreateCommand.php index 87edab3..745e213 100644 --- a/shared/Commands/PostCreateCommand.php +++ b/shared/Commands/PostCreateCommand.php @@ -14,10 +14,12 @@ namespace Shared\Commands; +use Quantum\Exceptions\ServiceException; use Quantum\Exceptions\DiException; use Quantum\Factory\ServiceFactory; use Shared\Services\PostService; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class PostCreateCommand @@ -58,6 +60,8 @@ class PostCreateCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Commands/PostDeleteCommand.php b/shared/Commands/PostDeleteCommand.php index 155790b..2e3d570 100644 --- a/shared/Commands/PostDeleteCommand.php +++ b/shared/Commands/PostDeleteCommand.php @@ -14,10 +14,12 @@ namespace Shared\Commands; +use Quantum\Exceptions\ServiceException; use Quantum\Exceptions\DiException; use Quantum\Factory\ServiceFactory; use Shared\Services\PostService; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class PostDeleteCommand @@ -55,6 +57,8 @@ class PostDeleteCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Commands/PostShowCommand.php b/shared/Commands/PostShowCommand.php index 3956eb1..73d471c 100644 --- a/shared/Commands/PostShowCommand.php +++ b/shared/Commands/PostShowCommand.php @@ -15,10 +15,12 @@ namespace Shared\Commands; use Symfony\Component\Console\Helper\Table; +use Quantum\Exceptions\ServiceException; use Quantum\Exceptions\DiException; use Quantum\Factory\ServiceFactory; use Shared\Services\PostService; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class PostShowCommand @@ -56,6 +58,8 @@ class PostShowCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Commands/PostUpdateCommand.php b/shared/Commands/PostUpdateCommand.php index 7576f7b..e04587d 100644 --- a/shared/Commands/PostUpdateCommand.php +++ b/shared/Commands/PostUpdateCommand.php @@ -14,10 +14,12 @@ namespace Shared\Commands; +use Quantum\Exceptions\ServiceException; use Quantum\Exceptions\DiException; use Quantum\Factory\ServiceFactory; use Shared\Services\PostService; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class PostUpdateCommand @@ -65,6 +67,8 @@ class PostUpdateCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Commands/UserCreateCommand.php b/shared/Commands/UserCreateCommand.php index 90139fa..d8c96ce 100644 --- a/shared/Commands/UserCreateCommand.php +++ b/shared/Commands/UserCreateCommand.php @@ -15,6 +15,7 @@ namespace Shared\Commands; use Quantum\Libraries\Validation\Validator; +use Quantum\Exceptions\ServiceException; use Quantum\Libraries\Validation\Rule; use Quantum\Libraries\Hasher\Hasher; use Quantum\Exceptions\DiException; @@ -22,6 +23,7 @@ use Quantum\Factory\ModelFactory; use Shared\Services\AuthService; use Quantum\Console\QtCommand; +use ReflectionException; use Shared\Models\User; /** @@ -70,6 +72,8 @@ class UserCreateCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Commands/UserShowCommand.php b/shared/Commands/UserShowCommand.php index 275089a..4c18610 100644 --- a/shared/Commands/UserShowCommand.php +++ b/shared/Commands/UserShowCommand.php @@ -15,10 +15,12 @@ namespace Shared\Commands; use Symfony\Component\Console\Helper\Table; +use Quantum\Exceptions\ServiceException; use Quantum\Exceptions\DiException; use Quantum\Factory\ServiceFactory; use Shared\Services\AuthService; use Quantum\Console\QtCommand; +use ReflectionException; /** * Class UserShowCommand @@ -56,6 +58,8 @@ class UserShowCommand extends QtCommand /** * Executes the command * @throws DiException + * @throws ServiceException + * @throws ReflectionException */ public function exec() { diff --git a/shared/Services/AuthService.php b/shared/Services/AuthService.php index 207cb7c..03a38bc 100644 --- a/shared/Services/AuthService.php +++ b/shared/Services/AuthService.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.8.0 + * @since 2.9.0 */ namespace Shared\Services; @@ -96,10 +96,15 @@ public function userSchema(): array } /** - * Get + * Get * @param string $field - * @param mixed $value + * @param $value * @return AuthUser|null + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function get(string $field, $value): ?AuthUser { @@ -116,6 +121,11 @@ public function get(string $field, $value): ?AuthUser * Add user * @param array $data * @return AuthUser + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function add(array $data): AuthUser { @@ -137,6 +147,11 @@ public function add(array $data): AuthUser * @param string|null $value * @param array $data * @return AuthUser|null + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function update(string $field, ?string $value, array $data): ?AuthUser { @@ -162,7 +177,6 @@ public function deleteTable() /** * @param string $uuid - * @return void * @throws DiException * @throws ReflectionException */ diff --git a/shared/Services/PostService.php b/shared/Services/PostService.php index 65711fc..be40285 100644 --- a/shared/Services/PostService.php +++ b/shared/Services/PostService.php @@ -57,6 +57,11 @@ public function __init(PostTransformer $transformer) /** * Get posts * @return array + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function getPosts(): array { @@ -79,10 +84,15 @@ public function getPosts(): array } /** - * Get post + * Get post * @param string $uuid * @param bool $transformed * @return array|null + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function getPost(string $uuid, bool $transformed = true): ?array { @@ -110,9 +120,14 @@ public function getPost(string $uuid, bool $transformed = true): ?array } /** - * Get post + * Get post * @param int $userId - * @return ?array + * @return array|null + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function getMyPosts(int $userId): ?array { @@ -156,6 +171,11 @@ public function addPost(array $data): array * Update post * @param string $uuid * @param array $data + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function updatePost(string $uuid, array $data) { @@ -168,6 +188,11 @@ public function updatePost(string $uuid, array $data) * Deletes the post * @param string $uuid * @return bool + * @throws ConfigException + * @throws DatabaseException + * @throws DiException + * @throws ModelException + * @throws ReflectionException */ public function deletePost(string $uuid): bool { diff --git a/shared/config/cache.php b/shared/config/cache.php index 78e9957..71f7a37 100644 --- a/shared/config/cache.php +++ b/shared/config/cache.php @@ -3,7 +3,7 @@ return [ /** * --------------------------------------------------------- - * Current cache settings + * Cache settings * --------------------------------------------------------- * * Current configuration to use. diff --git a/shared/config/database.php b/shared/config/database.php index 0c1f53c..b1bd243 100644 --- a/shared/config/database.php +++ b/shared/config/database.php @@ -3,7 +3,7 @@ return [ /** * --------------------------------------------------------- - * Current database settings + * Database settings * --------------------------------------------------------- * * Current configuration to use. @@ -17,12 +17,12 @@ * * You can define as many database configurations as you want. * - * driver : mysql, pgsql, sqlite, sleekdb - * host : The database server (localhost) - * dbname : The database name - * username : Username of the database server - * password : Password of the database server - * charset : Default charset + * driver: mysql, pgsql, sqlite, sleekdb + * host: The database server (localhost) + * dbname: The database name + * username: Username of the database server + * password: Password of the database server + * charset: Default charset */ 'mysql' => [ 'driver' => env("DB_DRIVER", "mysql"), diff --git a/shared/config/dependencies.php b/shared/config/dependencies.php index 9417c10..2ca5c93 100644 --- a/shared/config/dependencies.php +++ b/shared/config/dependencies.php @@ -1,6 +1,11 @@ [ ] diff --git a/shared/config/session.php b/shared/config/session.php index 9fd9b59..d788c73 100644 --- a/shared/config/session.php +++ b/shared/config/session.php @@ -1,6 +1,11 @@ 'sessions', 'driver' => 'file', 'timeout' => 300,