mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-20 15:16:36 +00:00
Phpstan Tweaks
Phpstan level 10 reports an enormous number of errors. So does the excluded missingType.iterableValue. I do not plan to introduce either any time soon. But I will submit piecemeal changes from time to time. Changes will be mostly limited to phpdoc type declarations.
This commit is contained in:
@@ -87,7 +87,7 @@ jobs:
|
||||
|
||||
# This is non-ideal because it only checks for the last commit of the PR, not all of them, but better than nothing
|
||||
- name: Check PHPDoc types
|
||||
run: ./bin/check-phpdoc-types
|
||||
run: ./bin/check-phpdoc-types.php
|
||||
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->exclude('vendor')
|
||||
->exclude('vendor', 'docs', '.git', '.github')
|
||||
->notPath('src/PhpSpreadsheet/Writer/ZipStream3.php')
|
||||
->name('/(\.php|^generate-document|^generate-locales|^check-phpdoc-types)$/')
|
||||
->in(__DIR__);
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
|
||||
+1
-6
@@ -6,12 +6,7 @@
|
||||
<file>src</file>
|
||||
<file>tests</file>
|
||||
<file>infra</file>
|
||||
<file>bin/generate-document</file>
|
||||
<file>bin/generate-locales</file>
|
||||
<file>bin/check-phpdoc-types</file>
|
||||
|
||||
<exclude-pattern>samples/Header.php</exclude-pattern>
|
||||
<exclude-pattern>*/tests/Core/*/*Test\.(inc|css|js)$</exclude-pattern>
|
||||
<file>bin</file>
|
||||
|
||||
<arg name="report-width" value="200"/>
|
||||
<arg name="parallel" value="80"/>
|
||||
|
||||
Executable → Regular
Executable → Regular
+1
-1
@@ -4,7 +4,7 @@
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||
use PhpOffice\PhpSpreadsheetInfra\DocumentGenerator;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once __DIR__ . '/..' . '/vendor/autoload.php';
|
||||
|
||||
$phpSpreadsheetFunctions = Calculation::getFunctions();
|
||||
ksort($phpSpreadsheetFunctions);
|
||||
@@ -4,7 +4,7 @@
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||
use PhpOffice\PhpSpreadsheetInfra\LocaleGenerator;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once __DIR__ . '/..' . '/vendor/autoload.php';
|
||||
|
||||
$phpSpreadsheetFunctions = Calculation::getFunctions();
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ if [ "$files" != "" ]; then
|
||||
fi
|
||||
|
||||
# Check PHPDoc types
|
||||
./bin/check-phpdoc-types
|
||||
./bin/check-phpdoc-types.php
|
||||
if [ $? -ne 0 ]; then
|
||||
pass=false
|
||||
fi
|
||||
|
||||
@@ -33,11 +33,19 @@ class DocumentGenerator
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private static function getCategories(): array
|
||||
{
|
||||
return (new ReflectionClass(Category::class))->getConstants();
|
||||
/** @var array<string, string> */
|
||||
$x = (new ReflectionClass(Category::class))->getConstants();
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $lengths
|
||||
* @param null|array<int, int|string> $values
|
||||
*/
|
||||
private static function tableRow(array $lengths, ?array $values = null): string
|
||||
{
|
||||
$result = '';
|
||||
@@ -46,7 +54,7 @@ class DocumentGenerator
|
||||
if ($i > 0) {
|
||||
$result .= '|' . $pad;
|
||||
}
|
||||
$result .= str_pad($value ?? '', $length, $pad);
|
||||
$result .= str_pad("$value", $length ?? 0, $pad);
|
||||
}
|
||||
|
||||
return rtrim($result, ' ');
|
||||
@@ -71,7 +79,7 @@ class DocumentGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array[] $phpSpreadsheetFunctions
|
||||
* @param array<string, array<string, int|string>> $phpSpreadsheetFunctions
|
||||
*/
|
||||
public static function generateFunctionListByName(array $phpSpreadsheetFunctions): string
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ class LocaleGenerator
|
||||
|
||||
protected string $translationBaseFolder;
|
||||
|
||||
/** @var string[] */
|
||||
protected array $phpSpreadsheetFunctions;
|
||||
|
||||
protected Spreadsheet $translationSpreadsheet;
|
||||
@@ -38,16 +39,23 @@ class LocaleGenerator
|
||||
|
||||
protected Worksheet $localeTranslations;
|
||||
|
||||
/** @var string[] */
|
||||
protected array $localeLanguageMap = [];
|
||||
|
||||
/** @var array<string, int> */
|
||||
protected array $errorCodeMap = [];
|
||||
|
||||
private Worksheet $functionNameTranslations;
|
||||
|
||||
/** @var string[] */
|
||||
protected array $functionNameLanguageMap = [];
|
||||
|
||||
/** @var array<string, int|string> */
|
||||
protected array $functionNameMap = [];
|
||||
|
||||
/**
|
||||
* @param string[] $phpSpreadsheetFunctions
|
||||
*/
|
||||
public function __construct(
|
||||
string $translationBaseFolder,
|
||||
string $translationSpreadsheetName,
|
||||
@@ -268,6 +276,7 @@ class LocaleGenerator
|
||||
return $worksheet;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
protected function mapLanguageColumns(Worksheet $translationWorksheet): array
|
||||
{
|
||||
$sheetName = $translationWorksheet->getTitle();
|
||||
@@ -282,7 +291,7 @@ class LocaleGenerator
|
||||
$cells->setIterateOnlyExistingCells(true);
|
||||
foreach ($cells as $cell) {
|
||||
if ($this->localeCanBeSupported($translationWorksheet, $cell)) {
|
||||
$languageNameMap[$cell->getColumn()] = $cell->getValue();
|
||||
$languageNameMap[$cell->getColumn()] = $cell->getValueString();
|
||||
$this->log($cell->getColumn() . ' -> ' . $cell->getValueString());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -13,9 +13,7 @@ parameters:
|
||||
- src/
|
||||
- tests/
|
||||
- infra/
|
||||
- bin/generate-document
|
||||
- bin/generate-locales
|
||||
- bin/check-phpdoc-types
|
||||
- bin/
|
||||
excludePaths:
|
||||
- src/PhpSpreadsheet/Chart/Renderer/JpGraph.php
|
||||
- src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
|
||||
|
||||
@@ -22,6 +22,7 @@ $spreadsheet->getProperties()
|
||||
->setKeywords('Office PhpSpreadsheet php')
|
||||
->setCategory('Test result file');
|
||||
|
||||
/** @return array<int, string> */
|
||||
function transpose(string $value): array
|
||||
{
|
||||
return [$value];
|
||||
|
||||
@@ -338,6 +338,7 @@ $spreadsheet->setActiveSheetIndex(1);
|
||||
$helper->write($spreadsheet, __FILE__, ['Xlsx'], true, resetActiveSheet: false);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
|
||||
/** return array{'min': float|int, 'max': float|int} */
|
||||
function dateRange(int $nrows, Spreadsheet $wrkbk): array
|
||||
{
|
||||
$dataSheet = $wrkbk->getSheetByNameOrThrow('Data');
|
||||
|
||||
@@ -40,6 +40,7 @@ setYearlyData($worksheet, '2020', $data2020);
|
||||
$worksheet = $spreadsheet->addSheet(new Worksheet($spreadsheet));
|
||||
setYearlyData($worksheet, '2020', [], 'GROWTH');
|
||||
|
||||
/** @param array<int, array<int, int>> $yearlyData */
|
||||
function setYearlyData(Worksheet $worksheet, string $year, array $yearlyData, ?string $title = null): void
|
||||
{
|
||||
// Set up some basic data
|
||||
|
||||
@@ -16,7 +16,7 @@ class Mpdf2 extends Mpdf
|
||||
* be used by Mpdf (which would instead use a default substitution).
|
||||
* Other configuration options may be specified here.
|
||||
*
|
||||
* @param array $config Configuration array
|
||||
* @param array<string, mixed> $config Configuration array
|
||||
*/
|
||||
protected function createExternalWriterInstance($config): \Mpdf\Mpdf
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ $sheetname = 'Data Sheet #3';
|
||||
|
||||
class MyReadFilter implements IReadFilter
|
||||
{
|
||||
/** @param array<int, string> $columns */
|
||||
public function __construct(
|
||||
private int $startRow,
|
||||
private int $endRow,
|
||||
|
||||
@@ -110,6 +110,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder
|
||||
return parent::bindValue($cell, $value);
|
||||
}
|
||||
|
||||
/** @param array{0: non-falsy-string, 1: ?string, 2: numeric-string, 3: numeric-string, 4: numeric-string} $matches */
|
||||
protected function setImproperFraction(array $matches, Cell $cell): bool
|
||||
{
|
||||
// Convert value to number
|
||||
@@ -130,6 +131,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param array{0: non-falsy-string, 1: ?string, 2: numeric-string, 3: numeric-string} $matches */
|
||||
protected function setProperFraction(array $matches, Cell $cell): bool
|
||||
{
|
||||
// Convert value to number
|
||||
|
||||
@@ -135,6 +135,7 @@ class Theme
|
||||
'Geor' => 'Sylfaen',
|
||||
];
|
||||
|
||||
/** @return string[] */
|
||||
public function getThemeColors(): array
|
||||
{
|
||||
return $this->themeColors;
|
||||
@@ -152,6 +153,7 @@ class Theme
|
||||
return $this->themeColorName;
|
||||
}
|
||||
|
||||
/** @param null|string[] $themeColors */
|
||||
public function setThemeColorName(string $name, ?array $themeColors = null): self
|
||||
{
|
||||
$this->themeColorName = $name;
|
||||
@@ -182,11 +184,13 @@ class Theme
|
||||
return $this->majorFontComplexScript;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getMajorFontSubstitutions(): array
|
||||
{
|
||||
return $this->majorFontSubstitutions;
|
||||
}
|
||||
|
||||
/** @param null|string[] $substitutions */
|
||||
public function setMajorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self
|
||||
{
|
||||
if (!empty($latin)) {
|
||||
@@ -220,11 +224,13 @@ class Theme
|
||||
return $this->minorFontComplexScript;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getMinorFontSubstitutions(): array
|
||||
{
|
||||
return $this->minorFontSubstitutions;
|
||||
}
|
||||
|
||||
/** @param null|string[] $substitutions */
|
||||
public function setMinorFontValues(?string $latin, ?string $eastAsian, ?string $complexScript, ?array $substitutions): self
|
||||
{
|
||||
if (!empty($latin)) {
|
||||
|
||||
@@ -158,6 +158,8 @@ class Worksheet
|
||||
|
||||
/**
|
||||
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
|
||||
*
|
||||
* @var Conditional[][]
|
||||
*/
|
||||
private array $conditionalStylesCollection = [];
|
||||
|
||||
@@ -1558,6 +1560,8 @@ class Worksheet
|
||||
|
||||
/**
|
||||
* Get collection of conditional styles.
|
||||
*
|
||||
* @return Conditional[][]
|
||||
*/
|
||||
public function getConditionalStylesCollection(): array
|
||||
{
|
||||
|
||||
@@ -488,7 +488,7 @@ class Html extends BaseWriter
|
||||
foreach ($condStylesCollection as $condStyles) {
|
||||
foreach ($condStyles as $key => $cs) {
|
||||
if ($cs->getConditionType() === Conditional::CONDITION_COLORSCALE) {
|
||||
$cs->getColorScale()->setScaleArray();
|
||||
$cs->getColorScale()?->setScaleArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,14 @@ class Issue4049Test extends AbstractFunctional
|
||||
$colorScale = $cond1[0]->getColorScale();
|
||||
self::assertNotNull($colorScale);
|
||||
$min = $colorScale->getMinimumConditionalFormatValueObject();
|
||||
self::assertNotNull($min);
|
||||
self::assertSame('formula', $min->getType());
|
||||
self::assertSame('25', $min->getCellFormula());
|
||||
|
||||
self::assertNull($colorScale->getMidpointConditionalFormatValueObject());
|
||||
|
||||
$max = $colorScale->getMaximumConditionalFormatValueObject();
|
||||
self::assertNotNull($max);
|
||||
self::assertSame('max', $max->getType());
|
||||
self::assertNull($max->getValue());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user