Skip to content

Commit

Permalink
Phan fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Smet committed Mar 10, 2024
1 parent b20e4eb commit 8592314
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/Commands/CreateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CreateCsv extends CliCommand
{
protected function configure(): void
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/CreateSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class CreateSchema extends CliCommand
{
protected function configure(): void
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use JBZoo\CsvBlueprint\Validators\ErrorSuite;
use Symfony\Component\Console\Input\InputOption;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ValidateCsv extends CliCommand
{
protected function configure(): void
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/ValidateDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use JBZoo\Cli\CliCommand;
use Symfony\Component\Console\Input\InputArgument;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ValidateDir extends CliCommand
{
protected function configure(): void
Expand Down
5 changes: 1 addition & 4 deletions src/Csv/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public function getHeader(): array
return [];
}

/**
* @return iterable|\League\Csv\MapIterator
*/
public function getRecords(): iterable
public function getRecords(): \Iterator
{
return $this->reader->getRecords($this->getHeader());
}
Expand Down
5 changes: 5 additions & 0 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function __construct(null|array|string $csvSchemaFilenameOrArray = null)
&& \file_exists($csvSchemaFilenameOrArray)
) {
$this->filename = $csvSchemaFilenameOrArray;
$this->data = new Data();
$fileExtension = \pathinfo($csvSchemaFilenameOrArray, \PATHINFO_EXTENSION);

if ($fileExtension === 'yml' || $fileExtension === 'yaml') {
$this->data = yml($csvSchemaFilenameOrArray);
} elseif ($fileExtension === 'json') {
Expand All @@ -54,6 +56,9 @@ public function __construct(null|array|string $csvSchemaFilenameOrArray = null)
} else {
throw new \InvalidArgumentException("Unsupported file extension: {$fileExtension}");
}
} else {
$this->filename = null;
$this->data = new Data();
}

$this->columns = $this->prepareColumns();
Expand Down
15 changes: 8 additions & 7 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public function render(string $mode = self::RENDER_TEXT): string
return '';
}

$map = [
self::RENDER_TEXT => fn () => $this->renderPlainText(),
self::RENDER_TABLE => fn () => $this->renderTable(),
self::RENDER_GITHUB => fn () => (new GithubCliConverter())->fromInternal($this->prepareSourceSuite()),
self::RENDER_GITLAB => fn () => (new GitLabJsonConverter())->fromInternal($this->prepareSourceSuite()),
self::RENDER_TEAMCITY => fn () => (new TeamCityTestsConverter())->fromInternal($this->prepareSourceSuite()),
self::RENDER_JUNIT => fn () => (new JUnitConverter())->fromInternal($this->prepareSourceSuite()),
$sourceSuite = $this->prepareSourceSuite();
$map = [
self::RENDER_TEXT => fn (): string => $this->renderPlainText(),
self::RENDER_TABLE => fn (): string => $this->renderTable(),
self::RENDER_GITHUB => static fn (): string => (new GithubCliConverter())->fromInternal($sourceSuite),
self::RENDER_GITLAB => static fn (): string => (new GitLabJsonConverter())->fromInternal($sourceSuite),
self::RENDER_TEAMCITY => static fn (): string => (new TeamCityTestsConverter())->fromInternal($sourceSuite),
self::RENDER_JUNIT => static fn (): string => (new JUnitConverter())->fromInternal($sourceSuite),
];

if (isset($map[$mode])) {
Expand Down
6 changes: 5 additions & 1 deletion src/Validators/Rules/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function validateRule(?string $cellValue): ?string
{
$regex = Utils::prepareRegex($this->getOptionAsString());

if (\preg_match((string)$regex, (string)$cellValue) === 0) {
if ($regex === null || $regex === '') {
return 'Regex pattern is not defined';
}

if (\preg_match($regex, (string)$cellValue) === 0) {
return "Value \"{$cellValue}\" does not match the pattern \"{$regex}\"";
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validators/Rules/UsaMarketName.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}

if (\preg_match('/^[A-Za-z0-9\s-]+, [A-Z]{2}$/u', (string)$cellValue) === 0) {
return 'Invalid market name format for value "' . $cellValue . '". ' .
return "Invalid market name format for value \"{$cellValue}\". " .
'Market name must have format "New York, NY"';
}

Expand Down
5 changes: 5 additions & 0 deletions src/Validators/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ final class Ruleset
public function __construct(array $rules, string $columnNameId)
{
$this->columnNameId = $columnNameId;
$this->rules = [];

foreach ($rules as $ruleName => $options) {
$this->rules[] = $this->createRule($ruleName, $options);
}
}

/**
* @psalm-suppress MoreSpecificReturnType
* @psalm-suppress LessSpecificReturnStatement
*/
public function createRule(string $ruleName, null|array|bool|float|int|string $options = null): AbstarctRule
{
$classname = __NAMESPACE__ . '\\Rules\\' . Utils::kebabToCamelCase($ruleName);
Expand Down

0 comments on commit 8592314

Please sign in to comment.