Skip to content

Commit

Permalink
Codestyle!
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Smet committed Mar 10, 2024
1 parent 8592314 commit 36fa39e
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 29 deletions.
11 changes: 11 additions & 0 deletions .phan.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@

$default = include __DIR__ . '/vendor/jbzoo/codestyle/src/phan.php';

// Remove SimplifyExpressionPlugin from plugin list
$default['plugins'] = \array_diff($default['plugins'], ['SimplifyExpressionPlugin']);

return \array_merge($default, [
'directory_list' => [
'src',

'vendor/jbzoo/data/src',
'vendor/jbzoo/cli/src',
'vendor/jbzoo/utils/src',
'vendor/jbzoo/ci-report-converter/src',
'vendor/league/csv/src',
'vendor/fakerphp/faker/src',
'vendor/symfony/console',
],
]);
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"prefer-stable" : true,

"require" : {
"php" : "^8.1",
"ext-mbstring" : "*",

"jbzoo/data" : "^7.1",
"jbzoo/cli" : "^7.1",
"jbzoo/utils" : "^7.1",
"league/csv" : "^9.15",
"fakerphp/faker" : "^1.23",
"jbzoo/ci-report-converter": "^7.2"
"php" : "^8.1",
"ext-mbstring" : "*",

"jbzoo/data" : "^7.1",
"jbzoo/cli" : "^7.1",
"jbzoo/utils" : "^7.1",
"jbzoo/ci-report-converter" : "^7.2",
"league/csv" : "^9.15",
"fakerphp/faker" : "^1.23"
},

"require-dev" : {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Csv/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ private function prepareRuleSet(string $schemaKey): array
{
$rules = [];

$ruleSetConfig = $this->column->getSelf($schemaKey, []);
$ruleSetConfig = $this->column->getSelf($schemaKey, [])->getArrayCopy();

foreach ($ruleSetConfig as $ruleName => $ruleValue) {
if (\str_starts_with($ruleName, 'custom_')) {
if (\str_starts_with((string)$ruleName, 'custom_')) {
$rules[$ruleName] = \array_merge(['class' => '', 'args' => []], $ruleValue);
} else {
$rules[$ruleName] = $ruleValue;
Expand Down
8 changes: 4 additions & 4 deletions src/Csv/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(string $csvFilename, null|array|string $csvSchemaFil

public function getCsvFilename(): string
{
return \str_replace(PROJECT_ROOT, '.', (string)\realpath($this->csvFilename));
return \pathinfo((string)\realpath($this->csvFilename), \PATHINFO_BASENAME);
}

public function getCsvStructure(): ParseConfig
Expand Down Expand Up @@ -79,7 +79,7 @@ public function validate(bool $quickStop = false): ErrorSuite

$errors->addErrorSuit($this->validateHeader())
->addErrorSuit($this->validateEachCell($quickStop))
->addErrorSuit($this->validateAggregateRules($quickStop));
->addErrorSuit(self::validateAggregateRules($quickStop));

return $errors;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private function validateEachCell(bool $quickStop = false): ErrorSuite
continue;
}

$errors->addErrorSuit($column->validate($record[$column->getKey()], $line + 1));
$errors->addErrorSuit($column->validate($record[$column->getKey()], (int)$line + 1));
if ($quickStop && $errors->count() > 0) {
return $errors;
}
Expand All @@ -147,7 +147,7 @@ private function validateEachCell(bool $quickStop = false): ErrorSuite
return $errors;
}

private function validateAggregateRules(bool $quickStop = false): ErrorSuite
private static function validateAggregateRules(bool $quickStop = false): ErrorSuite
{
$errors = new ErrorSuite();

Expand Down
6 changes: 3 additions & 3 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public function getColumns(): array

/**
* @return Column[]|null[]
* @phan-suppress PhanPartialTypeMismatchReturn
*/
public function getColumnsMappedByHeader(array $header): array
{
$map = [];

foreach ($header as $headerName) {
$column = $this->columns[$headerName] ?? null;
$map[$headerName] = $column;
$map[$headerName] = $this->columns[$headerName] ?? null;
}

return $map;
Expand Down Expand Up @@ -141,7 +141,7 @@ private function prepareColumns(): array
$result = [];

foreach ($this->data->getArray('columns') as $columnId => $columnPreferences) {
$column = new Column($columnId, $columnPreferences);
$column = new Column((int)$columnId, $columnPreferences);

$result[$column->getKey()] = $column;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/Rules/MaxDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validateRule(?string $cellValue): ?string
$minDate = $this->getOptionAsDate();
$cellDate = new \DateTimeImmutable((string)$cellValue);

if ($cellDate > $minDate) {
if ($cellDate->getTimestamp() > $minDate->getTimestamp()) {
return "Value \"{$cellValue}\" is more than the maximum " .
"date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/Rules/MinDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function validateRule(?string $cellValue): ?string
$minDate = $this->getOptionAsDate();
$cellDate = new \DateTimeImmutable((string)$cellValue);

if ($cellDate < $minDate) {
if ($cellDate->getTimestamp() < $minDate->getTimestamp()) {
return "Value \"{$cellValue}\" is less than the minimum " .
"date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
}
Expand Down
11 changes: 6 additions & 5 deletions src/Validators/Rules/Precision.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ final class Precision extends AbstarctRule
{
public function validateRule(?string $cellValue): ?string
{
if ($this->getOptionAsInt() !== $this->getFloatPrecision($cellValue)) {
return "Value \"{$cellValue}\" has a precision of " . $this->getFloatPrecision(
$cellValue,
) . ' but should have a precision of ' . $this->getOptionAsInt();
$valuePrecision = self::getFloatPrecision($cellValue);

if ($this->getOptionAsInt() !== $valuePrecision) {
return "Value \"{$cellValue}\" has a precision of {$valuePrecision} " .
"but should have a precision of {$this->getOptionAsInt()}";
}

return null;
}

private function getFloatPrecision(?string $cellValue): int
private static function getFloatPrecision(?string $cellValue): int
{
$floatAsString = (string)$cellValue;
$dotPosition = \strpos($floatAsString, '.');
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $rules, string $columnNameId)
$this->rules = [];

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

Expand Down
4 changes: 2 additions & 2 deletions tests/Blueprint/CsvReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class CsvReaderTest extends PHPUnit
public function testReadCsvFileWithoutHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_NO_HEADER, self::SCHEMA_SIMPLE_NO_HEADER);
isSame('./tests/fixtures/simple_no_header.csv', $csv->getCsvFilename());
isSame('simple_no_header.csv', $csv->getCsvFilename());

isSame([], $csv->getHeader());

Expand All @@ -50,7 +50,7 @@ public function testReadCsvFileWithoutHeader(): void
public function testReadCsvFileWithHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, self::SCHEMA_SIMPLE_HEADER);
isSame('./tests/fixtures/simple_header.csv', $csv->getCsvFilename());
isSame('simple_header.csv', $csv->getCsvFilename());

isSame(['seq', 'bool', 'exact'], $csv->getHeader());

Expand Down

0 comments on commit 36fa39e

Please sign in to comment.