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,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)
{