Skip to content

Commit dca14b2

Browse files
committed
chore: standardization with PHPStan and PHP_CodeSniffer is added
1 parent 0eff632 commit dca14b2

25 files changed

+948
-329
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/vendor/
66
/storage/**/*.key
77
/storage/**/*.log
8-
/storage/postman/*.json
8+
/storage/postman/
99
/tests/build/
1010
/vite/
1111
/app/

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: max
3+
4+
excludePaths:
5+
- %currentWorkingDirectory%/src/LionBundle/Traits/

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
>
2525
<php>
2626
<env name="APP_ENV" value="testing" />
27-
27+
2828
<ini name="date.timezone" value="America/Bogota" />
2929
<ini name="intl.default_locale" value="C.UTF-8" />
3030
<ini name="memory_limit" value="2048M" />

src/LionBundle/Commands/Lion/Route/PostmanCollectionCommand.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
namespace Lion\Bundle\Commands\Lion\Route;
66

7-
use Carbon\Carbon;
87
use DI\Attribute\Inject;
98
use GuzzleHttp\Exception\GuzzleException;
109
use Lion\Bundle\Helpers\Commands\ClassFactory;
1110
use Lion\Bundle\Helpers\Commands\PostmanCollection;
1211
use Lion\Bundle\Helpers\Http\Fetch;
13-
use Lion\Bundle\Helpers\Http\Routes;
1412
use Lion\Command\Command;
1513
use Lion\Files\Store;
1614
use Lion\Helpers\Str;
@@ -141,7 +139,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
141139

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

144-
$path = storage_path('postman/', false);
142+
$this->postmanCollection->generateItems();
143+
144+
$path = storage_path('postman/');
145145

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

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

188-
$this->jsonName = $this->str->of(Carbon::now()->format('Y_m_d'))->concat('_lion_collection')->lower()->get();
189-
190-
$this->routes = json_decode(
191-
fetch(
192-
new Fetch(Route::GET, ($_ENV['SERVER_URL'] . '/route-list'), [
193-
'headers' => [
194-
'Lion-Auth' => $_ENV['SERVER_HASH'],
195-
],
196-
])
197-
)
198-
->getBody()
199-
->getContents(),
200-
true
201-
);
188+
$this->jsonName = $this->str
189+
->of(now()->format('Y_m_d'))
190+
->concat('_lion_collection')
191+
->lower()
192+
->get();
193+
194+
$json = fetch(
195+
new Fetch(Route::GET, ($_ENV['SERVER_URL'] . '/route-list'), [
196+
'headers' => [
197+
'Lion-Auth' => $_ENV['SERVER_HASH'],
198+
],
199+
])
200+
)
201+
->getBody()
202+
->getContents();
203+
204+
$decode = json_decode($json, true);
205+
206+
/**
207+
* @var array{
208+
* array<string, array{
209+
* filters: array<int, string>,
210+
* handler: array{
211+
* controller: bool|array{
212+
* name: string,
213+
* function: string
214+
* },
215+
* callback: bool
216+
* }
217+
* }>
218+
* } $routes
219+
*/
220+
$routes = $decode;
221+
222+
$this->routes = $routes;
202223

203224
array_pop($this->routes);
204225
}

src/LionBundle/Helpers/Commands/Migrations/Migrations.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Lion\Bundle\Interface\SeedInterface;
1313
use Lion\Command\Command;
1414
use Lion\Files\Store;
15+
use stdClass;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617

1718
/**
@@ -50,8 +51,7 @@ public function setStore(Store $store): Migrations
5051
/**
5152
* Sorts the list of elements by the value defined in the INDEX constant
5253
*
53-
* @param array<string, MigrationUpInterface|SeedInterface> $list [Class
54-
* List]
54+
* @param array<string, MigrationUpInterface|SeedInterface> $list [Class List]
5555
*
5656
* @return array<string, MigrationUpInterface|SeedInterface>
5757
*
@@ -72,6 +72,7 @@ public function orderList(array $list): array
7272
return -1;
7373
}
7474

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

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

101102
if (!isset($this->loadedMigrations[$migration])) {
102-
$this->loadedMigrations[$migration] = new $namespace();
103+
/** @var MigrationUpInterface $migrationInstance */
104+
$migrationInstance = new $namespace();
105+
106+
$this->loadedMigrations[$migration] = $migrationInstance;
103107
}
104108

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

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

146-
if (isError($response)) {
147-
$output->writeln($command->errorOutput("\t>> MIGRATION: {$response->message}"));
148-
} else {
149-
$output->writeln($command->successOutput("\t>> MIGRATION: {$response->message}"));
150-
}
150+
$output->writeln($command->warningOutput("\t>> MIGRATION: {$namespace}"));
151+
152+
if (isError($response)) {
153+
$output->writeln($command->errorOutput($message));
154+
} else {
155+
$output->writeln($command->successOutput($message));
151156
}
152157
}
153158
}
154159

155160
/**
156161
* Run the migrations
157162
*
158-
* @param array<int, string> $list [List of classes]
163+
* @param array<int, class-string> $list [List of classes]
159164
*
160165
* @return void
161166
*/
@@ -192,10 +197,12 @@ public function executeMigrationsGroup(array $list): void
192197
*/
193198
$run = function (array $list): void {
194199
foreach ($list as $migration) {
200+
/** @phpstan-ignore-next-line */
195201
$migration->up();
196202
}
197203
};
198204

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

201208
$run($migrations[ViewInterface::class]);

0 commit comments

Comments
 (0)