{
/**
* Table headers.
- *
- * @var array
*/
private $headers = array();
/**
* Table rows.
- *
- * @var array
*/
private $rows = array();
/**
* Column widths cache.
- *
- * @var array
*/
private $effectiveColumnWidths = array();
/**
* Number of columns cache.
*
- * @var array
+ * @var int
*/
private $numberOfColumns;
* Renders table to output.
*
* Example:
+ * <code>
* +---------------+-----------------------+------------------+
* | ISBN | Title | Author |
* +---------------+-----------------------+------------------+
* | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
* | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
* +---------------+-----------------------+------------------+
+ * </code>
*/
public function render()
{
/**
* Renders horizontal header separator.
*
- * Example: +-----+-----------+-------+
+ * Example: <code>+-----+-----------+-------+</code>
*/
private function renderRowSeparator()
{
/**
* Renders table row.
*
- * Example: | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
+ * Example: <code>| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |</code>
*
* @param array $row
* @param string $cellFormat
* @param int $line
*
* @return array
+ *
+ * @throws InvalidArgumentException
*/
- private function fillNextRows($rows, $line)
+ private function fillNextRows(array $rows, $line)
{
$unmergedRows = array();
foreach ($rows[$line] as $column => $cell) {
+ if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(is_object($cell) && method_exists($cell, '__toString'))) {
+ throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing __toString, %s given.', gettype($cell)));
+ }
if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
$nbLines = $cell->getRowspan() - 1;
$lines = array($cell);
/**
* fill cells for a row that contains colspan > 1.
*
- * @param array $row
- *
* @return array
*/
private function fillCells($row)
*
* @return array
*/
- private function copyRow($rows, $line)
+ private function copyRow(array $rows, $line)
{
$row = $rows[$line];
foreach ($row as $cellKey => $cellValue) {
/**
* Gets number of columns by row.
*
- * @param array $row
- *
* @return int
*/
private function getNumberOfColumns(array $row)
/**
* Gets list of columns for the given row.
*
- * @param array $row
- *
* @return array
*/
- private function getRowColumns($row)
+ private function getRowColumns(array $row)
{
$columns = range(0, $this->numberOfColumns - 1);
foreach ($row as $cellKey => $cell) {
/**
* Calculates columns widths.
- *
- * @param array $rows
*/
- private function calculateColumnsWidth($rows)
+ private function calculateColumnsWidth(array $rows)
{
for ($column = 0; $column < $this->numberOfColumns; ++$column) {
$lengths = array();