Skip to content

Commit

Permalink
Updated PHPStan and Rector to v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 9, 2025
1 parent 12afcd8 commit cbde59b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
17 changes: 14 additions & 3 deletions CsvTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,19 @@ public function parse(): void {
}
fclose($stream);

$this->header = $this->shouldParseHeader && count($rows) > 0 ? array_slice($rows, 0, 1)[0] : [];
$this->rows = $this->shouldParseHeader && count($rows) > 0 ? array_slice($rows, 1) : $rows;
$this->header = $this->shouldParseHeader && count($rows) > 0
? array_map(fn($value): string => $value ?? '', array_slice($rows, 0, 1)[0])
: [];

$this->rows = $this->shouldParseHeader && count($rows) > 0
? array_map(
fn($row) => array_map(fn($value): string => $value ?? '', $row),
array_slice($rows, 1)
)
: array_map(
fn($row) => array_map(fn($value): string => $value ?? '', $row),
$rows
);
}

/**
Expand Down Expand Up @@ -333,7 +344,7 @@ public static function formatMarkdownTable(array $header, array $rows, array $op
// Calculate max column widths based on the header and rows by transposing
// the array and getting the max length of each column.
$widths = array_map(
fn($col): mixed => max(array_map(fn($item): int => strlen($item ?: ''), $col)),
fn($col): int => max(array_map(fn($item): int => strlen($item ?: ''), $col) ?: [0]),
array_map(NULL, ...array_merge([$header], $rows))
);

Expand Down
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alexskrypnyk/csvtable",
"description": "PHP class to work with CSV as a table and export it as Markdown.",
"description": "PHP class to parse and format CSV content.",
"license": "GPL-2.0-or-later",
"type": "library",
"authors": [
Expand All @@ -21,10 +21,9 @@
"require-dev": {
"drupal/coder": "^8.3",
"ergebnis/composer-normalize": "^2.44",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2",
"phpunit/phpunit": "^10.1",
"rector/rector": "^1.0.0"
"rector/rector": "^2"
},
"autoload": {
"psr-4": {
Expand All @@ -45,7 +44,6 @@
"scripts": {
"lint": [
"phpcs",
"phpmd --exclude vendor,node_modules . text phpmd.xml",
"phpstan",
"rector --clear-cache --dry-run"
],
Expand Down
15 changes: 0 additions & 15 deletions phpmd.xml

This file was deleted.

1 change: 0 additions & 1 deletion tests/CsvTableUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* Unit tests for CsvTable and default formatters.
*
* @covers \AlexSkrypnyk\CsvTable\CsvTable
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CsvTableUnitTest extends TestCase {

Expand Down

0 comments on commit cbde59b

Please sign in to comment.