Skip to content

Commit

Permalink
Code-Modernisierung
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Sep 29, 2023
1 parent 81ff734 commit 56f9326
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 48 deletions.
6 changes: 3 additions & 3 deletions lib/api_protected_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
final class rex_api_ydeploy_protected_page extends rex_api_function
{
public function execute()
public function execute(): rex_api_result
{
if (!rex::getUser()->isAdmin()) {
if (!rex::requireUser()->isAdmin()) {
throw new rex_api_exception('Protected pages can be (un)locked only by admins.');
}

Expand Down Expand Up @@ -50,7 +50,7 @@ public function execute()
return $result;
}

protected function requiresCsrfProtection()
protected function requiresCsrfProtection(): bool
{
return true;
}
Expand Down
9 changes: 3 additions & 6 deletions lib/command/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
*/
abstract class rex_ydeploy_command_abstract extends rex_console_command
{
/** @var rex_addon */
protected $addon;

/** @var string */
protected $migrationTable;
protected readonly rex_addon $addon;
protected readonly string $migrationTable;

public function __construct()
{
$this->addon = rex_addon::get('ydeploy');
$this->addon = rex_addon::require('ydeploy');
$this->migrationTable = rex::getTable('ydeploy_migration');

parent::__construct();
Expand Down
7 changes: 4 additions & 3 deletions lib/command/diff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -9,7 +10,7 @@
*/
final class rex_ydeploy_command_diff extends rex_ydeploy_command_abstract
{
protected function configure()
protected function configure(): void
{
$this
->setName('ydeploy:diff')
Expand All @@ -19,7 +20,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->getStyle($input, $output);

Expand Down Expand Up @@ -57,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->success('Updated schema and fixtures files, nothing changed.');
}

return 0;
return Command::SUCCESS;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions lib/command/migrate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -9,7 +10,7 @@
*/
final class rex_ydeploy_command_migrate extends rex_ydeploy_command_abstract
{
protected function configure()
protected function configure(): void
{
$this
->setName('ydeploy:migrate')
Expand All @@ -18,7 +19,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = $this->getStyle($input, $output);

Expand Down Expand Up @@ -50,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$paths) {
$io->success('Nothing to migrate.');

return 0;
return Command::SUCCESS;
}

$io->text(count($paths).' migrations to execute');
Expand All @@ -77,12 +78,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($countMigrated === count($paths)) {
$io->success(sprintf('%s %d migrations.', $fake ? 'Faked' : 'Executed', $countMigrated));

return 0;
return Command::SUCCESS;
}

$io->error(sprintf('%s %d of %d migrations, aborted with "%s".', $fake ? 'Faked' : 'Executed', $countMigrated, count($paths), basename($path)));

return 1;
return Command::FAILURE;
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/diff_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
final class rex_ydeploy_diff_file
{
/** @var array<string, rex_sql_table> */
private $create = [];
private array $create = [];

/**
* @var array<string, array{
Expand All @@ -21,19 +21,19 @@ final class rex_ydeploy_diff_file
* removeForeignKey?: list<string>
* }>
*/
private $alter = [];
private array $alter = [];

/** @var list<string> */
private $drop = [];
private array $drop = [];

/** @var array<string, string> */
private $views = [];
private array $views = [];

/** @var list<string> */
private $dropViews = [];
private array $dropViews = [];

/** @var array<string, array{ensure?: list<array<?scalar>>, remove?: list<array<string, int|string>>}> */
private $fixtures = [];
private array $fixtures = [];

public function createTable(rex_sql_table $table): void
{
Expand Down
2 changes: 2 additions & 0 deletions lib/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
final class rex_ydeploy_handler
{
/** @param rex_extension_point<array<mixed>> $ep */
public static function addBodyClasses(rex_extension_point $ep): array
{
$ydeploy = rex_ydeploy::factory();
Expand All @@ -24,6 +25,7 @@ public static function addBodyClasses(rex_extension_point $ep): array
return $attr;
}

/** @param rex_extension_point<string> $ep */
public static function addBadge(rex_extension_point $ep): ?string
{
$ydeploy = rex_ydeploy::factory();
Expand Down
36 changes: 12 additions & 24 deletions lib/ydeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@

final class rex_ydeploy
{
/** @var self|null */
private static $instance;
private static ?self $instance = null;

/** @var bool */
private $deployed;

/** @var string|null */
private $host;

/** @var string|null */
private $stage;

/** @var string|null */
private $branch;

/** @var string|null */
private $commit;

/** @var DateTimeImmutable|null */
private $timestamp;
private bool $deployed;
private ?string $host = null;
private ?string $stage = null;
private ?string $branch = null;
private ?string $commit = null;
private ?DateTimeImmutable $timestamp = null;

private function __construct()
{
Expand All @@ -37,11 +25,11 @@ private function __construct()

$info = rex_file::getCache($path);

$this->host = $info['host'];
$this->stage = $info['stage'];
$this->branch = $info['branch'];
$this->commit = $info['commit'];
$this->timestamp = DateTimeImmutable::createFromFormat('U', $info['timestamp']);
$this->host = rex_type::string($info['host']);
$this->stage = rex_type::string($info['stage']);
$this->branch = rex_type::string($info['branch']);
$this->commit = rex_type::string($info['commit']);
$this->timestamp = rex_type::instanceOf(DateTimeImmutable::createFromFormat('U', $info['timestamp']), DateTimeImmutable::class);
}

public static function factory(): self
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@
</plugins>
<issueHandlers>
<Trace errorLevel="error"/> <!-- https://psalm.dev/docs/running_psalm/issues/Trace/ -->
<InvalidLiteralArgument errorLevel="info"/>
</issueHandlers>
</psalm>

0 comments on commit 56f9326

Please sign in to comment.