Skip to content

Commit

Permalink
bump: openspout/openspout 4.0 (#172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dkarlovi authored Mar 27, 2023
1 parent 1ab3353 commit 6688de1
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@
</projectFiles>

<issueHandlers>
<InternalMethod>
<errorLevel type="info">
<referencedMethod name="OpenSpout\Common\Entity\Row::toArray"/>
</errorLevel>
</InternalMethod>
<MissingConstructor>
<errorLevel type="info">
<directory name="src/Xezilaires/Annotation/"/>
<directory name="src/Xezilaires/Test/Model/"/>
</errorLevel>
</MissingConstructor>
<MissingTemplateParam>
<errorLevel type="info">
<file name="src/Xezilaires/FilterIterator.php"/>
<file name="src/Xezilaires/Iterator.php"/>
</errorLevel>
</MissingTemplateParam>
<RedundantCondition>
<errorLevel type="info">
<file name="src/Xezilaires/Metadata/Annotation/AnnotationDriver.php"/>
Expand Down
4 changes: 1 addition & 3 deletions src/Bridge/PhpSpreadsheet/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/Bridge/Spout/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
namespace Xezilaires\Bridge\Spout;

use OpenSpout\Common\Entity\Row;
use OpenSpout\Reader\IteratorInterface;
use OpenSpout\Reader\RowIteratorInterface;
use Xezilaires\Iterator;

/**
* @internal
*/
final class RowIterator implements Iterator
{
private IteratorInterface $iterator;
private RowIteratorInterface $iterator;

private int $firstRow;

Expand All @@ -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();

Expand All @@ -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<int, null|float|int|string> $current */
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Spout/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Spout/Test/RowIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -78,10 +78,10 @@ public function testCanDetermineHighestRowProperly(int $startRow, int $currentRo
* @param null|array<string, int> $counts
* @param null|array<string, 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()
;

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Spout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.0",
"openspout/openspout": "^3.0",
"openspout/openspout": "^4.0",
"sigwin/xezilaires": "^0.5 || ^0.6"
},
"require-dev": {
Expand Down
5 changes: 5 additions & 0 deletions src/Bridge/Spout/psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
</projectFiles>

<issueHandlers>
<InternalMethod>
<errorLevel type="info">
<referencedMethod name="OpenSpout\Common\Entity\Row::toArray"/>
</errorLevel>
</InternalMethod>
<PropertyNotSetInConstructor>
<errorLevel type="info">
<directory name="Test/"/>
Expand Down
5 changes: 5 additions & 0 deletions src/Xezilaires/Test/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,26 @@ final class Product
{
/**
* @Groups({"array"})
*
* @XLS\ArrayReference({
*
* @XLS\ColumnReference(column="A"),
*
* @XLS\HeaderReference(header="Price USD")
* })
*/
public array $all;

/**
* @Groups({"column", "product"})
*
* @XLS\ColumnReference(column="A")
*/
public string $name;

/**
* @Groups({"header", "product"})
*
* @XLS\HeaderReference(header="Price USD")
*/
public float $price;
Expand Down
6 changes: 6 additions & 0 deletions src/Xezilaires/psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<directory name="Test/" />
</errorLevel>
</MissingConstructor>
<MissingTemplateParam>
<errorLevel type="info">
<file name="FilterIterator.php"/>
<file name="Iterator.php"/>
</errorLevel>
</MissingTemplateParam>
<RedundantCondition>
<errorLevel type="info">
<file name="Metadata/Annotation/AnnotationDriver.php" />
Expand Down

0 comments on commit 6688de1

Please sign in to comment.