Skip to content

Commit

Permalink
Run tests for PHP8.0 + cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Peacock committed Jun 14, 2022
1 parent 8cae3f2 commit 77a4533
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
php-version:
- '7.3'
- '7.4'
- '8.0'

steps:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class GuzzleStopwatchProfilerMiddleware implements MiddlewareInterface
{
/**
* @var Stopwatch
* @var \Symfony\Component\Stopwatch\Stopwatch
*/
private $stopwatch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function resolveShellPath(string $shellName): string
if ($path === null) {
throw new RuntimeException(sprintf(
'Shell "%s" not found, maybe you need to install it?',
$shellName
$shellName,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'PGHOST' => Config::get(PropelConstants::ZED_DB_HOST),
'PGDATABASE' => Config::get(PropelConstants::ZED_DB_DATABASE),
'PGPORT' => Config::get(PropelConstants::ZED_DB_PORT),
]
],
);
$output->getErrorOutput()->writeln(sprintf('<comment>Executing "%s" (connection params passed via env vars)</comment>', $process->getCommandLine()));
$output->getErrorOutput()->writeln('<info>Type "\\q" to quit</info>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
class DebugConfigConsole extends Console
{
private const NAME = 'debug:config';

private const DESCRIPTION = 'Inspect the current Spryker configuration';

private const ARG_FILTER = 'filter';

private const OPT_ORIGIN = 'origin';

public function configure(): void
Expand All @@ -33,7 +36,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$config = $this->extractConfiguration();
$config = $this->filterConfig(
$config,
Cast::toStringOrNull($input->getArgument(self::ARG_FILTER))
Cast::toStringOrNull($input->getArgument(self::ARG_FILTER)),
);
$config = $this->sortConfiguration($config);
$config = $this->addOrigin($config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
class DebugQueuesConsole extends Console
{
public const OPT_VHOST = 'vhost';

public const ARG_PATTERN = 'pattern';

public const OPT_NON_EMPTY = 'non-empty';

public function configure(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
class DebugQueuesPeekConsole extends Console
{
private const ARG_NAME = 'peek';

private const OPT_VHOST = 'vhost';

private const OPT_JSON = 'json';

private const OPT_COUNT = 'count';

public function configure(): void
Expand All @@ -37,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$messages = $client->peek(
Cast::toString($input->getOption(self::OPT_VHOST)),
Cast::toString($input->getArgument(self::ARG_NAME)),
Cast::toInt($input->getOption(self::OPT_COUNT))
Cast::toInt($input->getOption(self::OPT_COUNT)),
);

foreach ($messages as $message) {
Expand All @@ -54,14 +57,14 @@ private function formatPayload(InputInterface $input, string $message): string
if ($decoded === false) {
throw new RuntimeException(sprintf(
'Could not decode JSON: "%s"',
json_last_error_msg()
json_last_error_msg(),
));
}

$encoded = json_encode($decoded, JSON_PRETTY_PRINT);
if ($encoded === false) {
throw new RuntimeException(
'Could not encode JSON'
'Could not encode JSON',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@
class PropelDumpEntityConsole extends Console
{
private const ARG_NAME = 'name';

private const OPT_BY = 'by';

private const OPT_LIMIT = 'limit';

private const OPT_RECORDS = 'records';

private const OPT_FIELDS = 'fields';

/**
* @var CriteriaParser
* @var \Inviqa\Zed\SprykerDebug\Communication\Model\Propel\CriteriaParser
*/
private $criteriaParser;

/**
* @var FieldParser
* @var \Inviqa\Zed\SprykerDebug\Communication\Model\Propel\FieldParser
*/
private $fieldParser;

Expand Down Expand Up @@ -64,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$entities = $query->findByArray($this->criteriaParser->parseMany(
Cast::toArray($input->getOption(self::OPT_BY))
Cast::toArray($input->getOption(self::OPT_BY)),
));
} catch (PropelException $exception) {
$output->writeln('<error>' . $exception->getMessage() . '</>');
Expand Down Expand Up @@ -93,7 +97,7 @@ private function buildQuery(TableMap $table, InputInterface $input): ModelCriter
throw new RuntimeException(sprintf(
'Could not find query class "%s" for "%s"',
$queryClass,
$table->getClassName()
$table->getClassName(),
));
}
$query = new $queryClass();
Expand Down Expand Up @@ -149,13 +153,13 @@ private function renderRows(Collection $entities, OutputInterface $output): void
private function entityToCells($entity): array
{
if (is_scalar($entity)) {
return [ $entity ];
return [$entity];
}

if ($entity instanceof ActiveRecordInterface) {
if (!method_exists($entity, 'toArray')) {
throw new RuntimeException(
'Active record has no ->toArray method'
'Active record has no ->toArray method',
);
}
$entity = $entity->toArray();
Expand All @@ -164,7 +168,7 @@ private function entityToCells($entity): array
if (!is_array($entity)) {
throw new RuntimeException(sprintf(
'Entity/row data is not an array, is "%s"',
gettype($entity)
gettype($entity),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$selected = $input->getArgument(self::ARG_PATTERN);
$tables = $this->getFactory()->createPropelTablesFactory()->createTables();

if (empty($selected)) {
if (!$selected) {
$selected = $style->choice('Select entity:', array_map(function (TableMap $tableMap) {
return sprintf('%s', $tableMap->getName());
}, $tables->toArray()));
Expand Down Expand Up @@ -80,7 +80,7 @@ private function renderGeneral(SymfonyStyle $style, TableMap $table): void
['class' => $table->getClassName()],
['collection' => $table->getCollectionClassName()],
['table' => $table->getName()],
['primaryKeys' => json_encode($table->getPrimaryKeys())]
['primaryKeys' => json_encode($table->getPrimaryKeys())],
);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ private function renderRelations(SymfonyStyle $style, TableMap $table): void
return $column->getName();
}, $relation->getLocalColumns())),
$this->relationType($relation->getType()),
$relation->getForeignTable()->getName()
$relation->getForeignTable()->getName(),
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
null,
[
'REDISCLI_AUTH' => Config::get('STORAGE_REDIS:STORAGE_REDIS_PASSWORD', Config::get(StorageConstants::STORAGE_REDIS_PASSWORD, '')),
]
],
);
$output->getErrorOutput()->writeln(sprintf('<comment>Executing "%s" (password passed via env REDISCLI_AUTH)</comment>', $process->getCommandLine()));
$output->getErrorOutput()->writeln('<info>Type "exit" to quit</info>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function parse(string $fields): array
{
$fields = trim($fields);

if (empty($fields)) {
if (!$fields) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
class TableNameFinder
{
/**
* @var PropelConfig
* @var \Inviqa\Zed\SprykerDebug\Model\Propel\PropelConfig
*/
private $config;

/**
* @var PhpNameGenerator
* @var \Propel\Generator\Model\PhpNameGenerator
*/
private $nameGenerator;

Expand Down Expand Up @@ -51,7 +51,8 @@ private function extractTableNames(string $schemaPath): array
}

// spryker does not seem to have consistent XML namespace
foreach ([
foreach (
[
'sprk' => 'spryker:schema-01',
'' => '',
] as $alias => $namespace
Expand Down
2 changes: 1 addition & 1 deletion src/Zed/SprykerDebug/Communication/Model/Propel/Tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function get(string $phpOrTableName): TableMap

throw new TableNotFoundException(sprintf(
'Could not find table map "%s" (using either PHP or table name)',
$phpOrTableName
$phpOrTableName,
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class TablesFactory
{
/**
* @var DatabaseMap
* @var \Propel\Runtime\Map\DatabaseMap
*/
private $map;

/**
* @var TableNameFinder
* @var \Inviqa\Zed\SprykerDebug\Communication\Model\Propel\TableNameFinder
*/
private $finder;

Expand Down
2 changes: 1 addition & 1 deletion src/Zed/SprykerDebug/Communication/Model/Rabbit/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function fromRabbitApiData(array $data): self
$data['messages_ready'] ?? -1,
$data['messages_unacknowledged'] ?? -1,
$data['messages'] ?? -1,
$data['vhost'] ?? ''
$data['vhost'] ?? '',
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Zed/SprykerDebug/Communication/Model/Rabbit/RabbitClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
final class RabbitClient
{
/**
* @var Client
* @var \GuzzleHttp\Client
*/
private $client;

Expand All @@ -18,7 +18,7 @@ public function __construct(Client $client)
}

/**
* @return Queues<Queue>
* @return \Inviqa\Zed\SprykerDebug\Communication\Model\Rabbit\Queues<\Inviqa\Zed\SprykerDebug\Communication\Model\Rabbit\Queue>
*/
public function queues(): Queues
{
Expand All @@ -32,9 +32,9 @@ private function get(string $url): array
$decoded = json_decode(
$this->client->request(
'GET',
sprintf('/api/%s', $url)
sprintf('/api/%s', $url),
)->getBody()->__toString(),
true
true,
);

if ($decoded === false) {
Expand All @@ -52,9 +52,9 @@ private function post(string $url, array $options): array
sprintf('/api/%s', $url),
[
'json' => $options,
]
],
)->getBody()->__toString(),
true
true,
);

if ($decoded === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getRabbitClient(): RabbitClient
'base_uri' => sprintf(
'http://%s:%s/api',
Config::get(RabbitMqEnv::RABBITMQ_API_HOST),
Config::get(RabbitMqEnv::RABBITMQ_API_PORT)
Config::get(RabbitMqEnv::RABBITMQ_API_PORT),
),
'auth' => [
Config::get(RabbitMqEnv::RABBITMQ_API_USERNAME),
Expand All @@ -33,7 +33,7 @@ public function getRabbitClient(): RabbitClient
'headers' => [
'Content-Type' => 'application/json',
],
])
]),
);
}

Expand Down

0 comments on commit 77a4533

Please sign in to comment.