From 19293ad30230c9b72f8f6324bbfc32311cc81093 Mon Sep 17 00:00:00 2001 From: "FBGER\\dwinter" Date: Thu, 22 Aug 2024 12:00:59 +0200 Subject: [PATCH 1/4] PHP 8.2 Update Removed Port/Spreadsheet --- composer.json | 14 +++--- src/Reader/XlsxReader.php | 92 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index ab32d58..46bcb01 100644 --- a/composer.json +++ b/composer.json @@ -20,17 +20,17 @@ } ], "require": { - "php": "^7.4|^8.0|^8.1", + "php": ">=8.2", "ext-zlib": "*", "doctrine/persistence": "^2.4|^3.0", "guzzlehttp/guzzle": "^7.5", "portphp/csv": "^2.0", - "portphp/spreadsheet": "^1.0", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/filesystem": "^4.4|^5.0|^6.0", - "symfony/framework-bundle": "^4.4|^5.0|^6.0", - "symfony/string": "^4.4|^5.0|^6.0", - "webmozart/assert" : "^1.11" + "symfony/config": "^6.0", + "symfony/filesystem": "^6.0", + "symfony/framework-bundle": "^6.0", + "symfony/string": "^6.0", + "webmozart/assert" : "^1.11", + "phpoffice/phpspreadsheet": "^2.1" }, "require-dev": { "fastbolt/test-helpers": "^0.1.1", diff --git a/src/Reader/XlsxReader.php b/src/Reader/XlsxReader.php index 90a6460..6e1819f 100644 --- a/src/Reader/XlsxReader.php +++ b/src/Reader/XlsxReader.php @@ -8,13 +8,13 @@ namespace Fastbolt\EntityImporter\Reader; -use Port\Spreadsheet\SpreadsheetReader; +use PhpOffice\PhpSpreadsheet\IOFactory; use SplFileObject; /** * @psalm-suppress PropertyNotSetInConstructor */ -class XlsxReader extends SpreadsheetReader implements ReaderInterface +class XlsxReader implements ReaderInterface { /** * Faulty rows @@ -23,6 +23,33 @@ class XlsxReader extends SpreadsheetReader implements ReaderInterface */ protected ?array $errors = null; + /** + * @var array + */ + protected array $columnHeaders; + + /** + * Total number of rows + * + * @var int + */ + protected int $count; + + /** + * @var int|null + */ + protected ?int $headerRowNumber = null; + + /** + * @var int + */ + protected int $pointer = 0; + + /** + * @var array + */ + protected array $worksheet; + /** * @param SplFileObject $file * @param array $columnHeaders @@ -30,7 +57,12 @@ class XlsxReader extends SpreadsheetReader implements ReaderInterface */ public function __construct(SplFileObject $file, array $columnHeaders, ?int $headerRowNumber) { - parent::__construct($file, $headerRowNumber); + $reader = IOFactory::createReaderForFile($file->getPathName()); + $reader->setReadDataOnly(true); + + $spreadsheet = $reader->load($file->getPathname()); + + $this->worksheet = $spreadsheet->getActiveSheet()->toArray(); if (null !== $headerRowNumber) { $this->setHeaderRowNumber($headerRowNumber); @@ -38,6 +70,11 @@ public function __construct(SplFileObject $file, array $columnHeaders, ?int $hea $this->setColumnHeaders($columnHeaders); } + public function setColumnHeaders(array $columnHeaders): void + { + $this->columnHeaders = $columnHeaders; + } + /** * @inheritDoc */ @@ -61,4 +98,53 @@ public function getErrors(): array /** @psalm-var array> */ return $this->errors; } + + public function current() + { + $row = $this->worksheet[$this->pointer]; + + // If the spreadsheet file has column headers, use them to construct an associative + // array for the columns in this line + if (!empty($this->columnHeaders) && count($this->columnHeaders) === count($row)) { + return array_combine(array_values($this->columnHeaders), $row); + } + + // Else just return the column values + return $row; + } + + public function setHeaderRowNumber(int $rowNumber): void + { + $this->headerRowNumber = $rowNumber; + $this->columnHeaders = $this->worksheet[$rowNumber]; + } + + public function getColumnHeaders(): array + { + return $this->columnHeaders; + } + + public function next(): void + { + $this->pointer++; + } + + public function key(): mixed + { + return $this->pointer; + } + + public function valid(): bool + { + return isset($this->worksheet[$this->pointer]); + } + + public function rewind(): void + { + if (null === $this->headerRowNumber) { + $this->pointer = 0; + } else { + $this->pointer = $this->headerRowNumber + 1; + } + } } From dc9d0ccb27f9e9031b9d155810fe7d28a0619263 Mon Sep 17 00:00:00 2001 From: DWinter Date: Tue, 27 Jan 2026 09:50:04 +0100 Subject: [PATCH 2/4] Allowed Symfony ^7.0 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 46bcb01..05d3d0b 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ "doctrine/persistence": "^2.4|^3.0", "guzzlehttp/guzzle": "^7.5", "portphp/csv": "^2.0", - "symfony/config": "^6.0", - "symfony/filesystem": "^6.0", - "symfony/framework-bundle": "^6.0", - "symfony/string": "^6.0", + "symfony/config": "^6.0|^7.0", + "symfony/filesystem": "^6.0|^7.0", + "symfony/framework-bundle": "^6.0|^7.0", + "symfony/string": "^6.0|^7.0", "webmozart/assert" : "^1.11", "phpoffice/phpspreadsheet": "^2.1" }, From 57ad8d3be8d231b374c08aa5de4d1f52aeccf0c3 Mon Sep 17 00:00:00 2001 From: DWinter Date: Tue, 27 Jan 2026 09:58:41 +0100 Subject: [PATCH 3/4] actions/cache@v3 --- .github/workflows/phpunit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yaml b/.github/workflows/phpunit.yaml index 4ff426d..75fc913 100644 --- a/.github/workflows/phpunit.yaml +++ b/.github/workflows/phpunit.yaml @@ -41,7 +41,7 @@ jobs: - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: vendor key: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}$-${{ hashFiles('**/composer.lock') }} From 61f7b3f2d60b7f189a3fe1422b641dca492707dd Mon Sep 17 00:00:00 2001 From: DWinter Date: Tue, 27 Jan 2026 10:21:03 +0100 Subject: [PATCH 4/4] removed codecov --- .github/workflows/phpunit.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/phpunit.yaml b/.github/workflows/phpunit.yaml index 75fc913..27a8b56 100644 --- a/.github/workflows/phpunit.yaml +++ b/.github/workflows/phpunit.yaml @@ -53,10 +53,3 @@ jobs: - name: Run test suite run: vendor/bin/phpunit ${{ matrix.phpunit-flags }} - - - name: Upload PHPunit coverage - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: true # optional (default = false) - verbose: true # optional (default = false) - flags: unittests