Add phpstan until level 7

This commit is contained in:
Antoine Lamirault committed 2021-09-18 18:09:14 +02:00
1 parent ab973cab34
commit bfb7c2c68f
114 files changed
+527 -319

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ class WriterPerfTest extends TestCase
*/
private function getNumWrittenRows($resourcePath)
{
$lineCountResult = `wc -l $resourcePath`;
$lineCountResult = shell_exec("wc -l $resourcePath");
return (int) $lineCountResult;
}
+7 -3
View File
@@ -69,6 +69,7 @@ class WriterTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$writer = WriterEntityFactory::createCSVWriter();
/* @phpstan-ignore-next-line */
$writer->addRows([['csv--11', 'csv--12']]);
$writer->close();
}
@@ -176,7 +177,7 @@ class WriterTest extends TestCase
$this->assertEquals('#This is, a comma#,csv--12,csv--13', $writtenContent, 'The fields should be enclosed with #');
}
public function testWriteShouldSupportedEscapedCharacters()
public function testWriteShouldSupportedEscapedCharacters() : void
{
$allRows = $this->createRowsFromValues([
['"csv--11"', 'csv--12\\', 'csv--13\\\\', 'csv--14\\\\\\'],
@@ -193,7 +194,7 @@ class WriterTest extends TestCase
* @param string $fieldDelimiter
* @param string $fieldEnclosure
* @param bool $shouldAddBOM
* @return string|null
* @return string
*/
private function writeToCsvFileAndReturnWrittenContent($allRows, $fileName, $fieldDelimiter = ',', $fieldEnclosure = '"', $shouldAddBOM = true)
{
@@ -209,7 +210,10 @@ class WriterTest extends TestCase
$writer->addRows($allRows);
$writer->close();
return file_get_contents($resourcePath);
/** @var string $content */
$content = file_get_contents($resourcePath);
return $content;
}
/**
@@ -25,7 +25,7 @@ class SheetTest extends TestCase
/**
* @param int $sheetIndex
* @param int $associatedWorkbookId
* @param string $associatedWorkbookId
* @return Sheet
*/
private function createSheet($sheetIndex, $associatedWorkbookId)
@@ -57,7 +57,7 @@ class SheetTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForInvalidSheetNames()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class CellHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetColumnLettersFromColumnIndex()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class RowManagerTest extends TestCase
{
/**
* @return array
* @return array<mixed>
*/
public function dataProviderForTestIsEmptyRow()
{
@@ -26,7 +26,7 @@ class RowManagerTest extends TestCase
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param array<Cell> $cells
* @param bool $expectedIsEmpty
* @return void
*/
+1 -1
View File
@@ -95,7 +95,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @param string $sheetName
* @return Sheet
* @return void
*/
private function writeDataAndReturnSheetWithCustomName($fileName, $sheetName)
{
+1 -1
View File
@@ -88,7 +88,7 @@ class WriterPerfTest extends TestCase
copy($pathToContentXmlFile, $tmpFile);
// Get the last 200 characters
$lastCharacters = `tail -c 200 $tmpFile`;
$lastCharacters = shell_exec("tail -c 200 $tmpFile");
// remove the temporary file
unlink($tmpFile);
+7 -3
View File
@@ -280,7 +280,7 @@ class WriterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestAddRowShouldUseNumberColumnsRepeatedForRepeatedValues()
{
@@ -296,7 +296,7 @@ class WriterTest extends TestCase
/**
* @dataProvider dataProviderForTestAddRowShouldUseNumberColumnsRepeatedForRepeatedValues
*
* @param array $dataRow
* @param array<mixed> $dataRow
* @param int $expectedNumTableCells
* @param int $expectedNumColumnsRepeated
* @return void
@@ -306,6 +306,7 @@ class WriterTest extends TestCase
$fileName = 'test_add_row_should_use_number_columns_repeated.ods';
$this->writeToODSFile($this->createRowsFromValues([$dataRow]), $fileName);
/** @var \DOMElement $sheetXmlNode */
$sheetXmlNode = $this->getSheetXmlNode($fileName, 1);
$tableCellNodes = $sheetXmlNode->getElementsByTagName('table-cell');
@@ -589,7 +590,10 @@ class WriterTest extends TestCase
{
$xmlReader = $this->moveReaderToCorrectTableNode($fileName, $sheetIndex);
return $xmlReader->expand();
/** @var \DOMNode $node */
$node = $xmlReader->expand();
return $node;
}
/**
+19 -7
View File
@@ -112,6 +112,7 @@ class WriterWithStyleTest extends TestCase
$this->writeToODSFile([$dataRow], $fileName);
/** @var \DOMElement $textPropertiesElement */
$textPropertiesElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'style:text-properties');
$this->assertEquals(Style::DEFAULT_FONT_SIZE . 'pt', $textPropertiesElement->getAttribute('fo:font-size'));
$this->assertEquals('#' . Style::DEFAULT_FONT_COLOR, $textPropertiesElement->getAttribute('fo:color'));
@@ -351,6 +352,7 @@ class WriterWithStyleTest extends TestCase
$this->writeToODSFileWithDefaultStyle($dataRows, $fileName, $defaultStyle);
/** @var \DOMElement $textPropertiesElement */
$textPropertiesElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'style:text-properties');
$this->assertEquals($defaultFontSize . 'pt', $textPropertiesElement->getAttribute('fo:font-size'));
}
@@ -397,7 +399,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellElementsFromContentXmlFile($fileName)
{
@@ -410,7 +412,9 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('table:table-cell') && $xmlReader->getAttribute('office:value-type') !== null) {
$cellElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellElements[] = $element;
}
}
@@ -421,7 +425,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellStyleElementsFromContentXmlFile($fileName)
{
@@ -434,7 +438,10 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('style:style') && $xmlReader->getAttribute('style:family') === 'table-cell') {
$cellStyleElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellStyleElements[] = $element;
}
}
@@ -456,18 +463,23 @@ class WriterWithStyleTest extends TestCase
$xmlReader->openFileInZip($resourcePath, 'styles.xml');
$xmlReader->readUntilNodeFound($section);
return $xmlReader->expand();
/** @var \DOMNode $node */
$node = $xmlReader->expand();
return $node;
}
/**
* @param string $expectedValue
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @param string $attributeName
* @return void
*/
private function assertFirstChildHasAttributeEquals($expectedValue, $parentElement, $childTagName, $attributeName)
{
$this->assertEquals($expectedValue, $parentElement->getElementsByTagName($childTagName)->item(0)->getAttribute($attributeName));
/** @var \DOMElement $child */
$child = $parentElement->getElementsByTagName($childTagName)->item(0);
$this->assertEquals($expectedValue, $child->getAttribute($attributeName));
}
}
+4 -4
View File
@@ -12,7 +12,7 @@ use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
trait RowCreationHelper
{
/**
* @param array $cellValues
* @param array<mixed> $cellValues
* @return Row
*/
protected function createRowFromValues(array $cellValues)
@@ -21,7 +21,7 @@ trait RowCreationHelper
}
/**
* @param array $cellValues
* @param array<mixed> $cellValues
* @param Style|null $rowStyle
* @return Row
*/
@@ -31,7 +31,7 @@ trait RowCreationHelper
}
/**
* @param array $rowValues
* @param array<array> $rowValues
* @return Row[]
*/
protected function createRowsFromValues(array $rowValues)
@@ -40,7 +40,7 @@ trait RowCreationHelper
}
/**
* @param array $rowValues
* @param array<array> $rowValues
* @param Style|null $rowsStyle
* @return Row[]
*/
@@ -2,6 +2,7 @@
namespace Box\Spout\Writer\XLSX\Manager\Style;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -10,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class StyleManagerTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestShouldApplyStyleOnEmptyCell()
{
@@ -38,6 +39,7 @@ class StyleManagerTest extends TestCase
*/
public function testShouldApplyStyleOnEmptyCell($fillId, $borderId, $expectedResult)
{
/** @var \Box\Spout\Writer\Common\Manager\Style\StyleRegistry&MockObject $styleRegistryMock */
$styleRegistryMock = $this->getMockBuilder(StyleRegistry::class)
->disableOriginalConstructor()
->setMethods(['getFillIdForStyleId', 'getBorderIdForStyleId'])
+3 -3
View File
@@ -15,7 +15,7 @@ class WriterPerfTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestPerfWhenWritingOneMillionRowsXLSX()
{
@@ -102,7 +102,7 @@ class WriterPerfTest extends TestCase
/**
* @param string $filePath
* @return string
* @return int
*/
private function getLasRowNumberForFile($filePath)
{
@@ -135,7 +135,7 @@ class WriterPerfTest extends TestCase
copy($filePath, $tmpFile);
// Get the last 200 characters
$lastCharacters = `tail -c $numCharacters $tmpFile`;
$lastCharacters = shell_exec("tail -c $numCharacters $tmpFile");
// remove the temporary file
unlink($tmpFile);
+1
View File
@@ -120,6 +120,7 @@ class WriterTest extends TestCase
[str_repeat('a', WorksheetManager::MAX_CHARACTERS_PER_CELL + 1)],
];
/* @phpstan-ignore-next-line */
$this->writeToXLSXFile($dataRows, $fileName);
}
@@ -394,10 +394,16 @@ class WriterWithStyleTest extends TestCase
'3 cell xfs present - a default one and two custom ones'
);
$firstCustomId = $styleXfsElements->childNodes->item(1)->getAttribute('fillId');
/** @var \DOMElement $firstItem */
$firstItem = $styleXfsElements->childNodes->item(1);
$firstCustomId = $firstItem->getAttribute('fillId');
$this->assertEquals(2, (int) $firstCustomId, 'The first custom fill id should have the index 2');
$secondCustomId = $styleXfsElements->childNodes->item(2)->getAttribute('fillId');
/** @var \DOMElement $secondItem */
$secondItem = $styleXfsElements->childNodes->item(2);
$secondCustomId = $secondItem->getAttribute('fillId');
$this->assertEquals(2, (int) $secondCustomId, 'The second custom fill id should have the index 2');
}
@@ -468,7 +474,6 @@ class WriterWithStyleTest extends TestCase
$borderParts = $borderNode->childNodes;
$ordering = [];
/** @var \DOMText $part */
foreach ($borderParts as $part) {
if ($part instanceof \DOMElement) {
$ordering[] = $part->nodeName;
@@ -617,6 +622,7 @@ class WriterWithStyleTest extends TestCase
$xmlReader->openFileInZip($resourcePath, 'xl/styles.xml');
$xmlReader->readUntilNodeFound($section);
/** @var \DOMElement $xmlSection */
$xmlSection = $xmlReader->expand();
$xmlReader->close();
@@ -626,7 +632,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellElementsFromSheetXmlFile($fileName)
{
@@ -639,7 +645,9 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('c')) {
$cellElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellElements[] = $element;
}
}
@@ -650,19 +658,21 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $expectedValue
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @param string $attributeName
* @return void
*/
private function assertFirstChildHasAttributeEquals($expectedValue, $parentElement, $childTagName, $attributeName)
{
$this->assertEquals($expectedValue, $parentElement->getElementsByTagName($childTagName)->item(0)->getAttribute($attributeName));
/** @var \DOMElement $child */
$child = $parentElement->getElementsByTagName($childTagName)->item(0);
$this->assertEquals($expectedValue, $child->getAttribute($attributeName));
}
/**
* @param int $expectedNumber
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $message
* @return void
*/
@@ -672,7 +682,7 @@ class WriterWithStyleTest extends TestCase
}
/**
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @return void
*/