Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
vendor/
.php_cs.cache
.phpunit.result.cache
composer.lock
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ sudo: false
matrix:
fast_finish: true
include:
- php: 7.1
env: CS_CHECK=1 STATIC_ANALYSIS=1
- php: 7.2
- php: 7.3
env: CS_CHECK=1 STATIC_ANALYSIS=1
- php: 7.4
env: CODE_COVERAGE=1

cache:
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.3"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpoffice/phpexcel": "^1.8",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpunit/phpunit": "^7.5",
"phpoffice/phpspreadsheet": "^1.10",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
"slam/php-cs-fixer-extensions": "^1.18",
"slam/php-cs-fixer-extensions": "^1.19",
"slam/php-debug-r": "^1.6",
"slam/phpstan-extensions": "^3.6",
"thecodingmachine/phpstan-strict-rules": "^0.11"
"slam/phpstan-extensions": "^4.0",
"thecodingmachine/phpstan-strict-rules": "^0.12"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions lib/Helper/CellStyleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

interface CellStyleInterface
{
/**
* @param mixed $value
*
* @return mixed
*/
public function decorateValue($value);

public function styleCell(Format $format): void;
Expand Down
12 changes: 12 additions & 0 deletions lib/Helper/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

final class Column implements ColumnInterface
{
/**
* @var string
*/
private $key;

/**
* @var string
*/
private $heading;

/**
* @var int
*/
private $width;

/**
* @var CellStyleInterface
*/
private $cellStyle;

public function __construct(string $key, string $heading, int $width, CellStyleInterface $cellStyle)
Expand Down
22 changes: 21 additions & 1 deletion lib/Helper/ColumnCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

final class ColumnCollection implements ColumnCollectionInterface
{
/**
* @var array<string, ColumnInterface>
*/
private $columns = [];

public function __construct(array $columns)
Expand All @@ -17,26 +20,43 @@ public function __construct(array $columns)
}
}

private function addColumn(ColumnInterface $column)
private function addColumn(ColumnInterface $column): void
{
$this->columns[$column->getKey()] = $column;
}

/**
* @param string $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
throw new Exception\RuntimeException('Collection not editable');
}

/**
* @param string $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->columns[$offset]);
}

/**
* @param string $offset
*/
public function offsetUnset($offset)
{
throw new Exception\RuntimeException('Collection not editable');
}

/**
* @param string $offset
*
* @return null|mixed
*/
public function offsetGet($offset)
{
return $this->columns[$offset] ?? null;
Expand Down
61 changes: 60 additions & 1 deletion lib/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,84 @@ final class Table implements Countable
*/
private $activeSheet;

/**
* @var null|int
*/
private $dataRowStart;

/**
* @var int
*/
private $rowStart;

/**
* @var int
*/
private $rowEnd;

/**
* @var int
*/
private $rowCurrent;

/**
* @var int
*/
private $columnStart;

/**
* @var int
*/
private $columnEnd;

/**
* @var int
*/
private $columnCurrent;

/**
* @var string
*/
private $heading;

/**
* @var Iterator
*/
private $data;

/**
* @var null|ColumnCollectionInterface
*/
private $columnCollection;

/**
* @var bool
*/
private $freezePanes = true;
private $fontSize = 8;

/**
* @var int
*/
private $fontSize = 8;

/**
* @var null|int
*/
private $rowHeight;

/**
* @var bool
*/
private $textWrap = false;

/**
* @var null|array
*/
private $writtenColumnTitles;

/**
* @var null|int
*/
private $count;

public function __construct(Worksheet $activeSheet, int $row, int $column, string $heading, Iterator $data)
Expand Down Expand Up @@ -200,6 +256,9 @@ public function setCount(int $count): void
$this->count = $count;
}

/**
* @return null|int
*/
public function count()
{
if (null === $this->count) {
Expand Down
11 changes: 7 additions & 4 deletions lib/Helper/TableWorkbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setEmptyTableMessage(string $emptyTableMessage): void
$this->emptyTableMessage = $emptyTableMessage;
}

public static function getColumnStringFromIndex(int $index)
public static function getColumnStringFromIndex(int $index): string
{
if ($index < 0) {
throw new Excel\Exception\InvalidArgumentException('Column index must be equal or greater than zero');
Expand Down Expand Up @@ -173,7 +173,7 @@ private function writeColumnsHeading(Table $table, array $row): void
$table->flagDataRowStart();
}

private function writeRow(Table $table, array $row, string $type = null): void
private function writeRow(Table $table, array $row, ?string $type = null): void
{
$table->resetColumn();
$sheet = $table->getActiveSheet();
Expand Down Expand Up @@ -212,6 +212,9 @@ private function writeRow(Table $table, array $row, string $type = null): void
$table->incrementRow();
}

/**
* @param mixed $value
*/
private function sanitize($value): string
{
static $sanitizeMap = [
Expand All @@ -225,14 +228,14 @@ private function sanitize($value): string
$value = \str_replace(
\array_keys($sanitizeMap),
\array_values($sanitizeMap),
$value
(string) $value
);
$value = \mb_convert_encoding($value, 'Windows-1252');

return $value;
}

private function generateFormats(Table $table, array $titles, ColumnCollectionInterface $columnCollection = null): void
private function generateFormats(Table $table, array $titles, ?ColumnCollectionInterface $columnCollection = null): void
{
$this->formats = [];
foreach ($titles as $key) {
Expand Down
14 changes: 6 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
includes:
- vendor/phpstan/phpstan/conf/config.levelmax.neon
- phar://phpstan.phar/conf/config.levelmax.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon

parameters:
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
paths:
- lib/
- tests/
excludes_analyse:
- %currentWorkingDirectory%/lib/Pear/*
ignoreErrors:
-
message: '#Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with \d+ and float will always evaluate to false#'
path: %currentWorkingDirectory%/tests/Helper/TableWorkbookTest.php
message: '#Method Slam\\Excel\\Helper\\ColumnCollection::offset.+ has no return typehint specified#'
path: %currentWorkingDirectory%/lib/Helper/ColumnCollection.php
-
message: '#Cannot call method \w+\(\) on PHPExcel_Cell\|null#'
message: '#Cannot call method \w+\(\) on PhpOffice\\PhpSpreadsheet\\Cell\\Cell\|null#'
path: %currentWorkingDirectory%/tests/Helper/TableWorkbookTest.php
-
message: '#Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with .+ and null will always evaluate to false#'
path: %currentWorkingDirectory%/tests/Helper/TableTest.php

19 changes: 13 additions & 6 deletions tests/Helper/ColumnCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

final class ColumnCollectionTest extends TestCase
{
/**
* @var Helper\Column
*/
private $column;

/**
* @var Helper\ColumnCollection
*/
private $collection;

protected function setUp()
protected function setUp(): void
{
$this->column = new Helper\Column('foo', 'Foo', 10, new Helper\CellStyle\Text());

Expand All @@ -22,20 +29,20 @@ protected function setUp()
]);
}

public function testBaseFunctionalities()
public function testBaseFunctionalities(): void
{
static::assertArrayHasKey('foo', $this->collection);
static::assertSame($this->column, $this->collection['foo']);
self::assertArrayHasKey('foo', $this->collection);
self::assertSame($this->column, $this->collection['foo']);
}

public function testNotEditableOnSet()
public function testNotEditableOnSet(): void
{
$this->expectException(Exception\RuntimeException::class);

$this->collection['foo'] = 1;
}

public function testNotEditableOnUnset()
public function testNotEditableOnUnset(): void
{
$this->expectException(Exception\RuntimeException::class);

Expand Down
Loading