Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardization with PHPStan and PHP_CodeSniffer is added #114

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/vendor/
/storage/**/*.key
/storage/**/*.log
/storage/postman/*.json
/storage/postman/
/tests/build/
/vite/
/app/
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"fakerphp/faker": "^1.23",
"guzzlehttp/guzzle": "^7.9",
"lion/command": "^5.1",
"lion/database": "^11.2",
"lion/database": "^11.3",
"lion/dependency-injection": "^4.2",
"lion/exceptions": "^2.0",
"lion/files": "^8.1",
Expand All @@ -74,7 +74,7 @@
"squizlabs/php_codesniffer": "^3.11"
},
"suggest": {
"ext-gd": "Required to use LionSpreadsheet.",
"ext-gd": "Required to use spreadsheet/files.",
"ext-pdo": "Required to use all database features.",
"ext-redis": "Required to use the Redis cache.",
"fakerphp/faker": "Required to use the factory builder.",
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max

excludePaths:
- %currentWorkingDirectory%/src/LionBundle/Traits/
29 changes: 1 addition & 28 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
>
<php>
<env name="APP_ENV" value="testing" />

<ini name="date.timezone" value="America/Bogota" />
<ini name="intl.default_locale" value="C.UTF-8" />
<ini name="memory_limit" value="2048M" />
Expand All @@ -44,33 +45,5 @@
<testsuite name="All-Test">
<directory>tests/</directory>
</testsuite>

<testsuite name="Commands">
<directory>tests/Commands/</directory>
</testsuite>

<testsuite name="Enums">
<directory>tests/Enums/</directory>
</testsuite>

<testsuite name="Exceptions">
<directory>tests/Exceptions/</directory>
</testsuite>

<testsuite name="Helpers">
<directory>tests/Helpers/</directory>
</testsuite>

<testsuite name="Middleware">
<directory>tests/Middleware/</directory>
</testsuite>

<testsuite name="Traits">
<directory>tests/Traits/</directory>
</testsuite>

<testsuite name="Mailhog">
<file>tests/MailhogTest.php</file>
</testsuite>
</testsuites>
</phpunit>
55 changes: 38 additions & 17 deletions src/LionBundle/Commands/Lion/Route/PostmanCollectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Lion\Bundle\Commands\Lion\Route;

use Carbon\Carbon;
use DI\Attribute\Inject;
use GuzzleHttp\Exception\GuzzleException;
use Lion\Bundle\Helpers\Commands\ClassFactory;
use Lion\Bundle\Helpers\Commands\PostmanCollection;
use Lion\Bundle\Helpers\Http\Fetch;
use Lion\Bundle\Helpers\Http\Routes;
use Lion\Command\Command;
use Lion\Files\Store;
use Lion\Helpers\Str;
Expand Down Expand Up @@ -141,7 +139,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->postmanCollection->addRoutes($this->routes);

$path = storage_path('postman/', false);
$this->postmanCollection->generateItems();

$path = storage_path('postman/');

$this->store->folder($path);

Expand Down Expand Up @@ -185,20 +185,41 @@ private function fetchRoutes(): void
{
$this->postmanCollection->init($_ENV['SERVER_URL']);

$this->jsonName = $this->str->of(Carbon::now()->format('Y_m_d'))->concat('_lion_collection')->lower()->get();

$this->routes = json_decode(
fetch(
new Fetch(Route::GET, ($_ENV['SERVER_URL'] . '/route-list'), [
'headers' => [
'Lion-Auth' => $_ENV['SERVER_HASH'],
],
])
)
->getBody()
->getContents(),
true
);
$this->jsonName = $this->str
->of(now()->format('Y_m_d'))
->concat('_lion_collection')
->lower()
->get();

$json = fetch(
new Fetch(Route::GET, ($_ENV['SERVER_URL'] . '/route-list'), [
'headers' => [
'Lion-Auth' => $_ENV['SERVER_HASH'],
],
])
)
->getBody()
->getContents();

$decode = json_decode($json, true);

/**
* @var array{
* array<string, array{
* filters: array<int, string>,
* handler: array{
* controller: bool|array{
* name: string,
* function: string
* },
* callback: bool
* }
* }>
* } $routes
*/
$routes = $decode;

$this->routes = $routes;

array_pop($this->routes);
}
Expand Down
43 changes: 0 additions & 43 deletions src/LionBundle/Enums/TaskStatusEnum.php

This file was deleted.

31 changes: 19 additions & 12 deletions src/LionBundle/Helpers/Commands/Migrations/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Lion\Bundle\Interface\SeedInterface;
use Lion\Command\Command;
use Lion\Files\Store;
use stdClass;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -50,8 +51,7 @@ public function setStore(Store $store): Migrations
/**
* Sorts the list of elements by the value defined in the INDEX constant
*
* @param array<string, MigrationUpInterface|SeedInterface> $list [Class
* List]
* @param array<string, MigrationUpInterface|SeedInterface> $list [Class List]
*
* @return array<string, MigrationUpInterface|SeedInterface>
*
Expand All @@ -72,6 +72,7 @@ public function orderList(array $list): array
return -1;
}

/** @phpstan-ignore-next-line */
return $classA::INDEX <=> $classB::INDEX;
});

Expand Down Expand Up @@ -99,7 +100,10 @@ public function getMigrations(): array
$namespace = $this->store->getNamespaceFromFile($migration, 'Database\\Migrations\\', 'Migrations/');

if (!isset($this->loadedMigrations[$migration])) {
$this->loadedMigrations[$migration] = new $namespace();
/** @var MigrationUpInterface $migrationInstance */
$migrationInstance = new $namespace();

$this->loadedMigrations[$migration] = $migrationInstance;
}

$tableMigration = $this->loadedMigrations[$migration];
Expand Down Expand Up @@ -138,24 +142,25 @@ public function getMigrations(): array
public function executeMigrations(Command $command, OutputInterface $output, array $files): void
{
foreach ($files as $namespace => $classObject) {
if ($classObject instanceof MigrationUpInterface) {
$response = $classObject->up();
$response = $classObject->up();

$output->writeln($command->warningOutput("\t>> MIGRATION: {$namespace}"));
/** @phpstan-ignore-next-line */
$message = "\t>> MIGRATION: {$response->message}";

if (isError($response)) {
$output->writeln($command->errorOutput("\t>> MIGRATION: {$response->message}"));
} else {
$output->writeln($command->successOutput("\t>> MIGRATION: {$response->message}"));
}
$output->writeln($command->warningOutput("\t>> MIGRATION: {$namespace}"));

if (isError($response)) {
$output->writeln($command->errorOutput($message));
} else {
$output->writeln($command->successOutput($message));
}
}
}

/**
* Run the migrations
*
* @param array<int, string> $list [List of classes]
* @param array<int, class-string> $list [List of classes]
*
* @return void
*/
Expand Down Expand Up @@ -192,10 +197,12 @@ public function executeMigrationsGroup(array $list): void
*/
$run = function (array $list): void {
foreach ($list as $migration) {
/** @phpstan-ignore-next-line */
$migration->up();
}
};

/** @phpstan-ignore-next-line */
$run($this->orderList($migrations[TableInterface::class]));

$run($migrations[ViewInterface::class]);
Expand Down
Loading