From 5fa9154bfa0e65ec26d86157db4d9a5dc173fce5 Mon Sep 17 00:00:00 2001 From: madflow Date: Thu, 8 Feb 2018 12:24:24 +0100 Subject: [PATCH] added Row::getCellAtIndex method --- src/Spout/Common/Entity/Row.php | 12 ++++++++++-- tests/Spout/Common/Entity/RowTest.php | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Spout/Common/Entity/Row.php b/src/Spout/Common/Entity/Row.php index a4e5aff..abf610a 100644 --- a/src/Spout/Common/Entity/Row.php +++ b/src/Spout/Common/Entity/Row.php @@ -54,8 +54,7 @@ class Row /** * @param Cell $cell - * @param mixed $cellIndex - * @parma int $cellIndex + * @param int $cellIndex * @return Row */ public function setCellAtIndex(Cell $cell, $cellIndex) @@ -65,6 +64,15 @@ class Row return $this; } + /** + * @param int $cellIndex + * @return Cell|null + */ + public function getCellAtIndex($cellIndex) + { + return isset($this->cells[$cellIndex]) ? $this->cells[$cellIndex] : null; + } + /** * @param Cell $cell * @return Row diff --git a/tests/Spout/Common/Entity/RowTest.php b/tests/Spout/Common/Entity/RowTest.php index ead2e74..2325412 100644 --- a/tests/Spout/Common/Entity/RowTest.php +++ b/tests/Spout/Common/Entity/RowTest.php @@ -70,6 +70,18 @@ class RowTest extends \PHPUnit\Framework\TestCase $this->assertEquals(2, $row->getNumCells()); } + /** + * @return void + */ + public function testGetCellAtIndex() + { + $row = new Row([], null); + $cellMock = $this->getCellMock(); + $row->setCellAtIndex($cellMock, 3); + $this->assertEquals($cellMock, $row->getCellAtIndex(3)); + $this->assertNull($row->getCellAtIndex(10)); + } + /** * @return void */