From 6688de1a00828ce3c44a97d196214a7cd10645f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Mon, 27 Mar 2023 09:22:35 +0200 Subject: [PATCH] bump: openspout/openspout 4.0 (#172) * bump: openspout/openspout 4.0 * fix: CS * bump: sigwin/infra ^1.4.1 * fix: use getCell() * fix: use getCell() with the string name * fix: Psalm issues * fix: Psalm issues * fix: CS --- composer.json | 4 ++-- psalm.xml.dist | 11 +++++++++++ src/Bridge/PhpSpreadsheet/Spreadsheet.php | 4 +--- src/Bridge/Spout/RowIterator.php | 12 ++++++++---- src/Bridge/Spout/Spreadsheet.php | 4 ++-- src/Bridge/Spout/Test/RowIteratorTest.php | 6 +++--- src/Bridge/Spout/composer.json | 2 +- src/Bridge/Spout/psalm.xml.dist | 5 +++++ src/Xezilaires/Test/Model/Product.php | 5 +++++ src/Xezilaires/psalm.xml.dist | 6 ++++++ 10 files changed, 44 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 59fa69a..1d9e014 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ "matthiasnoback/symfony-dependency-injection-test": "^4.0", "nyholm/nsa": "^1.1", "nyholm/symfony-bundle-test": "dev-master", - "openspout/openspout": "^3.0", + "openspout/openspout": "^4.0", "phpoffice/phpspreadsheet": "^1.18", "phpunit/phpunit": "^9.5", - "sigwin/infra": "^1.0", + "sigwin/infra": "~1.4.1", "symfony/console": "^4.4 || ^5.0 || ^6.0", "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0", "symfony/phpunit-bridge": "^4.4.9 || ^5.0 || ^6.0", diff --git a/psalm.xml.dist b/psalm.xml.dist index 3438d36..4147842 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -17,12 +17,23 @@ + + + + + + + + + + + diff --git a/src/Bridge/PhpSpreadsheet/Spreadsheet.php b/src/Bridge/PhpSpreadsheet/Spreadsheet.php index 2461453..5886ece 100644 --- a/src/Bridge/PhpSpreadsheet/Spreadsheet.php +++ b/src/Bridge/PhpSpreadsheet/Spreadsheet.php @@ -13,7 +13,6 @@ namespace Xezilaires\Bridge\PhpSpreadsheet; -use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Reader\Exception as PhpSpreadsheetReaderException; @@ -147,9 +146,8 @@ private function getActiveWorksheet(): Worksheet private function fetchCell(string $columnName, int $rowIndex) { $worksheet = $this->getActiveWorksheet(); - $columnIndex = Coordinate::columnIndexFromString($columnName); - $cell = $worksheet->getCellByColumnAndRow($columnIndex, $rowIndex); + $cell = $worksheet->getCell($columnName.$rowIndex); /** @var null|float|int|string $value */ $value = $cell->getValue(); diff --git a/src/Bridge/Spout/RowIterator.php b/src/Bridge/Spout/RowIterator.php index 0f84d9e..f1fb5aa 100644 --- a/src/Bridge/Spout/RowIterator.php +++ b/src/Bridge/Spout/RowIterator.php @@ -14,7 +14,7 @@ namespace Xezilaires\Bridge\Spout; use OpenSpout\Common\Entity\Row; -use OpenSpout\Reader\IteratorInterface; +use OpenSpout\Reader\RowIteratorInterface; use Xezilaires\Iterator; /** @@ -22,7 +22,7 @@ */ final class RowIterator implements Iterator { - private IteratorInterface $iterator; + private RowIteratorInterface $iterator; private int $firstRow; @@ -31,7 +31,7 @@ final class RowIterator implements Iterator */ private int $highestRow; - public function __construct(IteratorInterface $iterator, int $firstRow) + public function __construct(RowIteratorInterface $iterator, int $firstRow) { $iterator->rewind(); @@ -44,7 +44,11 @@ public function __construct(IteratorInterface $iterator, int $firstRow) */ public function current(): object { - /** @var Row $row */ + /** + * @var Row $row + * + * @psalm-suppress UnnecessaryVarAnnotation + */ $row = $this->iterator->current(); /** @var array $current */ diff --git a/src/Bridge/Spout/Spreadsheet.php b/src/Bridge/Spout/Spreadsheet.php index f551f83..8af8cb6 100644 --- a/src/Bridge/Spout/Spreadsheet.php +++ b/src/Bridge/Spout/Spreadsheet.php @@ -15,10 +15,10 @@ use OpenSpout\Common\Exception\IOException; use OpenSpout\Common\Exception\UnsupportedTypeException; -use OpenSpout\Reader\Common\Creator\ReaderEntityFactory; use OpenSpout\Reader\Exception\ReaderNotOpenedException; use OpenSpout\Reader\ReaderInterface; use OpenSpout\Reader\SheetInterface; +use OpenSpout\Reader\XLSX\Reader; use Xezilaires\Exception\SpreadsheetException; use Xezilaires\Iterator; use Xezilaires\Spreadsheet as SpreadsheetInterface; @@ -161,7 +161,7 @@ private function getReader(): ReaderInterface } try { - $this->reader = ReaderEntityFactory::createXLSXReader(); + $this->reader = new Reader(); $this->reader->open($path); } catch (UnsupportedTypeException|IOException $exception) { throw SpreadsheetException::invalidSpreadsheet($exception); diff --git a/src/Bridge/Spout/Test/RowIteratorTest.php b/src/Bridge/Spout/Test/RowIteratorTest.php index bc10858..300f055 100644 --- a/src/Bridge/Spout/Test/RowIteratorTest.php +++ b/src/Bridge/Spout/Test/RowIteratorTest.php @@ -13,7 +13,7 @@ namespace Xezilaires\Bridge\Spout\Test; -use OpenSpout\Reader\IteratorInterface; +use OpenSpout\Reader\RowIteratorInterface; use PHPUnit\Framework\TestCase; use Xezilaires\Bridge\Spout\RowIterator; @@ -78,10 +78,10 @@ public function testCanDetermineHighestRowProperly(int $startRow, int $currentRo * @param null|array $counts * @param null|array $calls */ - private function mockIterator(int $currentRow, ?array $counts = null, ?array $calls = null): IteratorInterface + private function mockIterator(int $currentRow, ?array $counts = null, ?array $calls = null): RowIteratorInterface { $iterator = $this - ->getMockBuilder(IteratorInterface::class) + ->getMockBuilder(RowIteratorInterface::class) ->getMock() ; diff --git a/src/Bridge/Spout/composer.json b/src/Bridge/Spout/composer.json index f23aabc..fff062c 100644 --- a/src/Bridge/Spout/composer.json +++ b/src/Bridge/Spout/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": "^8.0", - "openspout/openspout": "^3.0", + "openspout/openspout": "^4.0", "sigwin/xezilaires": "^0.5 || ^0.6" }, "require-dev": { diff --git a/src/Bridge/Spout/psalm.xml.dist b/src/Bridge/Spout/psalm.xml.dist index d6bd97e..523e251 100644 --- a/src/Bridge/Spout/psalm.xml.dist +++ b/src/Bridge/Spout/psalm.xml.dist @@ -12,6 +12,11 @@ + + + + + diff --git a/src/Xezilaires/Test/Model/Product.php b/src/Xezilaires/Test/Model/Product.php index 95aa3b8..24036ff 100644 --- a/src/Xezilaires/Test/Model/Product.php +++ b/src/Xezilaires/Test/Model/Product.php @@ -23,8 +23,11 @@ final class Product { /** * @Groups({"array"}) + * * @XLS\ArrayReference({ + * * @XLS\ColumnReference(column="A"), + * * @XLS\HeaderReference(header="Price USD") * }) */ @@ -32,12 +35,14 @@ final class Product /** * @Groups({"column", "product"}) + * * @XLS\ColumnReference(column="A") */ public string $name; /** * @Groups({"header", "product"}) + * * @XLS\HeaderReference(header="Price USD") */ public float $price; diff --git a/src/Xezilaires/psalm.xml.dist b/src/Xezilaires/psalm.xml.dist index 4b661d4..1c5cd5f 100644 --- a/src/Xezilaires/psalm.xml.dist +++ b/src/Xezilaires/psalm.xml.dist @@ -18,6 +18,12 @@ + + + + + +