Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Commit 9ccc01c

Browse files
authored
Php 7.4 (#5)
* PHPUnit ok * Support PHP 7.4 * Tests: update to PHPOffice\PhpSpreadsheet * Updated PHPStan rules to reflect new library
1 parent 0ba927a commit 9ccc01c

File tree

13 files changed

+235
-120
lines changed

13 files changed

+235
-120
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
12
vendor/
23
.php_cs.cache
4+
.phpunit.result.cache
35
composer.lock

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ sudo: false
55
matrix:
66
fast_finish: true
77
include:
8-
- php: 7.1
9-
env: CS_CHECK=1 STATIC_ANALYSIS=1
10-
- php: 7.2
118
- php: 7.3
9+
env: CS_CHECK=1 STATIC_ANALYSIS=1
10+
- php: 7.4
1211
env: CODE_COVERAGE=1
1312

1413
cache:

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.1"
13+
"php": "^7.3"
1414
},
1515
"require-dev": {
1616
"mikey179/vfsstream": "^1.6",
17-
"phpoffice/phpexcel": "^1.8",
18-
"phpstan/phpstan": "^0.11",
19-
"phpstan/phpstan-phpunit": "^0.11",
20-
"phpunit/phpunit": "^7.5",
17+
"phpoffice/phpspreadsheet": "^1.10",
18+
"phpstan/phpstan": "^0.12",
19+
"phpstan/phpstan-phpunit": "^0.12",
20+
"phpunit/phpunit": "^8.5",
2121
"roave/security-advisories": "dev-master",
22-
"slam/php-cs-fixer-extensions": "^1.18",
22+
"slam/php-cs-fixer-extensions": "^1.19",
2323
"slam/php-debug-r": "^1.6",
24-
"slam/phpstan-extensions": "^3.6",
25-
"thecodingmachine/phpstan-strict-rules": "^0.11"
24+
"slam/phpstan-extensions": "^4.0",
25+
"thecodingmachine/phpstan-strict-rules": "^0.12"
2626
},
2727
"autoload": {
2828
"psr-4": {

lib/Helper/CellStyleInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
interface CellStyleInterface
1010
{
11+
/**
12+
* @param mixed $value
13+
*
14+
* @return mixed
15+
*/
1116
public function decorateValue($value);
1217

1318
public function styleCell(Format $format): void;

lib/Helper/Column.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@
66

77
final class Column implements ColumnInterface
88
{
9+
/**
10+
* @var string
11+
*/
912
private $key;
1013

14+
/**
15+
* @var string
16+
*/
1117
private $heading;
1218

19+
/**
20+
* @var int
21+
*/
1322
private $width;
1423

24+
/**
25+
* @var CellStyleInterface
26+
*/
1527
private $cellStyle;
1628

1729
public function __construct(string $key, string $heading, int $width, CellStyleInterface $cellStyle)

lib/Helper/ColumnCollection.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
final class ColumnCollection implements ColumnCollectionInterface
1010
{
11+
/**
12+
* @var array<string, ColumnInterface>
13+
*/
1114
private $columns = [];
1215

1316
public function __construct(array $columns)
@@ -17,26 +20,43 @@ public function __construct(array $columns)
1720
}
1821
}
1922

20-
private function addColumn(ColumnInterface $column)
23+
private function addColumn(ColumnInterface $column): void
2124
{
2225
$this->columns[$column->getKey()] = $column;
2326
}
2427

28+
/**
29+
* @param string $offset
30+
* @param mixed $value
31+
*/
2532
public function offsetSet($offset, $value)
2633
{
2734
throw new Exception\RuntimeException('Collection not editable');
2835
}
2936

37+
/**
38+
* @param string $offset
39+
*
40+
* @return bool
41+
*/
3042
public function offsetExists($offset)
3143
{
3244
return isset($this->columns[$offset]);
3345
}
3446

47+
/**
48+
* @param string $offset
49+
*/
3550
public function offsetUnset($offset)
3651
{
3752
throw new Exception\RuntimeException('Collection not editable');
3853
}
3954

55+
/**
56+
* @param string $offset
57+
*
58+
* @return null|mixed
59+
*/
4060
public function offsetGet($offset)
4161
{
4262
return $this->columns[$offset] ?? null;

lib/Helper/Table.php

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,84 @@ final class Table implements Countable
1616
*/
1717
private $activeSheet;
1818

19+
/**
20+
* @var null|int
21+
*/
1922
private $dataRowStart;
2023

24+
/**
25+
* @var int
26+
*/
2127
private $rowStart;
28+
29+
/**
30+
* @var int
31+
*/
2232
private $rowEnd;
33+
34+
/**
35+
* @var int
36+
*/
2337
private $rowCurrent;
2438

39+
/**
40+
* @var int
41+
*/
2542
private $columnStart;
43+
44+
/**
45+
* @var int
46+
*/
2647
private $columnEnd;
48+
49+
/**
50+
* @var int
51+
*/
2752
private $columnCurrent;
2853

54+
/**
55+
* @var string
56+
*/
2957
private $heading;
3058

59+
/**
60+
* @var Iterator
61+
*/
3162
private $data;
3263

64+
/**
65+
* @var null|ColumnCollectionInterface
66+
*/
3367
private $columnCollection;
3468

69+
/**
70+
* @var bool
71+
*/
3572
private $freezePanes = true;
36-
private $fontSize = 8;
73+
74+
/**
75+
* @var int
76+
*/
77+
private $fontSize = 8;
78+
79+
/**
80+
* @var null|int
81+
*/
3782
private $rowHeight;
83+
84+
/**
85+
* @var bool
86+
*/
3887
private $textWrap = false;
88+
89+
/**
90+
* @var null|array
91+
*/
3992
private $writtenColumnTitles;
4093

94+
/**
95+
* @var null|int
96+
*/
4197
private $count;
4298

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

259+
/**
260+
* @return null|int
261+
*/
203262
public function count()
204263
{
205264
if (null === $this->count) {

lib/Helper/TableWorkbook.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setEmptyTableMessage(string $emptyTableMessage): void
5151
$this->emptyTableMessage = $emptyTableMessage;
5252
}
5353

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

176-
private function writeRow(Table $table, array $row, string $type = null): void
176+
private function writeRow(Table $table, array $row, ?string $type = null): void
177177
{
178178
$table->resetColumn();
179179
$sheet = $table->getActiveSheet();
@@ -212,6 +212,9 @@ private function writeRow(Table $table, array $row, string $type = null): void
212212
$table->incrementRow();
213213
}
214214

215+
/**
216+
* @param mixed $value
217+
*/
215218
private function sanitize($value): string
216219
{
217220
static $sanitizeMap = [
@@ -225,14 +228,14 @@ private function sanitize($value): string
225228
$value = \str_replace(
226229
\array_keys($sanitizeMap),
227230
\array_values($sanitizeMap),
228-
$value
231+
(string) $value
229232
);
230233
$value = \mb_convert_encoding($value, 'Windows-1252');
231234

232235
return $value;
233236
}
234237

235-
private function generateFormats(Table $table, array $titles, ColumnCollectionInterface $columnCollection = null): void
238+
private function generateFormats(Table $table, array $titles, ?ColumnCollectionInterface $columnCollection = null): void
236239
{
237240
$this->formats = [];
238241
foreach ($titles as $key) {

phpstan.neon

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
includes:
2-
- vendor/phpstan/phpstan/conf/config.levelmax.neon
2+
- phar://phpstan.phar/conf/config.levelmax.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
55
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon
66

77
parameters:
8+
checkGenericClassInNonGenericObjectType: false
9+
checkMissingIterableValueType: false
810
paths:
911
- lib/
1012
- tests/
1113
excludes_analyse:
1214
- %currentWorkingDirectory%/lib/Pear/*
1315
ignoreErrors:
1416
-
15-
message: '#Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with \d+ and float will always evaluate to false#'
16-
path: %currentWorkingDirectory%/tests/Helper/TableWorkbookTest.php
17+
message: '#Method Slam\\Excel\\Helper\\ColumnCollection::offset.+ has no return typehint specified#'
18+
path: %currentWorkingDirectory%/lib/Helper/ColumnCollection.php
1719
-
18-
message: '#Cannot call method \w+\(\) on PHPExcel_Cell\|null#'
20+
message: '#Cannot call method \w+\(\) on PhpOffice\\PhpSpreadsheet\\Cell\\Cell\|null#'
1921
path: %currentWorkingDirectory%/tests/Helper/TableWorkbookTest.php
20-
-
21-
message: '#Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with .+ and null will always evaluate to false#'
22-
path: %currentWorkingDirectory%/tests/Helper/TableTest.php
23-

tests/Helper/ColumnCollectionTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010

1111
final class ColumnCollectionTest extends TestCase
1212
{
13+
/**
14+
* @var Helper\Column
15+
*/
1316
private $column;
17+
18+
/**
19+
* @var Helper\ColumnCollection
20+
*/
1421
private $collection;
1522

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

@@ -22,20 +29,20 @@ protected function setUp()
2229
]);
2330
}
2431

25-
public function testBaseFunctionalities()
32+
public function testBaseFunctionalities(): void
2633
{
27-
static::assertArrayHasKey('foo', $this->collection);
28-
static::assertSame($this->column, $this->collection['foo']);
34+
self::assertArrayHasKey('foo', $this->collection);
35+
self::assertSame($this->column, $this->collection['foo']);
2936
}
3037

31-
public function testNotEditableOnSet()
38+
public function testNotEditableOnSet(): void
3239
{
3340
$this->expectException(Exception\RuntimeException::class);
3441

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

38-
public function testNotEditableOnUnset()
45+
public function testNotEditableOnUnset(): void
3946
{
4047
$this->expectException(Exception\RuntimeException::class);
4148

0 commit comments

Comments
 (0)