diff --git a/.env.example b/.env.example index 07a4c407..75521268 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -DEVELOPMENT_ENVIRONMENT="dev" ################################################################################ ################# SERVER INFORMATION ------------------------- ################# ################################################################################ diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 7550d42c..c2407b21 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,10 +1,9 @@ -name: Lion-Test (CI Workflow) +name: Lion-Bundle (CI Workflow) on: push: branches: - - actions-sleon - - actions-saco + - main pull_request: branches: - main @@ -12,116 +11,83 @@ on: - cron: "15 0 * * *" jobs: - composer-validation: + build: runs-on: ubuntu-latest - name: Composer Validation - - steps: - - name: Check out the repository - uses: actions/checkout@v4 - - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer - - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.4' - extensions: mbstring, gd, zip - - - name: Composer Validate - run: composer validate --strict - - - name: Composer Check for vulnerabilities - run: composer audit --locked - - name: Composer Install - run: composer install - - - name: Composer Dump-Autoload - run: composer dump-autoload --optimize --strict-psr - - docker-validation: - runs-on: ubuntu-latest - name: Docker Validation + services: + mysql: + image: mysql + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + ports: + - 3306:3306 + env: + MYSQL_DATABASE: lion_database + MYSQL_ROOT_PASSWORD: lion + MYSQL_PASSWORD: lion + + redis: + image: redis + ports: + - 6379:6379 + + postgres: + image: postgres + ports: + - 5432:5432 + env: + POSTGRES_DB: lion_database + POSTGRES_USER: root + POSTGRES_PASSWORD: lion steps: - - name: Check out the repository + - name: Checkout repository uses: actions/checkout@v4 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Validate Docker Compose configuration - run: docker compose config - - code-analyze: - runs-on: ubuntu-latest - name: PHP Code Analyze - needs: - - composer-validation - - docker-validation - - steps: - - name: Check out the repository - uses: actions/checkout@v4 + - name: Install system dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y sudo nano zsh curl wget unzip + sudo apt-get install -y libpq-dev libpng-dev libzip-dev zlib1g-dev libonig-dev libevent-dev libssl-dev + sudo apt-get clean - - name: Set up PHP + - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.4' - extensions: mbstring, gd, zip - - - name: Composer Install - run: composer install - - - name: PHP CodeSnifer (Src) - run: php -d memory_limit=-1 vendor/bin/phpcs --standard=PSR12 src/ - - # - name: PHPStan (Src) - # run: php -d memory_limit=-1 vendor/bin/phpstan analyse --level max src - - tests: - runs-on: ubuntu-latest - name: PHP Tests - needs: code-analyze - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Tear down containers - run: docker compose down --volumes --remove-orphans - - - name: Stop running Docker containers (if any) + php-version: 8.4 + extensions: mbstring, gd, zip, pdo, pdo_mysql, pdo_pgsql, redis, xdebug + coverage: xdebug + ini-values: | + xdebug.mode=develop,coverage,debug + xdebug.start_with_request=yes + xdebug.log_level=0 + tools: composer + + - name: Setup NPM run: | - docker ps -q | xargs -r docker stop - docker ps -aq | xargs -r docker rm - - - name: Build the Docker image - run: docker build -t bundle-app . - - - name: Start services using Docker Compose + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + source /home/runner/.bashrc + nvm install 20 + npm install -g npm@11 + echo 'export NVM_DIR="$HOME/.nvm"' >> /home/runner/.bashrc + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /home/runner/.bashrc + echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> /home/runner/.bashrc + source /home/runner/.bashrc + + - name: Copy .env.example to .env run: | - docker compose -f docker-compose.yml up -d - env: - COMPOSE_PROJECT_NAME: test - - - name: Install Composer dependencies - run: docker exec bundle-app composer install + if [ -f .env.example ]; then + cp .env.example .env + else + echo ".env.example not found! Please make sure the file exists." + exit 1 + fi + + - name: Install php dependencies + run: composer install - - name: Run PHP Tests - run: docker exec bundle-app php vendor/bin/phpunit + - name: Run tests + run: php lion test diff --git a/Dockerfile b/Dockerfile index 61db3136..03ce0d0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,10 @@ USER lion SHELL ["/bin/bash", "--login", "-i", "-c"] # Install nvm, Node.js and npm +ENV NVM_DIR="/home/lion/.nvm" + +ENV PATH="$NVM_DIR/versions/node/v20/bin:$PATH" + RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \ && source /home/lion/.bashrc \ && nvm install 20 \ diff --git a/composer.json b/composer.json index 5aa883c2..85f77763 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "routes/middleware.php", "src/LionBundle/Helpers/Bundle/constants.php", "src/LionBundle/Helpers/Bundle/helpers.php", - "tests/Providers/NameRuleProvider.php" + "tests/Providers/NameProviderRule.php" ] }, "autoload-dev": { @@ -58,7 +58,7 @@ "lion/files": "^8.0", "lion/helpers": "^5.1", "lion/request": "^7.1", - "lion/route": "^12.0", + "lion/route": "^12.1", "lion/security": "^11.0", "monolog/monolog": "^3.3", "nesbot/carbon": "^3.8", @@ -71,7 +71,8 @@ "lion/test": "^3.1", "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^11.5", - "squizlabs/php_codesniffer": "^3.11" + "squizlabs/php_codesniffer": "^3.11", + "symfony/mailer": "^7.2" }, "suggest": { "ext-gd": "Required to use LionSpreadsheet.", diff --git a/lion b/lion index e43034c4..7b26b69a 100644 --- a/lion +++ b/lion @@ -22,8 +22,6 @@ use Lion\Files\Store; define('IS_INDEX', false); -define('DEVELOPMENT_ENVIRONMENT', 'dev' === env('DEVELOPMENT_ENVIRONMENT')); - /** * ----------------------------------------------------------------------------- * Register environment variable loader automatically diff --git a/npm b/npm index 8676c4d3..4a1418a4 100644 --- a/npm +++ b/npm @@ -22,8 +22,6 @@ use Lion\Files\Store; define('IS_INDEX', false); -define('DEVELOPMENT_ENVIRONMENT', 'dev' === env('DEVELOPMENT_ENVIRONMENT')); - /** * ----------------------------------------------------------------------------- * Register environment variable loader automatically diff --git a/routes/web.php b/routes/web.php index 8e323d98..afa078eb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,8 +6,6 @@ define('IS_INDEX', true); -define('DEVELOPMENT_ENVIRONMENT', 'dev' === env('DEVELOPMENT_ENVIRONMENT')); - /** * ----------------------------------------------------------------------------- * Register The Auto Loader @@ -27,7 +25,6 @@ use Lion\Bundle\Helpers\Http\Routes; use Lion\Database\Driver; use Lion\Files\Store; -use Lion\Mailer\Mailer; use Tests\Providers\ExampleProvider; /** @@ -57,7 +54,7 @@ 'port' => env('DB_PORT'), 'dbname' => env('DB_NAME'), 'user' => env('DB_USER'), - 'password' => env('DB_PASSWORD') + 'password' => env('DB_PASSWORD'), ], env('DB_NAME_TEST') => [ 'type' => env('DB_TYPE_TEST'), @@ -65,9 +62,9 @@ 'port' => env('DB_PORT_TEST'), 'dbname' => env('DB_NAME'), 'user' => env('DB_USER_TEST'), - 'password' => env('DB_PASSWORD_TEST') - ] - ] + 'password' => env('DB_PASSWORD_TEST'), + ], + ], ]); /** diff --git a/src/LionBundle/Commands/Lion/DB/CrudCommand.php b/src/LionBundle/Commands/Lion/DB/CrudCommand.php index aedbb5d7..1c42eac3 100644 --- a/src/LionBundle/Commands/Lion/DB/CrudCommand.php +++ b/src/LionBundle/Commands/Lion/DB/CrudCommand.php @@ -258,7 +258,9 @@ private function addControllerAndModel( ], 20 => [ 'replace' => true, - 'content' => "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]', + 'content' => ( + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]' + ), 'search' => '*' ], 25 => [ @@ -273,7 +275,9 @@ private function addControllerAndModel( ], 44 => [ 'replace' => true, - 'content' => "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]', + 'content' => ( + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]' + ), 'search' => '*' ], 50 => [ @@ -288,7 +292,9 @@ private function addControllerAndModel( ], 57 => [ 'replace' => true, - 'content' => "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]', + 'content' => ( + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . ' [Parameter Description]' + ), 'search' => '*' ], 63 => [ @@ -317,7 +323,8 @@ private function addControllerAndModel( foreach ($gettersCallModel as $keyGetterCallModel => $method) { foreach ($method as $name) { $listGettersCallModel[$keyGetterCallModel] .= $this->str - ->lt()->lt()->lt()->concat('$')->concat(lcfirst($entityPascal))->concat("->{$name}()")->concat(',') + ->lt()->lt()->lt() + ->concat('$')->concat(lcfirst($entityPascal))->concat("->{$name}()")->concat(',') ->ln() ->get(); } @@ -331,8 +338,8 @@ private function addControllerAndModel( 20 => [ 'replace' => true, 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), 'search' => '*', ], @@ -362,8 +369,8 @@ private function addControllerAndModel( 43 => [ 'replace' => true, 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), 'search' => '*', ], @@ -388,8 +395,8 @@ private function addControllerAndModel( 54 => [ 'replace' => true, 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), 'search' => '*', ], @@ -429,8 +436,8 @@ private function addControllerAndModel( 'replace' => true, 'search' => '*', 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), ], 23 => [ @@ -462,8 +469,8 @@ private function addControllerAndModel( 43 => [ 'replace' => true, 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), 'search' => '*', ], @@ -488,8 +495,8 @@ private function addControllerAndModel( 54 => [ 'replace' => true, 'content' => ( - "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . " [Parameter Description]\n" . - "\t *" + "*\n\t * @param {$entityPascal} " . '$' . lcfirst($entityPascal) . + " [Parameter Description]\n\t *" ), 'search' => '*', ], @@ -526,6 +533,8 @@ private function addControllerAndModel( * implemented by all Output classes] * * @return void + * + * @throws ExceptionInterface */ private function addCapsule( string $driver, @@ -590,7 +599,7 @@ private function generateCallGettersModel(string $entityPascal, array $columns): } } - foreach ($columns as $key => $column) { + foreach ($columns as $column) { if ('PRI' === $column->Key) { $methods['update'] = [ ...$this->arr->of($methods['update'])->where(fn ($value, $key) => $key != 0)->get(), diff --git a/src/LionBundle/Commands/Lion/Migrations/FreshMigrationsCommand.php b/src/LionBundle/Commands/Lion/Migrations/FreshMigrationsCommand.php index a5ad1cce..deab9d2e 100644 --- a/src/LionBundle/Commands/Lion/Migrations/FreshMigrationsCommand.php +++ b/src/LionBundle/Commands/Lion/Migrations/FreshMigrationsCommand.php @@ -83,10 +83,10 @@ protected function configure(): void * @param OutputInterface $output [OutputInterface is the interface * implemented by all Output classes] * - * @return int [0 if everything went fine, or an exit code] + * @return int * - * @throws LogicException [When this abstract method is not implemented] * @throws ExceptionInterface + * @throws LogicException [When this abstract method is not implemented] */ protected function execute(InputInterface $input, OutputInterface $output): int { @@ -109,7 +109,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::INVALID; } - $this->migrations->executeMigrations($this, $output, $this->migrations->orderList($migrations[TableInterface::class])); + $this->migrations->executeMigrations( + $this, + $output, + $this->migrations->orderList($migrations[TableInterface::class]) + ); $this->migrations->executeMigrations($this, $output, $migrations[ViewInterface::class]); diff --git a/src/LionBundle/Commands/Lion/New/CommandsCommand.php b/src/LionBundle/Commands/Lion/New/CommandsCommand.php index fc25b596..8a56beda 100644 --- a/src/LionBundle/Commands/Lion/New/CommandsCommand.php +++ b/src/LionBundle/Commands/Lion/New/CommandsCommand.php @@ -200,7 +200,9 @@ protected function execute(InputInterface \$input, OutputInterface \$output): in $output->writeln($this->warningOutput("\t>> COMMAND: {$class}")); - $output->writeln($this->successOutput("\t>> COMMAND: the '{$namespace}\\{$class}' command has been generated")); + $output->writeln( + $this->successOutput("\t>> COMMAND: the '{$namespace}\\{$class}' command has been generated") + ); return Command::SUCCESS; } diff --git a/src/LionBundle/Commands/Lion/New/ControllerCommand.php b/src/LionBundle/Commands/Lion/New/ControllerCommand.php index be85eb36..3ad3f22e 100644 --- a/src/LionBundle/Commands/Lion/New/ControllerCommand.php +++ b/src/LionBundle/Commands/Lion/New/ControllerCommand.php @@ -248,7 +248,8 @@ class {$dataController->class} $output->writeln( $this->successOutput( - "\t>> CONTROLLER: the '{$dataController->namespace}\\{$dataController->class}' controller has been generated" + "\t>> CONTROLLER: the '{$dataController->namespace}\\{$dataController->class}' " . + 'controller has been generated' ) ); diff --git a/src/LionBundle/Commands/Lion/New/InterfaceCommand.php b/src/LionBundle/Commands/Lion/New/InterfaceCommand.php index ed9d2b8c..2518c986 100644 --- a/src/LionBundle/Commands/Lion/New/InterfaceCommand.php +++ b/src/LionBundle/Commands/Lion/New/InterfaceCommand.php @@ -58,13 +58,13 @@ public function setStore(Store $store): InterfaceCommand * * @return void */ - protected function configure(): void - { - $this + protected function configure(): void + { + $this ->setName('new:interface') ->setDescription('Command required for interface creation') ->addArgument('interface', InputArgument::OPTIONAL, 'Interface name', 'ExampleInterface'); - } + } /** * Executes the current command @@ -83,8 +83,8 @@ protected function configure(): void * * @throws LogicException [When this abstract method is not implemented] */ - protected function execute(InputInterface $input, OutputInterface $output): int - { + protected function execute(InputInterface $input, OutputInterface $output): int + { $interface = $input->getArgument('interface'); $this->classFactory->classFactory('app/Interfaces/', $interface); @@ -129,5 +129,5 @@ interface {$class} ); return Command::SUCCESS; - } + } } diff --git a/src/LionBundle/Commands/Lion/New/MigrationCommand.php b/src/LionBundle/Commands/Lion/New/MigrationCommand.php index da8d8d84..86300411 100644 --- a/src/LionBundle/Commands/Lion/New/MigrationCommand.php +++ b/src/LionBundle/Commands/Lion/New/MigrationCommand.php @@ -143,7 +143,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $migration = $input->getArgument('migration'); - if (str->of($migration)->test("/.*\//")) { + if (STR->of($migration)->test("/.*\//")) { $output->writeln($this->errorOutput("\t>> migration cannot be inside subfolders")); return Command::INVALID; @@ -177,7 +177,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln( $this->successOutput( - "\t>> MIGRATION: the '{$this->classFactory->getNamespace()}\\{$this->classFactory->getClass()}' migration has been generated" + "\t>> MIGRATION: the '{$this->classFactory->getNamespace()}\\{$this->classFactory->getClass()}' " . + 'migration has been generated' ) ); diff --git a/src/LionBundle/Commands/Lion/New/ModelCommand.php b/src/LionBundle/Commands/Lion/New/ModelCommand.php index fbabd53f..eada0ff2 100644 --- a/src/LionBundle/Commands/Lion/New/ModelCommand.php +++ b/src/LionBundle/Commands/Lion/New/ModelCommand.php @@ -156,7 +156,11 @@ class {$class} $this->str->of($method . $class)->replace('Model', '')->replace('model', '')->concat('DB')->get(), $method === 'read' ? 'stdClass|array|DatabaseCapsuleInterface' : 'stdClass', '', - $method === 'read' ? "return DB::table('')\n\t\t\t->select()\n\t\t\t->getAll();" : "return DB::call('', [])\n\t\t\t->execute();", + ( + $method === 'read' + ? "return DB::table('')\n\t\t\t->select()\n\t\t\t->getAll();" + : "return DB::call('', [])\n\t\t\t->execute();" + ), 'public', $method === 'delete' ? 1 : 2 ); diff --git a/src/LionBundle/Commands/Lion/New/RSACommand.php b/src/LionBundle/Commands/Lion/New/RSACommand.php index d9eaaec9..477df117 100644 --- a/src/LionBundle/Commands/Lion/New/RSACommand.php +++ b/src/LionBundle/Commands/Lion/New/RSACommand.php @@ -59,13 +59,13 @@ public function setStore(Store $store): RSACommand * * @return void */ - protected function configure(): void - { - $this + protected function configure(): void + { + $this ->setName('new:rsa') ->setDescription('Command required to create public and private keys for RSA encryptions') ->addOption('path', 'p', InputOption::VALUE_REQUIRED, 'Save to a specific path?'); - } + } /** * Executes the current command @@ -80,13 +80,13 @@ protected function configure(): void * @param OutputInterface $output [OutputInterface is the interface * implemented by all Output classes] * - * @return int [0 if everything went fine, or an exit code] + * @return int * * @throws Exception * @throws LogicException [When this abstract method is not implemented] */ - protected function execute(InputInterface $input, OutputInterface $output): int - { + protected function execute(InputInterface $input, OutputInterface $output): int + { $path = $input->getOption('path'); $this->rsa->config([ @@ -106,6 +106,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($this->successOutput("\t>> RSA KEYS: Exported in {$this->rsa->getUrlPath()}private.key")); - return Command::SUCCESS; - } + return Command::SUCCESS; + } } diff --git a/src/LionBundle/Commands/Lion/New/SHFileCommand.php b/src/LionBundle/Commands/Lion/New/SHFileCommand.php index daf60b4d..885ffd8d 100644 --- a/src/LionBundle/Commands/Lion/New/SHFileCommand.php +++ b/src/LionBundle/Commands/Lion/New/SHFileCommand.php @@ -8,6 +8,7 @@ use Lion\Bundle\Helpers\Commands\ClassFactory; use Lion\Command\Command; use Lion\Files\Store; +use LogicException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -57,13 +58,13 @@ public function setStore(Store $store): SHFileCommand * * @return void */ - protected function configure(): void - { - $this + protected function configure(): void + { + $this ->setName('new:sh') ->setDescription('Command required to create files with sh extension') ->addArgument('sh', InputArgument::OPTIONAL, 'SH name', 'Example'); - } + } /** * Executes the current command @@ -78,14 +79,12 @@ protected function configure(): void * @param OutputInterface $output [OutputInterface is the interface * implemented by all Output classes] * - * @return int 0 if everything went fine, or an exit code - * - * @throws LogicException When this abstract method is not implemented + * @return int * - * @see setCode() + * @throws LogicException [When this abstract method is not implemented] */ - protected function execute(InputInterface $input, OutputInterface $output): int - { + protected function execute(InputInterface $input, OutputInterface $output): int + { $sh = $input->getArgument('sh'); $this->store->folder('storage/sh/'); @@ -98,6 +97,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($this->successOutput("\t>> SH: File generated successfully")); - return Command::SUCCESS; - } + return Command::SUCCESS; + } } diff --git a/src/LionBundle/Commands/Lion/New/TestCommand.php b/src/LionBundle/Commands/Lion/New/TestCommand.php index c8377b10..4e53701d 100644 --- a/src/LionBundle/Commands/Lion/New/TestCommand.php +++ b/src/LionBundle/Commands/Lion/New/TestCommand.php @@ -37,7 +37,7 @@ class TestCommand extends Command */ private Store $store; - #[Inject] + #[Inject] public function setClassFactory(ClassFactory $classFactory): TestCommand { $this->classFactory = $classFactory; @@ -58,13 +58,13 @@ public function setStore(Store $store): TestCommand * * @return void */ - protected function configure(): void + protected function configure(): void { - $this + $this ->setName('new:test') ->setDescription('Command required for the creation of new test') ->addArgument('test', InputArgument::OPTIONAL, 'Test name', 'ExampleTest'); - } + } /** * Executes the current command @@ -83,7 +83,7 @@ protected function configure(): void * * @throws LogicException [When this abstract method is not implemented] */ - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output): int { $test = $input->getArgument('test'); @@ -95,9 +95,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $namespace = $this->classFactory->getNamespace(); - $this->store->folder($folder); + $this->store->folder($folder); - $this->classFactory + $this->classFactory ->create($class, ClassFactory::PHP_EXTENSION, $folder) ->add( <<setName('npm:init') - ->setDescription('Command to create Javascript projects with Vite.JS (Vanilla/Vue/React/Preact/Lit/Svelte/Solid/Qwik/Electron)') + ->setDescription('Command to create Javascript projects with Vite.JS') ->addArgument('project', InputArgument::OPTIONAL, "Project's name", 'vite-project'); } @@ -149,7 +149,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->setViteConfig($project, 18, [ 'replace' => true, - 'content' => "],\n server: {\n host: true,\n port: 5173,\n watch: {\n usePolling: true\n }\n }", + 'content' => ( + "],\n server: {\n host: true,\n port: 5173,\n watch: {\n " . + "usePolling: true\n }\n }" + ), 'search' => ']' ]); } else { @@ -157,7 +160,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->setViteConfig($project, 6, [ 'replace' => true, - 'content' => ",\n server: {\n host: true,\n port: 5173,\n watch: {\n usePolling: true\n }\n }", + 'content' => ( + ",\n server: {\n host: true,\n port: 5173,\n watch: {\n " . + "usePolling: true\n }\n }" + ), 'search' => ',' ]); } diff --git a/src/LionBundle/Commands/Lion/Schedule/ListScheduleCommand.php b/src/LionBundle/Commands/Lion/Schedule/ListScheduleCommand.php index 9318ca40..30dc55a8 100644 --- a/src/LionBundle/Commands/Lion/Schedule/ListScheduleCommand.php +++ b/src/LionBundle/Commands/Lion/Schedule/ListScheduleCommand.php @@ -132,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** @var Command $command */ - $command = new $config['command']; + $command = new $config['command'](); $rows[] = [ $this->errorOutput($config['cron']), diff --git a/src/LionBundle/Commands/Lion/Schedule/UpScheduleCommand.php b/src/LionBundle/Commands/Lion/Schedule/UpScheduleCommand.php index 98732626..6600b98d 100644 --- a/src/LionBundle/Commands/Lion/Schedule/UpScheduleCommand.php +++ b/src/LionBundle/Commands/Lion/Schedule/UpScheduleCommand.php @@ -164,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** @var Command $commandObject */ - $commandObject = new $config['command']; + $commandObject = new $config['command'](); $command = "{$config['cron']} lion cd {$_ENV['CRONTAB_PROJECT_PATH']} && "; @@ -183,7 +183,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->store->folder($this->store->normalizePath('./storage/logs/cron/')); - if (isError($this->store->exist($this->store->normalizePath('./storage/logs/cron/') . $config['logName']))) { + $exist = $this->store->exist($this->store->normalizePath('./storage/logs/cron/') . $config['logName']); + + if (isError($exist)) { $this->classFactory ->create( $config['logName'], diff --git a/src/LionBundle/Commands/Lion/ServerCommand.php b/src/LionBundle/Commands/Lion/ServerCommand.php index 70a9c2b1..6a28f92b 100644 --- a/src/LionBundle/Commands/Lion/ServerCommand.php +++ b/src/LionBundle/Commands/Lion/ServerCommand.php @@ -23,14 +23,14 @@ class ServerCommand extends Command * * @return void */ - protected function configure(): void + protected function configure(): void { - $this + $this ->setName('serve') ->setDescription('Created command to start server locally') ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'Do you want to set your own port?', 8000) ->addOption('host', 's', InputOption::VALUE_OPTIONAL, 'Do you want to set your own host?', 'localhost'); - } + } /** * Executes the current command @@ -49,9 +49,9 @@ protected function configure(): void * * @throws LogicException [When this abstract method is not implemented] */ - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output): int { - $port = $input->getOption('port'); + $port = $input->getOption('port'); $host = $input->getOption('host'); @@ -76,5 +76,5 @@ protected function execute(InputInterface $input, OutputInterface $output): int ProcessCommand::run("php -S {$host}:{$port} -t public"); return Command::SUCCESS; - } + } } diff --git a/src/LionBundle/Helpers/Bundle/constants.php b/src/LionBundle/Helpers/Bundle/constants.php index f82f3235..82278b07 100644 --- a/src/LionBundle/Helpers/Bundle/constants.php +++ b/src/LionBundle/Helpers/Bundle/constants.php @@ -1,5 +1,12 @@ capture()); - -/** - * [Object with properties captured in an HTTP request] - */ -define('ssl', (new Request())->capture()); +define('REQUEST', (new Request())->capture()); /** * [Object of Response class to generate response objects] * * @var Response */ -const response = new Response(); +const RESPONSE = new Response(); /** * Object of class Str * * @var Str */ -const str = new Str(); +const STR = new Str(); /** * Object of class Arr * * @var Arr */ -const arr = new Arr(); +const ARR = new Arr(); diff --git a/src/LionBundle/Helpers/Bundle/helpers.php b/src/LionBundle/Helpers/Bundle/helpers.php index bc92c68a..56530983 100644 --- a/src/LionBundle/Helpers/Bundle/helpers.php +++ b/src/LionBundle/Helpers/Bundle/helpers.php @@ -117,7 +117,7 @@ function public_path(string $path): string */ function finish(mixed $response = null): void { - response->finish(null === $response ? success() : $response); + RESPONSE->finish(null === $response ? success() : $response); } } @@ -138,7 +138,7 @@ function response( int $code = Http::OK, mixed $data = null ): stdClass { - return response->custom($status, $message, $code, $data); + return RESPONSE->custom($status, $message, $code, $data); } } @@ -154,7 +154,7 @@ function response( */ function success(?string $message = null, int $code = Http::OK, mixed $data = null): stdClass { - return response->success($message, $code, $data); + return RESPONSE->success($message, $code, $data); } } @@ -170,7 +170,7 @@ function success(?string $message = null, int $code = Http::OK, mixed $data = nu */ function error(?string $message = null, int $code = Http::INTERNAL_SERVER_ERROR, mixed $data = null): stdClass { - return response->error($message, $code, $data); + return RESPONSE->error($message, $code, $data); } } @@ -186,7 +186,7 @@ function error(?string $message = null, int $code = Http::INTERNAL_SERVER_ERROR, */ function warning(?string $message = null, int $code = Http::OK, mixed $data = null): stdClass { - return response->warning($message, $code, $data); + return RESPONSE->warning($message, $code, $data); } } @@ -202,7 +202,7 @@ function warning(?string $message = null, int $code = Http::OK, mixed $data = nu */ function info(?string $message = null, int $code = Http::OK, mixed $data = null): stdClass { - return response->info($message, $code, $data); + return RESPONSE->info($message, $code, $data); } } @@ -293,7 +293,7 @@ function isError(stdClass|array $response): bool return false; } - return in_array($response->status, response->getErrors()); + return in_array($response->status, RESPONSE->getErrors()); } } diff --git a/src/LionBundle/Helpers/Commands/ClassFactory.php b/src/LionBundle/Helpers/Commands/ClassFactory.php index ce96969d..8827a0cd 100644 --- a/src/LionBundle/Helpers/Commands/ClassFactory.php +++ b/src/LionBundle/Helpers/Commands/ClassFactory.php @@ -262,7 +262,8 @@ public function getProperty( 'type' => (object) [ 'camel' => ($finalVisibility . "?{$type} $" . "{$camel} = null;"), 'snake' => ( - "/**\n\t * [Property for {$propertyName}]\n\t *\n\t * @var {$type}|null $" . "{$snake}\n\t */\n" . + "/**\n\t * [Property for {$propertyName}]\n\t *\n\t * @var {$type}|null $" . + "{$snake}\n\t */\n" . "\t{$finalVisibility}?{$type} $" . "{$snake} = null;\n" ) ], diff --git a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php index 1e14b98e..954fae2a 100644 --- a/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php +++ b/src/LionBundle/Helpers/Commands/Selection/MenuCommand.php @@ -408,7 +408,8 @@ protected function getTableForeigns( kcu.column_name AS "COLUMN_NAME" FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name - JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name + JOIN information_schema.constraint_column_usage AS ccu + ON ccu.constraint_name = tc.constraint_name WHERE tc.constraint_type = ? AND tc.table_schema = ? AND tc.table_name = ? diff --git a/src/LionBundle/Helpers/Http/Fetch.php b/src/LionBundle/Helpers/Http/Fetch.php index 2317fe47..f050bd02 100644 --- a/src/LionBundle/Helpers/Http/Fetch.php +++ b/src/LionBundle/Helpers/Http/Fetch.php @@ -36,7 +36,8 @@ public function __construct( private readonly string $httpMethod, private readonly string $uri, private readonly array $options = [] - ) {} + ) { + } /** * Returns an HTTP configuration object diff --git a/src/LionBundle/Helpers/Http/FetchConfiguration.php b/src/LionBundle/Helpers/Http/FetchConfiguration.php index 65d5ea43..6d7fb848 100644 --- a/src/LionBundle/Helpers/Http/FetchConfiguration.php +++ b/src/LionBundle/Helpers/Http/FetchConfiguration.php @@ -20,7 +20,8 @@ class FetchConfiguration */ public function __construct( private readonly array $configuration = [] - ) {} + ) { + } /** * Returns configuration data diff --git a/src/LionBundle/Helpers/Http/Routes.php b/src/LionBundle/Helpers/Http/Routes.php index b34f9721..4965d6e1 100644 --- a/src/LionBundle/Helpers/Http/Routes.php +++ b/src/LionBundle/Helpers/Http/Routes.php @@ -41,6 +41,6 @@ public static function setMiddleware(array $middleware): Routes { self::$middleware = $middleware; - return new static; + return new static(); } } diff --git a/tests/Helpers/Bundle/ConstantsTest.php b/tests/Helpers/Bundle/ConstantsTest.php deleted file mode 100644 index 953b24f7..00000000 --- a/tests/Helpers/Bundle/ConstantsTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertTrue(defined('request')); - $this->assertIsObject(request); - } - - #[Testing] - public function responseConstant(): void - { - $this->assertTrue(defined('response')); - $this->assertInstanceOf(Response::class, response); - } - - #[Testing] - public function strConstant(): void - { - $this->assertTrue(defined('str')); - $this->assertInstanceOf(Str::class, str); - } - - #[Testing] - public function arrConstant(): void - { - $this->assertTrue(defined('arr')); - $this->assertInstanceOf(Arr::class, arr); - } - - #[Testing] - public function nullValueConstant(): void - { - $this->assertNull(null); - } -} diff --git a/tests/Providers/NameRuleProvider.php b/tests/Providers/NameProviderRule.php similarity index 100% rename from tests/Providers/NameRuleProvider.php rename to tests/Providers/NameProviderRule.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dc029abd..4b747b43 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,8 +20,6 @@ define('IS_INDEX', false); -define('DEVELOPMENT_ENVIRONMENT', 'dev' === env('DEVELOPMENT_ENVIRONMENT')); - /** * ----------------------------------------------------------------------------- * Register environment variable loader automatically