Skip to content

Commit

Permalink
Standardize code formatting across multiple files (#97)
Browse files Browse the repository at this point in the history
The commit introduces consistent spacing around the assignment operators
for better readability and maintainability. This change spans across
multiple files but does not affect the functionality of the code.
  • Loading branch information
SmetDenis committed Mar 26, 2024
1 parent 3759490 commit d1771ce
Show file tree
Hide file tree
Showing 39 changed files with 248 additions and 189 deletions.
39 changes: 39 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* JBZoo Toolbox - Csv-Blueprint.
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @see https://github.com/JBZoo/Csv-Blueprint
*/

declare(strict_types=1);

namespace JBZoo\Codestyle\PhpCsFixer;

return (new PhpCsFixerCodingStandard(__DIR__))->getFixerConfig(null, [
'binary_operator_spaces' => [
'operators' => [
'=' => 'single_space',
'=>' => 'align_single_space_minimal',
],
],
'blank_line_before_statement' => [
'statements' => [
'case',
'default',
'declare',
'do',
'for',
'switch',
'try',
'while',
'phpdoc',
],
],
]);
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# JBZoo / CSV Blueprint

[![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/main.yml?query=branch%3Amaster) [![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml/badge.svg)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml) [![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/release-docker.yml/badge.svg)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/release-docker.yml) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Csv-Blueprint/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Csv-Blueprint?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Csv-Blueprint/coverage.svg)](https://shepherd.dev/github/JBZoo/Csv-Blueprint)
[![Stable Version](https://poser.pugx.org/jbzoo/csv-blueprint/version)](https://packagist.org/packages/jbzoo/csv-blueprint/) [![Total Downloads](https://poser.pugx.org/jbzoo/csv-blueprint/downloads)](https://packagist.org/packages/jbzoo/csv-blueprint/stats) [![Docker Pulls](https://img.shields.io/docker/pulls/jbzoo/csv-blueprint.svg)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags) [![GitHub License](https://img.shields.io/github/license/jbzoo/csv-blueprint)](https://github.com/JBZoo/Csv-Blueprint/blob/master/LICENSE)
[![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/main.yml?query=branch%3Amaster) [![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml/badge.svg)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml) [![CI](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/release-docker.yml/badge.svg)](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/release-docker.yml) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Csv-Blueprint/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Csv-Blueprint?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Csv-Blueprint/coverage.svg)](https://shepherd.dev/github/JBZoo/Csv-Blueprint) [![GitHub License](https://img.shields.io/github/license/jbzoo/csv-blueprint)](https://github.com/JBZoo/Csv-Blueprint/blob/master/LICENSE)
[![GitHub Release](https://img.shields.io/github/v/release/jbzoo/csv-blueprint?label=Latest)](https://github.com/jbzoo/csv-blueprint/releases) [![Total Downloads](https://poser.pugx.org/jbzoo/csv-blueprint/downloads)](https://packagist.org/packages/jbzoo/csv-blueprint/stats) [![Docker Pulls](https://img.shields.io/docker/pulls/jbzoo/csv-blueprint.svg)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags) [![Docker Image Size](https://img.shields.io/docker/image-size/jbzoo/csv-blueprint)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags)

<!-- rules-counter -->
[![Static Badge](https://img.shields.io/badge/Rules-277-green?label=Total%20Number%20of%20Rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-66-green?label=Cell%20Value&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20Column&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20Checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-227-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
[![Static Badge](https://img.shields.io/badge/Rules-277-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-66-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-227-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
<!-- /rules-counter -->

## Introduction
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"require-dev" : {
"roave/security-advisories" : "dev-latest",
"jbzoo/toolbox-dev" : "^7.1.0",
"jbzoo/codestyle" : "^7.1.2",
"fakerphp/faker" : "^1.23.1"
},

Expand Down
49 changes: 25 additions & 24 deletions 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 docker/preload-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
$loader->register();

$command = (new CliApplication())->add(new ValidateCsv());
$buffer = new BufferedOutput();
$args = new StringInput(Cli::build('', [
$buffer = new BufferedOutput();
$args = new StringInput(Cli::build('', [
'csv' => './tests/fixtures/*.csv',
'schema' => './tests/schemas/*.yml',
]));
Expand Down
2 changes: 1 addition & 1 deletion src/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function getLongVersion(): string
{
$logo = '<info>' . \implode("</info>\n<info>", $this->appLogo) . '</info>';

return "{$logo}\n" . Utils::getVersion(false);
return "{$logo}\n" . Utils::getVersion(true);
}
}
18 changes: 9 additions & 9 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ protected function configure(): void
protected function executeAction(): int
{
if ($this->isHumanReadableMode()) {
$this->_('CSV Blueprint: ' . Utils::getVersion(false, true));
$this->_('CSV Blueprint: ' . Utils::getVersion(true));
}

if ($this->getOptBool('profile')) {
\define('PROFILE_MODE', true);
}

$csvFilenames = $this->getCsvFilepaths();
$csvFilenames = $this->getCsvFilepaths();
$schemaFilenames = $this->getSchemaFilepaths();
$matchedFiles = Utils::matchSchemaAndCsvFiles($csvFilenames, $schemaFilenames);
$matchedFiles = Utils::matchSchemaAndCsvFiles($csvFilenames, $schemaFilenames);

$this->printHeaderInfo($csvFilenames, $schemaFilenames, $matchedFiles);

Expand Down Expand Up @@ -188,7 +188,7 @@ private function validateSchemas(array $schemaFilenames): int
$totalSchemaErrors = new ErrorSuite();

$schemaErrors = null;
$quickCheck = $this->isQuickMode();
$quickCheck = $this->isQuickMode();

if ($this->isCheckingSchema()) {
$totalFiles = \count($schemaFilenames);
Expand All @@ -197,7 +197,7 @@ private function validateSchemas(array $schemaFilenames): int

foreach ($schemaFilenames as $index => $schemaFilename) {
$prefix = '(' . ((int)$index + 1) . "/{$totalFiles})";
$path = Utils::printFile($schemaFilename->getPathname());
$path = Utils::printFile($schemaFilename->getPathname());

if ($quickCheck && $schemaErrors !== null && $schemaErrors->count() > 0) {
$this->out("{$prefix} <yellow>Skipped (Quick mode)</yellow>");
Expand Down Expand Up @@ -232,11 +232,11 @@ private function validateSchemas(array $schemaFilenames): int

private function validateCsvFiles(array $matchedFiles): array
{
$totalFiles = \count($matchedFiles['found_pairs']);
$totalFiles = \count($matchedFiles['found_pairs']);
$invalidFiles = 0;
$errorCounter = 0;
$errorSuite = null;
$quickCheck = $this->isQuickMode();
$errorSuite = null;
$quickCheck = $this->isQuickMode();

$this->out("CSV file validation: {$totalFiles}");

Expand All @@ -255,7 +255,7 @@ private function validateCsvFiles(array $matchedFiles): array
continue;
}

$csvFile = new CsvFile($csv, $schema);
$csvFile = new CsvFile($csv, $schema);
$errorSuite = $csvFile->validate($quickCheck);

if ($errorSuite->count() > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/Csv/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ final class Column

public function __construct(int $id, array $config)
{
$this->id = $id;
$this->column = new Data($config);
$this->rules = $this->prepareRuleSet('rules');
$this->id = $id;
$this->column = new Data($config);
$this->rules = $this->prepareRuleSet('rules');
$this->aggRules = $this->prepareRuleSet('aggregate_rules');
}

Expand Down
8 changes: 4 additions & 4 deletions src/Csv/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function __construct(string $csvFilename, null|array|string $csvSchemaFil
}

$this->csvFilename = $csvFilename;
$this->isEmpty = \filesize($this->csvFilename) <= 1;
$this->schema = new Schema($csvSchemaFilenameOrArray);
$this->structure = $this->schema->getCsvStructure();
$this->reader = $this->prepareReader();
$this->isEmpty = \filesize($this->csvFilename) <= 1;
$this->schema = new Schema($csvSchemaFilenameOrArray);
$this->structure = $this->schema->getCsvStructure();
$this->reader = $this->prepareReader();
}

public function getCsvFilename(): string
Expand Down
7 changes: 4 additions & 3 deletions src/Csv/ParseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

final class ParseConfig
{
public const ENCODING_UTF8 = 'utf-8';
public const ENCODING_UTF16 = 'utf-16';
public const ENCODING_UTF32 = 'utf-32';
public const ENCODING_UTF8 = 'utf-8';
public const ENCODING_UTF16 = 'utf-16';
public const ENCODING_UTF32 = 'utf-32';

private const FALLBACK_VALUES = [
'inherit' => null,
'bom' => false,
Expand Down
24 changes: 12 additions & 12 deletions src/Rules/AbstarctRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ abstract class AbstarctRule
{
public const INPUT_TYPE = self::INPUT_TYPE_UNDEF;

public const INPUT_TYPE_BOOL = 0;
public const INPUT_TYPE_INTS = 1;
public const INPUT_TYPE_FLOATS = 2;
public const INPUT_TYPE_BOOL = 0;
public const INPUT_TYPE_INTS = 1;
public const INPUT_TYPE_FLOATS = 2;
public const INPUT_TYPE_STRINGS = 3;
public const INPUT_TYPE_UNDEF = 4;
public const INPUT_TYPE_UNDEF = 4;

// Modes
public const DEFAULT = 'default';
public const EQ = '';
public const NOT = 'not';
public const MIN = 'min';
public const MAX = 'max';
public const LESS = 'less';
public const EQ = '';
public const NOT = 'not';
public const MIN = 'min';
public const MAX = 'max';
public const LESS = 'less';
public const GREATER = 'greater';

protected string $columnNameId;
Expand All @@ -54,10 +54,10 @@ public function __construct(
null|array|bool|float|int|string $options,
string $mode = self::DEFAULT,
) {
$this->mode = $mode;
$this->mode = $mode;
$this->columnNameId = $columnNameId;
$this->ruleCode = $this->getRuleCode();
$this->options = $options;
$this->ruleCode = $this->getRuleCode();
$this->options = $options;
// TODO: Move resolving and validating expected value on this stage to make it only once (before validation).
}

Expand Down

0 comments on commit d1771ce

Please sign in to comment.