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

+11 -9
View File
@@ -6,11 +6,13 @@ use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\CSV\Manager\OptionsManager;
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
use Box\Spout\Reader\ReaderInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -47,7 +49,7 @@ class ReaderTest extends TestCase
{
$this->expectException(IOException::class);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['is_readable'])
->getMock();
@@ -66,7 +68,7 @@ class ReaderTest extends TestCase
{
$this->expectException(IOException::class);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['fopen'])
->getMock();
@@ -159,7 +161,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldReadEmptyFile()
{
@@ -241,7 +243,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldSkipBom()
{
@@ -274,7 +276,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldSupportNonUTF8FilesWithoutBOMs()
{
@@ -302,7 +304,7 @@ class ReaderTest extends TestCase
$allRows = [];
$resourcePath = $this->getResourcePath($fileName);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['function_exists'])
->getMock();
@@ -475,8 +477,8 @@ class ReaderTest extends TestCase
}
/**
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper|null $optionsManager
* @param \Box\Spout\Common\Manager\OptionsManagerInterface|null $globalFunctionsHelper
* @param OptionsManagerInterface|null $optionsManager
* @param GlobalFunctionsHelper|null $globalFunctionsHelper
* @return ReaderInterface
*/
private function createCSVReader($optionsManager = null, $globalFunctionsHelper = null)
@@ -494,7 +496,7 @@ class ReaderTest extends TestCase
* @param string $fieldEnclosure
* @param string $encoding
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile(
$fileName,
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -27,7 +28,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet
* @return SheetInterface
*/
private function openFileAndReturnSheet($fileName)
{
+16 -6
View File
@@ -14,22 +14,25 @@ class SpoutTestStream
const PATH_TO_CSV_RESOURCES = 'tests/resources/csv/';
const CSV_EXTENSION = '.csv';
/** @var int $position */
/** @var int */
private $position;
/** @var resource $fileHandle */
/** @var resource */
private $fileHandle;
/**
* @param string $path
* @param int $flag
* @return array
* @return array<mixed>
*/
public function url_stat($path, $flag)
{
$filePath = $this->getFilePathFromStreamPath($path);
return stat($filePath);
/** @var array<mixed> $stat */
$stat = stat($filePath);
return $stat;
}
/**
@@ -56,7 +59,11 @@ class SpoutTestStream
// the path is like "spout://csv_name" so the actual file name correspond the name of the host.
$filePath = $this->getFilePathFromStreamPath($path);
$this->fileHandle = fopen($filePath, $mode);
/** @var resource $fileHandle */
$fileHandle = fopen($filePath, $mode);
$this->fileHandle = $fileHandle;
return true;
}
@@ -69,7 +76,10 @@ class SpoutTestStream
{
$this->position += $numBytes;
return fread($this->fileHandle, $numBytes);
/** @var string $read */
$read = fread($this->fileHandle, $numBytes);
return $read;
}
/**
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
class RowManagerTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFillMissingIndexesWithEmptyCells()
{
@@ -34,7 +34,7 @@ class RowManagerTest extends TestCase
* @param Cell[]|null $rowCells
* @param Cell[] $expectedFilledCells
*/
public function testFillMissingIndexesWithEmptyCells($rowCells, $expectedFilledCells)
public function testFillMissingIndexesWithEmptyCells($rowCells, $expectedFilledCells) : void
{
$rowManager = $this->createRowManager();
@@ -48,7 +48,7 @@ class RowManagerTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestIsEmptyRow()
{
@@ -64,7 +64,7 @@ class RowManagerTest extends TestCase
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param array<Cell> $cells
* @param bool $expectedIsEmpty
* @return void
*/
@@ -81,10 +81,13 @@ class RowManagerTest extends TestCase
*/
private function createRowManager()
{
$entityFactory = new InternalEntityFactory(
$this->createMock(ManagerFactory::class),
$this->createMock(HelperFactory::class)
);
/** @var ManagerFactory $managerFactory */
$managerFactory = $this->createMock(ManagerFactory::class);
/** @var HelperFactory $helperFactory */
$helperFactory = $this->createMock(HelperFactory::class);
$entityFactory = new InternalEntityFactory($managerFactory, $helperFactory);
return new RowManager($entityFactory);
}
+4 -4
View File
@@ -16,7 +16,7 @@ class ReaderTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldThrowException()
{
@@ -41,7 +41,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadForAllWorksheets()
{
@@ -109,7 +109,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadWithFilesGeneratedByExternalSoftwares()
{
@@ -530,7 +530,7 @@ class ReaderTest extends TestCase
* @param string $fileName
* @param bool $shouldFormatDates
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false)
{
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\ODS;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -55,7 +56,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet[]
* @return SheetInterface[]
*/
private function openFileAndReturnSheets($fileName)
{
+4 -3
View File
@@ -102,7 +102,7 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFileExistsWithinZip()
{
@@ -134,10 +134,11 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetRealPathURIForFileInZip()
{
/** @var string $tempFolder */
$tempFolder = realpath(sys_get_temp_dir());
$tempFolderName = basename($tempFolder);
$expectedRealPathURI = 'zip://' . $tempFolder . '/test.xlsx#test.xml';
@@ -174,7 +175,7 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestIsPositionedOnStartingAndEndingNode()
{
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class CellHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetColumnIndexFromCellIndex()
{
@@ -4,7 +4,9 @@ namespace Box\Spout\Reader\XLSX\Helper;
use Box\Spout\Common\Helper\Escaper;
use Box\Spout\Reader\Exception\InvalidValueException;
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
use Box\Spout\Reader\XLSX\Manager\StyleManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -13,7 +15,7 @@ use PHPUnit\Framework\TestCase;
class CellValueFormatterTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestExcelDate()
{
@@ -72,6 +74,7 @@ class CellValueFormatterTest extends TestCase
->with(0)
->will($this->returnValue((object) ['nodeValue' => $nodeValue]));
/** @var \DOMElement&MockObject $nodeMock */
$nodeMock = $this->createMock(\DOMElement::class);
$nodeMock
@@ -88,7 +91,7 @@ class CellValueFormatterTest extends TestCase
->with(CellValueFormatter::XML_NODE_VALUE)
->will($this->returnValue($nodeListMock));
/** @var StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */
/** @var StyleManager&MockObject $styleManagerMock */
$styleManagerMock = $this->createMock(StyleManager::class);
$styleManagerMock
@@ -97,7 +100,10 @@ class CellValueFormatterTest extends TestCase
->with(123)
->will($this->returnValue(true));
$formatter = new CellValueFormatter(null, $styleManagerMock, false, $shouldUse1904Dates, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManagerMock, false, $shouldUse1904Dates, new Escaper\XLSX());
try {
$result = $formatter->extractAndFormatNodeValue($nodeMock);
@@ -106,7 +112,9 @@ class CellValueFormatterTest extends TestCase
$this->fail('An exception should have been thrown');
} else {
$this->assertInstanceOf(\DateTime::class, $result);
$this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s'));
/** @var \DateTime $datetime */
$datetime = $result;
$this->assertSame($expectedDateAsString, $datetime->format('Y-m-d H:i:s'));
}
} catch (InvalidValueException $exception) {
// do nothing
@@ -114,7 +122,7 @@ class CellValueFormatterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFormatNumericCellValueWithNumbers()
{
@@ -149,14 +157,17 @@ class CellValueFormatterTest extends TestCase
*/
public function testFormatNumericCellValueWithNumbers($value, $expectedFormattedValue, $expectedType)
{
/** @var StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */
/** @var StyleManager&MockObject $styleManagerMock */
$styleManagerMock = $this->createMock(StyleManager::class);
$styleManagerMock
->expects($this->once())
->method('shouldFormatNumericValueAsDate')
->will($this->returnValue(false));
$formatter = new CellValueFormatter(null, $styleManagerMock, false, false, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManagerMock, false, false, new Escaper\XLSX());
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatNumericCellValue', $value, 0);
$this->assertEquals($expectedFormattedValue, $formattedValue);
@@ -164,7 +175,7 @@ class CellValueFormatterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFormatStringCellValue()
{
@@ -199,7 +210,13 @@ class CellValueFormatterTest extends TestCase
->with(CellValueFormatter::XML_NODE_INLINE_STRING_VALUE)
->will($this->returnValue($nodeListMock));
$formatter = new CellValueFormatter(null, null, false, false, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
/** @var StyleManager $styleManager */
$styleManager = $this->createMock(StyleManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManager, false, false, new Escaper\XLSX());
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatInlineStringCellValue', $nodeMock);
$this->assertEquals($expectedFormattedValue, $formattedValue);
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class DateFormatHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestToPHPDateFormat()
{
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -11,7 +12,7 @@ use PHPUnit\Framework\TestCase;
class CachingStrategyFactoryTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestCreateBestCachingStrategy()
{
@@ -36,7 +37,7 @@ class CachingStrategyFactoryTest extends TestCase
*/
public function testCreateBestCachingStrategy($sharedStringsUniqueCount, $memoryLimitInKB, $expectedStrategyClassName)
{
/** @var CachingStrategyFactory|\PHPUnit_Framework_MockObject_MockObject $factoryStub */
/** @var CachingStrategyFactory&MockObject $factoryStub */
$factoryStub = $this
->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory')
->disableOriginalConstructor()
@@ -46,7 +47,7 @@ class CachingStrategyFactoryTest extends TestCase
$factoryStub->method('getMemoryLimitInKB')->willReturn($memoryLimitInKB);
$tempFolder = sys_get_temp_dir();
$helperFactory = new HelperFactory($factoryStub);
$helperFactory = new HelperFactory();
$strategy = $factoryStub->createBestCachingStrategy($sharedStringsUniqueCount, $tempFolder, $helperFactory);
$fullExpectedStrategyClassName = 'Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\\' . $expectedStrategyClassName;
@@ -56,7 +57,7 @@ class CachingStrategyFactoryTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetMemoryLimitInKB()
{
@@ -84,7 +85,7 @@ class CachingStrategyFactoryTest extends TestCase
*/
public function testGetMemoryLimitInKB($memoryLimitFormatted, $expectedMemoryLimitInKB)
{
/** @var CachingStrategyFactory|\PHPUnit_Framework_MockObject_MockObject $factoryStub */
/** @var CachingStrategyFactory&MockObject $factoryStub */
$factoryStub = $this
->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory')
->disableOriginalConstructor()
@@ -19,7 +19,7 @@ class SharedStringsManagerTest extends TestCase
{
use TestUsingResource;
/** @var SharedStringsManager */
/** @var SharedStringsManager|null */
private $sharedStringsManager;
/**
@@ -144,6 +144,7 @@ class SharedStringsManagerTest extends TestCase
public function testGetStringAtIndexWithFileBasedStrategy()
{
// force the file-based strategy by setting no memory limit
/** @var string $originalMemoryLimit */
$originalMemoryLimit = ini_get('memory_limit');
ini_set('memory_limit', '-1');
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -11,8 +12,8 @@ use PHPUnit\Framework\TestCase;
class StyleManagerTest extends TestCase
{
/**
* @param array $styleAttributes
* @param array $customNumberFormats
* @param array<mixed> $styleAttributes
* @param array<mixed> $customNumberFormats
* @return StyleManager
*/
private function getStyleManagerMock($styleAttributes = [], $customNumberFormats = [])
@@ -21,7 +22,7 @@ class StyleManagerTest extends TestCase
$workbookRelationshipsManager = $this->createMock(WorkbookRelationshipsManager::class);
$workbookRelationshipsManager->method('hasStylesXMLFile')->willReturn(true);
/** @var StyleManager $styleManager */
/** @var StyleManager&MockObject $styleManager */
$styleManager = $this->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\StyleManager')
->setConstructorArgs(['/path/to/file.xlsx', $workbookRelationshipsManager, $entityFactory])
->setMethods(['getCustomNumberFormats', 'getStylesAttributes'])
@@ -132,7 +133,7 @@ class StyleManagerTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForCustomDateFormats()
{
+1 -1
View File
@@ -15,7 +15,7 @@ class ReaderPerfTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestPerfWhenReading300kRowsXLSX()
{
+3 -3
View File
@@ -15,7 +15,7 @@ class ReaderTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldThrowException()
{
@@ -42,7 +42,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadForAllWorksheets()
{
@@ -703,7 +703,7 @@ class ReaderTest extends TestCase
* @param string $fileName
* @param bool $shouldFormatDates
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false)
{
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -43,7 +44,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet[]
* @return SheetInterface[]
*/
private function openFileAndReturnSheets($fileName)
{