diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5db0f6e..b9f1440 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,28 @@ This will print a diff of proposed code style changes. To apply these suggestion vendor/bin/php-cs-fixer fix --config=.php_cs.dist ``` -### Step 9: Send the pull request +You can also use + +``` +composer phpcs +``` + +### Step 9: Fix phpstan + +Run the following command to analyse source code. +Make sure to fix all errors before submitting a pull request. + +``` +vendor/bin/phpstan analyse +``` + +You can also use + +``` +composer phpstan +``` + +### Step 10: Send the pull request Send the pull request from your feature branch to us. Be sure to include a description that lets us know what work you did. diff --git a/src/Spout/Common/Helper/StringHelper.php b/src/Spout/Common/Helper/StringHelper.php index 6256b1e..84996df 100644 --- a/src/Spout/Common/Helper/StringHelper.php +++ b/src/Spout/Common/Helper/StringHelper.php @@ -16,7 +16,7 @@ class StringHelper /** @var bool Whether the code is running with PHP7 or older versions */ private $isRunningPhp7OrOlder; - /** @var array Locale info, used for number formatting */ + /** @var array Locale info, used for number formatting */ private $localeInfo; /** @@ -93,13 +93,16 @@ class StringHelper public function formatNumericValue($numericValue) { if ($this->isRunningPhp7OrOlder && is_float($numericValue)) { - return str_replace( + /** @var string $replaced */ + $replaced = str_replace( [$this->localeInfo['thousands_sep'], $this->localeInfo['decimal_point']], ['', '.'], - $numericValue + (string) $numericValue ); + + return $replaced; } - return $numericValue; + return (string) $numericValue; } } diff --git a/src/Spout/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php b/src/Spout/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php index 6ccaa29..b808718 100644 --- a/src/Spout/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php +++ b/src/Spout/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php @@ -11,7 +11,14 @@ use Box\Spout\Common\Entity\Style\Style; */ class PossiblyUpdatedStyle { + /** + * @var Style + */ private $style; + + /** + * @var bool + */ private $isUpdated; public function __construct(Style $style, bool $isUpdated) diff --git a/tests/Spout/Writer/ODS/SheetTest.php b/tests/Spout/Writer/ODS/SheetTest.php index 4797406..64b99b1 100644 --- a/tests/Spout/Writer/ODS/SheetTest.php +++ b/tests/Spout/Writer/ODS/SheetTest.php @@ -87,6 +87,7 @@ class SheetTest extends TestCase $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToContentFile = $resourcePath . '#content.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToContentFile); $this->assertStringContainsString(' table:display="false"', $xmlContents, 'The sheet visibility should have been changed to "hidden"'); @@ -162,6 +163,7 @@ class SheetTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToWorkbookFile = $resourcePath . '#content.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToWorkbookFile); $this->assertStringContainsString("table:name=\"$expectedName\"", $xmlContents, $message); diff --git a/tests/Spout/Writer/ODS/WriterTest.php b/tests/Spout/Writer/ODS/WriterTest.php index 4545960..6ad0288 100644 --- a/tests/Spout/Writer/ODS/WriterTest.php +++ b/tests/Spout/Writer/ODS/WriterTest.php @@ -284,19 +284,28 @@ class WriterTest extends TestCase */ public function testAddRowShouldSupportFloatValuesInDifferentLocale() { - $previousLocale = \setlocale(LC_ALL, 0); + /** @var string[] $previousLocale */ + $previousLocale = \setlocale(LC_ALL, '0'); try { // Pick a supported locale whose decimal point is a comma. // Installed locales differ from one system to another, so we can't pick // a given locale. $supportedLocales = explode("\n", shell_exec('locale -a')); + + $commaDecimalPointSupported = false; foreach ($supportedLocales as $supportedLocale) { \setlocale(LC_ALL, $supportedLocale); if (\localeconv()['decimal_point'] === ',') { + $commaDecimalPointSupported = true; break; } } + + if ($commaDecimalPointSupported === false) { + $this->markTestSkipped('System has no local which support comma decimal point'); + } + $this->assertEquals(',', \localeconv()['decimal_point']); $fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx'; @@ -306,8 +315,8 @@ class WriterTest extends TestCase $this->writeToODSFile($dataRows, $fileName); - $this->assertValueWasNotWrittenToSheet($fileName, 1, "1234,5"); - $this->assertValueWasWrittenToSheet($fileName, 1, "1234.5"); + $this->assertValueWasNotWrittenToSheet($fileName, 1, '1234,5'); + $this->assertValueWasWrittenToSheet($fileName, 1, '1234.5'); } finally { // reset locale \setlocale(LC_ALL, $previousLocale); @@ -581,6 +590,7 @@ class WriterTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToContentFile = $resourcePath . '#content.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToContentFile); $this->assertStringContainsString($value, $xmlContents, $message); diff --git a/tests/Spout/Writer/XLSX/SheetTest.php b/tests/Spout/Writer/XLSX/SheetTest.php index a243161..53a3fbe 100644 --- a/tests/Spout/Writer/XLSX/SheetTest.php +++ b/tests/Spout/Writer/XLSX/SheetTest.php @@ -87,6 +87,7 @@ class SheetTest extends TestCase $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToWorkbookFile = $resourcePath . '#xl/workbook.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToWorkbookFile); $this->assertStringContainsString(' state="hidden"', $xmlContents, 'The sheet visibility should have been changed to "hidden"'); @@ -164,6 +165,7 @@ class SheetTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToWorkbookFile = $resourcePath . '#xl/workbook.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToWorkbookFile); $this->assertStringContainsString("markTestSkipped('System has no local which support comma decimal point'); + } + $this->assertEquals(',', \localeconv()['decimal_point']); $fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx'; @@ -422,8 +430,8 @@ class WriterTest extends TestCase $this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false); - $this->assertInlineDataWasNotWrittenToSheet($fileName, 1, "1234,5"); - $this->assertInlineDataWasWrittenToSheet($fileName, 1, "1234.5"); + $this->assertInlineDataWasNotWrittenToSheet($fileName, 1, '1234,5'); + $this->assertInlineDataWasWrittenToSheet($fileName, 1, '1234.5'); } finally { // reset locale \setlocale(LC_ALL, $previousLocale); @@ -643,6 +651,7 @@ class WriterTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToSheetFile); $this->assertStringContainsString((string) $inlineData, $xmlContents, $message); @@ -659,6 +668,7 @@ class WriterTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToSheetFile = $resourcePath . '#xl/worksheets/sheet' . $sheetIndex . '.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToSheetFile); $this->assertStringNotContainsString((string) $inlineData, $xmlContents, $message); @@ -674,6 +684,7 @@ class WriterTest extends TestCase { $resourcePath = $this->getGeneratedResourcePath($fileName); $pathToSharedStringsFile = $resourcePath . '#xl/sharedStrings.xml'; + /** @var string $xmlContents */ $xmlContents = file_get_contents('zip://' . $pathToSharedStringsFile); $this->assertStringContainsString($sharedString, $xmlContents, $message);