Skip to content

Commit

Permalink
Update PHP-CS-Fixer configuration and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
misantron committed Oct 25, 2021
1 parent 73a9c07 commit dda88a1
Show file tree
Hide file tree
Showing 53 changed files with 305 additions and 257 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,7 +1,7 @@
/.idea
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/composer.lock
/build
/vendor
/tools
/.phpunit.result.cache
32 changes: 30 additions & 2 deletions .php-cs-fixer.php
Expand Up @@ -16,10 +16,12 @@
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);
])
;

$config = new PhpCsFixer\Config();
$config
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
Expand All @@ -28,7 +30,33 @@
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'header_comment' => ['header' => $header],
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'line_ending' => true,
'modernize_types_casting' => true,
'no_blank_lines_after_phpdoc' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'phpdoc_align' => false,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'native_function_invocation' => true,
])
->setFinder($finder);
;

return $config;
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -22,7 +22,7 @@
"symfony/yaml": "^4.4 || ^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18 || ^3.0",
"friendsofphp/php-cs-fixer": "^2.18 || ^3.2",
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan": "^0.12.98",
"squizlabs/php_codesniffer": "^3.6"
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/DataSetIsEqual.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(IDataSet $value)
*/
public function toString(): string
{
return \sprintf(
return sprintf(
'is equal to expected %s',
(string) $this->value
);
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/TableIsEqual.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(ITable $value)
*/
public function toString(): string
{
return \sprintf(
return sprintf(
'is equal to expected %s',
(string) $this->value
);
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/TableRowCount.php
Expand Up @@ -45,7 +45,7 @@ public function __construct(string $tableName, int $value)
*/
public function toString(): string
{
return \sprintf('is equal to expected row count %d', $this->value);
return sprintf('is equal to expected row count %d', $this->value);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/DataSet/AbstractDataSet.php
Expand Up @@ -101,15 +101,16 @@ public function getReverseIterator(): ITableIterator
* Asserts that the given data set matches this data set.
*
* @param IDataSet $other
*
* @return bool
*/
public function matches(IDataSet $other): bool
{
$thisTableNames = $this->getTableNames();
$otherTableNames = $other->getTableNames();

\sort($thisTableNames);
\sort($otherTableNames);
sort($thisTableNames);
sort($otherTableNames);

if ($thisTableNames !== $otherTableNames) {
return false;
Expand All @@ -131,6 +132,7 @@ public function matches(IDataSet $other): bool
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
abstract protected function createIterator(bool $reverse = false): ITableIterator;
Expand Down
20 changes: 11 additions & 9 deletions src/DataSet/AbstractTable.php
Expand Up @@ -42,12 +42,12 @@ public function __toString()

// if count less than 0 (when table is empty), then set count to 1
$count = $count >= 1 ? $count : 1;
$lineSeparator = \str_repeat('+----------------------', $count) . "+\n";
$lineSeparator = str_repeat('+----------------------', $count) . "+\n";
$lineLength = \strlen($lineSeparator) - 1;

$tableString = $lineSeparator;
$tblName = $this->getTableMetaData()->getTableName();
$tableString .= '| ' . \str_pad(
$tableString .= '| ' . str_pad(
$tblName,
$lineLength - 4,
' ',
Expand All @@ -66,10 +66,10 @@ public function __toString()
if ($this->other) {
try {
if ($this->getValue($i, $columnName) !== $this->other->getValue($i, $columnName)) {
$values[] = \sprintf(
$values[] = sprintf(
'%s != actual %s',
\var_export($this->getValue($i, $columnName), true),
\var_export($this->other->getValue($i, $columnName), true)
var_export($this->getValue($i, $columnName), true),
var_export($this->other->getValue($i, $columnName), true)
);
} else {
$values[] = $this->getValue($i, $columnName);
Expand Down Expand Up @@ -113,6 +113,7 @@ public function getRowCount(): int
*
* @param int $row
* @param string $column
*
* @return mixed|string
*/
public function getValue(int $row, string $column)
Expand Down Expand Up @@ -150,6 +151,7 @@ public function getRow(int $row): array
* Asserts that the given table matches this table.
*
* @param ITable $other
*
* @return bool
*/
public function matches(ITable $other): bool
Expand All @@ -169,7 +171,7 @@ public function matches(ITable $other): bool
$thisValue = $this->getValue($i, $columnName);
$otherValue = $other->getValue($i, $columnName);

if (\is_numeric($thisValue) && \is_numeric($otherValue)) {
if (is_numeric($thisValue) && is_numeric($otherValue)) {
if ($thisValue != $otherValue) {
$this->other = $other;

Expand Down Expand Up @@ -219,11 +221,11 @@ protected function rowToString(array $row): string
$value = 'NULL';
}

$value_str = \mb_substr($value, 0, 20);
$value_str = mb_substr($value, 0, 20);

// make str_pad act in multi byte manner
$correction = \strlen($value_str) - \mb_strlen($value_str);
$rowString .= '| ' . \str_pad($value_str, 20 + $correction, ' ', STR_PAD_BOTH) . ' ';
$correction = \strlen($value_str) - mb_strlen($value_str);
$rowString .= '| ' . str_pad($value_str, 20 + $correction, ' ', STR_PAD_BOTH) . ' ';
}

/** @see https://github.com/sebastianbergmann/dbunit/issues/195 */
Expand Down
1 change: 1 addition & 0 deletions src/DataSet/AbstractTableMetadata.php
Expand Up @@ -69,6 +69,7 @@ public function getTableName(): string
* Asserts that the given tableMetaData matches this tableMetaData.
*
* @param ITableMetadata $other
*
* @return bool
*/
public function matches(ITableMetadata $other): bool
Expand Down
20 changes: 10 additions & 10 deletions src/DataSet/AbstractXmlDataSet.php
Expand Up @@ -38,34 +38,34 @@ public function __construct(string $xmlFile)
throw new \LogicException('Extension DOM is required.');
}

if (!\is_file($xmlFile)) {
if (!is_file($xmlFile)) {
throw new InvalidArgumentException("Could not find xml file: {$xmlFile}");
}

if (\LIBXML_VERSION < 20900) {
$libxmlEntityLoader = \libxml_disable_entity_loader(false);
$libxmlEntityLoader = libxml_disable_entity_loader(false);
}
$libxmlErrorReporting = \libxml_use_internal_errors(true);
$this->xmlFileContents = \simplexml_load_string(
\file_get_contents($xmlFile),
$libxmlErrorReporting = libxml_use_internal_errors(true);
$this->xmlFileContents = simplexml_load_string(
file_get_contents($xmlFile),
'SimpleXMLElement',
LIBXML_COMPACT | LIBXML_PARSEHUGE
);

if (!$this->xmlFileContents) {
$message = '';

foreach (\libxml_get_errors() as $error) {
$message .= \print_r($error, true);
foreach (libxml_get_errors() as $error) {
$message .= print_r($error, true);
}

throw new RuntimeException($message);
}

\libxml_clear_errors();
\libxml_use_internal_errors($libxmlErrorReporting);
libxml_clear_errors();
libxml_use_internal_errors($libxmlErrorReporting);
if (\LIBXML_VERSION < 20900) {
\libxml_disable_entity_loader($libxmlEntityLoader);
libxml_disable_entity_loader($libxmlEntityLoader);
}

$tableColumns = [];
Expand Down
2 changes: 1 addition & 1 deletion src/DataSet/ArrayDataSet.php
Expand Up @@ -45,7 +45,7 @@ public function __construct(array $data)
$columns = [];

if (isset($rows[0])) {
$columns = \array_keys($rows[0]);
$columns = array_keys($rows[0]);
}

$metaData = new DefaultTableMetadata($tableName, $columns);
Expand Down
1 change: 1 addition & 0 deletions src/DataSet/CompositeDataSet.php
Expand Up @@ -70,6 +70,7 @@ public function addDataSet(IDataSet $dataSet): void
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
protected function createIterator(bool $reverse = false): ITableIterator
Expand Down
12 changes: 6 additions & 6 deletions src/DataSet/CsvDataSet.php
Expand Up @@ -67,15 +67,15 @@ public function __construct($delimiter = ',', $enclosure = '"', $escape = '"')
*/
public function addTable($tableName, $csvFile): void
{
if (!\is_file($csvFile)) {
if (!is_file($csvFile)) {
throw new InvalidArgumentException("Could not find csv file: {$csvFile}");
}

if (!\is_readable($csvFile)) {
if (!is_readable($csvFile)) {
throw new InvalidArgumentException("Could not read csv file: {$csvFile}");
}

$fh = \fopen($csvFile, 'rb');
$fh = fopen($csvFile, 'rb');
$columns = $this->getCsvRow($fh);
$columnsCount = \count($columns);

Expand All @@ -92,7 +92,7 @@ public function addTable($tableName, $csvFile): void
if ($columnsCount !== \count($row)) {
throw new InvalidArgumentException("Row no. {$rowNumber} in csv file {$csvFile} should have an equal number of elements as table {$tableName}");
}
$table->addRow(\array_combine($columns, $row));
$table->addRow(array_combine($columns, $row));
$rowNumber++;
}

Expand Down Expand Up @@ -122,9 +122,9 @@ protected function createIterator(bool $reverse = false): ITableIterator
protected function getCsvRow($fh)
{
if (PHP_VERSION_ID > 50300) {
return \fgetcsv($fh, null, $this->delimiter, $this->enclosure, $this->escape);
return fgetcsv($fh, null, $this->delimiter, $this->enclosure, $this->escape);
}

return \fgetcsv($fh, null, $this->delimiter, $this->enclosure);
return fgetcsv($fh, null, $this->delimiter, $this->enclosure);
}
}
1 change: 1 addition & 0 deletions src/DataSet/DefaultDataSet.php
Expand Up @@ -46,6 +46,7 @@ public function addTable(ITable $table): void
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
protected function createIterator(bool $reverse = false): ITableIterator
Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/DefaultTable.php
Expand Up @@ -36,8 +36,8 @@ public function __construct(ITableMetadata $tableMetaData)
*/
public function addRow($values = []): void
{
$this->data[] = \array_replace(
\array_fill_keys($this->getTableMetaData()->getColumns(), null),
$this->data[] = array_replace(
array_fill_keys($this->getTableMetaData()->getColumns(), null),
$values
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/DataSet/DefaultTableIterator.php
Expand Up @@ -72,7 +72,7 @@ public function getTableMetaData(): ITableMetadata
*/
public function current()
{
return \current($this->tables);
return current($this->tables);
}

/**
Expand All @@ -91,9 +91,9 @@ public function key(): string
public function next(): void
{
if ($this->reverse) {
\prev($this->tables);
prev($this->tables);
} else {
\next($this->tables);
next($this->tables);
}
}

Expand All @@ -103,9 +103,9 @@ public function next(): void
public function rewind(): void
{
if ($this->reverse) {
\end($this->tables);
end($this->tables);
} else {
\reset($this->tables);
reset($this->tables);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/DataSet/Filter.php
Expand Up @@ -89,7 +89,7 @@ public function __construct(IDataSet $originalDataSet, array $excludeTables = []
*/
public function addIncludeTables(array $tables): void
{
$this->includeTables = \array_unique(\array_merge($this->includeTables, $tables));
$this->includeTables = array_unique(array_merge($this->includeTables, $tables));
}

/**
Expand All @@ -99,7 +99,7 @@ public function addIncludeTables(array $tables): void
*/
public function addExcludeTables(array $tables): void
{
$this->excludeTables = \array_unique(\array_merge($this->excludeTables, $tables));
$this->excludeTables = array_unique(array_merge($this->excludeTables, $tables));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/DataSet/IDataSet.php
Expand Up @@ -52,7 +52,8 @@ public function getReverseIterator(): ITableIterator;
* Asserts that the given data set matches this data set.
*
* @param IDataSet $other
*
* @return bool
*/
public function matches(IDataSet $other): bool;
public function matches(self $other): bool;
}
3 changes: 2 additions & 1 deletion src/DataSet/ITable.php
Expand Up @@ -51,7 +51,8 @@ public function getRow(int $row): array;
* Asserts that the given table matches this table.
*
* @param ITable $other
*
* @return bool
*/
public function matches(ITable $other): bool;
public function matches(self $other): bool;
}

0 comments on commit dda88a1

Please sign in to comment.