Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all missing native types #3793

Merged
merged 26 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
92b5ab8
Add all missing types
PowerKiKi Nov 15, 2023
c303df2
Type all interfaces
PowerKiKi Dec 9, 2023
f62245b
phpcs on samples/ too
PowerKiKi Dec 9, 2023
3c0350e
Add some return types
PowerKiKi Dec 9, 2023
77e6cc5
Apply PhpCsFixer `phpdoc_to_property_type`
PowerKiKi Dec 9, 2023
5d716b7
Apply PhpCsFixer `phpdoc_to_return_type`
PowerKiKi Dec 10, 2023
959719a
Apply PhpCsFixer `phpdoc_to_param_type`
PowerKiKi Dec 10, 2023
2e48f15
More typing
PowerKiKi Dec 10, 2023
816b91d
BREAKING Drop all deprecated things
PowerKiKi Dec 10, 2023
72d3266
Last scalar return types
PowerKiKi Dec 10, 2023
4c2f380
Remove duplicated return types
PowerKiKi Dec 10, 2023
bab6fc4
More @param to native types
PowerKiKi Dec 11, 2023
161d82d
A few more native return types
PowerKiKi Dec 11, 2023
f1772bf
A few more native param types
PowerKiKi Dec 12, 2023
a68a54e
Last native param types
PowerKiKi Jan 3, 2024
c1eafc5
Cleanup PHPDoc according to PhpStorm
PowerKiKi Jan 3, 2024
aefde29
More cleanup PHPDoc according to PhpStorm
PowerKiKi Jan 3, 2024
5c6c8e2
Sync most PHPDoc with actual code
PowerKiKi Jan 3, 2024
50f6afc
Drop redundant property initialyzer
PowerKiKi Jan 3, 2024
c01abbc
Merge branch 'master' into powerkiki
PowerKiKi Jan 4, 2024
5cc1ece
PhpStan
PowerKiKi Jan 4, 2024
a3c2ca9
Drop redundant PHPDoc
PowerKiKi Jan 4, 2024
83f7129
Also forbid PHPDoc without a variable name
PowerKiKi Jan 4, 2024
332f641
Allow usage of getters before setters
PowerKiKi Jan 4, 2024
b22fde2
Upgrade QA tools
PowerKiKi Jan 4, 2024
76c5b98
Drop commented code
PowerKiKi Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion bin/check-phpdoc-types
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
function checkPhpDocTypes(): void
{
$content = `git diff --cached` ?? `git diff` ?? `git show HEAD`;
preg_match_all('~^\+ +\* @(param|var) (mixed|string|int|float|bool|null|array|\?|\|)+ \$\w+$~m', $content, $parameters);
preg_match_all('~^\+ +\* @(param|var) (mixed|string|int|float|bool|null|array|\?|\|)+( \$\w+)?$~m', $content, $parameters);
preg_match_all('~^\+ +\* @return (mixed|string|int|float|bool|null|array|void|\?|\|)+$~m', $content, $returns);

$errors = [
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@
"scripts": {
"check": [
"./bin/check-phpdoc-types",
"phpcs src/ tests/ --report=checkstyle",
"phpcs --report-width=200 samples/ src/ tests/ --ignore=samples/Header.php --standard=PHPCompatibility --runtime-set testVersion 8.0- -n",
"phpcs samples/ src/ tests/ --report=checkstyle",
"phpcs samples/ src/ tests/ --standard=PHPCompatibility --runtime-set testVersion 8.0- -n",
"php-cs-fixer fix --ansi --dry-run --diff",
"phpunit --color=always",
"phpstan analyse --ansi --memory-limit=2048M"
],
"style": [
"phpcs src/ tests/ --report=checkstyle",
"phpcs samples/ src/ tests/ --report=checkstyle",
"php-cs-fixer fix --ansi --dry-run --diff"
],
"fix": [
"phpcbf src/ tests/ --report=checkstyle",
"phpcbf samples/ src/ tests/ --report=checkstyle",
"php-cs-fixer fix"
],
"versions": [
"phpcs --report-width=200 samples/ src/ tests/ --ignore=samples/Header.php --standard=PHPCompatibility --runtime-set testVersion 8.0- -n"
"phpcs samples/ src/ tests/ --standard=PHPCompatibility --runtime-set testVersion 8.0- -n"
]
},
"require": {
Expand Down
25 changes: 5 additions & 20 deletions infra/LocaleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,23 @@ class LocaleGenerator
private const ENGLISH_REFERENCE_COLUMN = 'B';
private const EOL = "\n"; // not PHP_EOL

/**
* @var string
*/
protected $translationSpreadsheetName;
protected string $translationSpreadsheetName;

/**
* @var string
*/
protected $translationBaseFolder;
protected string $translationBaseFolder;

protected array $phpSpreadsheetFunctions;

/**
* @var Spreadsheet
*/
protected $translationSpreadsheet;
protected Spreadsheet $translationSpreadsheet;

protected bool $verbose;

/**
* @var Worksheet
*/
protected $localeTranslations;
protected Worksheet $localeTranslations;

protected array $localeLanguageMap = [];

protected array $errorCodeMap = [];

/**
* @var Worksheet
*/
private $functionNameTranslations;
private Worksheet $functionNameTranslations;

protected array $functionNameLanguageMap = [];

Expand Down
995 changes: 995 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ includes:
parameters:
level: 8
paths:
- samples/
- src/
- tests/
- samples/
- infra/
- bin/generate-document
- bin/generate-locales
Expand Down
2 changes: 1 addition & 1 deletion samples/Basic/24_Readfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class MyReadFilter implements IReadFilter
{
public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
// Read title row and rows 20 - 30
if ($row == 1 || ($row >= 20 && $row <= 30)) {
Expand Down
23 changes: 8 additions & 15 deletions samples/Basic/26_Utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,20 @@
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);

// Export to PDF (mpdf)
function mpdfCjkWriter(Mpdf $writer): void
{
/** @var callable */
$callback = 'mpdfCjk';
$writer->setEditHtmlCallback($callback);
}
$mpdfCjkWriter = function (Mpdf $writer): void {
$mpdfCjk = function (string $html): string {
$html = str_replace("'Calibri'", "'Calibri',Sun-ExtA", $html);

function mpdfCjk(string $html): string
{
$html = str_replace("'Calibri'", "'Calibri',Sun-ExtA", $html);
return str_replace("'Times New Roman'", "'Times New Roman',Sun-ExtA", $html);
};

return str_replace("'Times New Roman'", "'Times New Roman',Sun-ExtA", $html);
}
$writer->setEditHtmlCallback($mpdfCjk);
};

$helper->log('Write to Mpdf');
IOFactory::registerWriter('Pdf', Mpdf::class);
/** @var callable */
$callback = 'mpdfCjkWriter';
$filename = __FILE__;
//$filename = str_replace('.php', '.mdpf.php', __FILE__);
$helper->write($spreadsheet, $filename, ['Pdf'], false, $callback);
$helper->write($spreadsheet, $filename, ['Pdf'], false, $mpdfCjkWriter);

// Remove first two rows with field headers before exporting to CSV
$helper->log('Removing first two heading rows for CSV export');
Expand Down
2 changes: 1 addition & 1 deletion samples/Basic/39_Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function transpose(string $value): array
$countryCount = count($countries);

// Transpose $countries from a row to a column array
$countries = array_map('transpose', $countries);
$countries = array_map(fn (mixed $value): array => [$value], $countries);
$spreadsheet->getActiveSheet()
->fromArray($countries, null, $column . '1');
$spreadsheet->addNamedRange(
Expand Down
4 changes: 2 additions & 2 deletions samples/Chart/33_Chart_create_line_dateaxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_SMOOTHMARKER // plotStyle
);

Expand Down Expand Up @@ -279,7 +279,7 @@
// change xAxis tick marks to match Qtr boundaries

$nQtrs = sprintf('%3.2f', (($dateMinMax['max'] - $dateMinMax['min']) / 30.5) / 4);
$tickMarkInterval = ($nQtrs > 20) ? 6 : 3; // tick marks every ? months
$tickMarkInterval = ($nQtrs > 20) ? '6' : '3'; // tick marks every ? months

$xAxis->setAxisOptionsProperties(
Properties::AXIS_LABELS_NEXT_TO, // axis_label pos
Expand Down
2 changes: 1 addition & 1 deletion samples/Chart/33_Chart_create_radar.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_MARKER // plotStyle
);

Expand Down
2 changes: 1 addition & 1 deletion samples/Chart/33_Chart_create_scatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_LINEMARKER // plotStyle
);

Expand Down
4 changes: 2 additions & 2 deletions samples/Chart/33_Chart_create_scatter2.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
Properties::LINE_STYLE_CAP_SQUARE, // cap
Properties::LINE_STYLE_JOIN_MITER, // join
Properties::LINE_STYLE_ARROW_TYPE_OPEN, // head type
(string) Properties::LINE_STYLE_ARROW_SIZE_4, // head size preset index
Properties::LINE_STYLE_ARROW_SIZE_4, // head size preset index
Properties::LINE_STYLE_ARROW_TYPE_ARROW, // end type
(string) Properties::LINE_STYLE_ARROW_SIZE_6 // end size preset index
Properties::LINE_STYLE_ARROW_SIZE_6 // end size preset index
);

// series 2 - straight line - no special effects, connected, straight line
Expand Down
2 changes: 1 addition & 1 deletion samples/Chart/33_Chart_create_scatter4.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_LINEMARKER // plotStyle
);

Expand Down
6 changes: 3 additions & 3 deletions samples/Chart/33_Chart_create_scatter5_trendlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_SMOOTHMARKER // plotStyle
);

Expand Down Expand Up @@ -217,7 +217,7 @@
$dataSeriesValues[0]->getTrendLines()[1]->setLineStyleProperties(1.25);

$dataSeriesValues[0]->getTrendLines()[2]->getLineColor()->setColorProperties('accent2', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
$dataSeriesValues[0]->getTrendLines()[2]->setLineStyleProperties(1.5, null, null, null, null, null, null, Properties::LINE_STYLE_ARROW_TYPE_OPEN, 8);
$dataSeriesValues[0]->getTrendLines()[2]->setLineStyleProperties(1.5, null, null, null, null, null, 0, Properties::LINE_STYLE_ARROW_TYPE_OPEN, 8);

$xAxis = new ChartAxis();
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601); // m/d/yyyy
Expand All @@ -231,7 +231,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_SMOOTHMARKER // plotStyle
);

Expand Down
14 changes: 7 additions & 7 deletions samples/Chart/33_Chart_create_scatter6_value_xaxis.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
null, // plotDirection
null, // smooth line
false, // smooth line
DataSeries::STYLE_LINEMARKER // plotStyle
);

Expand All @@ -81,10 +81,10 @@
null, // axisOrientation
null, // majorTmt
Properties::TICK_MARK_OUTSIDE, // minorTmt
0, // minimum
6, // maximum
'0', // minimum
'6', // maximum
null, // majorUnit
1, // minorUnit
'1', // minorUnit
);

$xAxis->setAxisType(ChartAxis::AXIS_TYPE_VALUE);
Expand All @@ -98,10 +98,10 @@
null, // axisOrientation
null, // majorTmt
Properties::TICK_MARK_OUTSIDE, // minorTmt
0, // minimum
25, // 30 // maximum
'0', // minimum
'25', // 30 // maximum
null, // majorUnit
5, // minorUnit
'5', // minorUnit
);

// Create the chart
Expand Down
4 changes: 1 addition & 3 deletions samples/Pdf/Mpdf2.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class Mpdf2 extends Mpdf
* Other configuration options may be specified here.
*
* @param array $config Configuration array
*
* @return \Mpdf\Mpdf implementation
*/
protected function createExternalWriterInstance($config)
protected function createExternalWriterInstance($config): \Mpdf\Mpdf
{
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getDesiredSheetNames(): array

$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType);
$reader = IOFactory::createReader($inputFileType);
$helper->log('Loading Sheet' . ((count($sheetnames) == 1) ? '' : 's') . ' "' . implode('" and "', $sheetnames) . '" only');
$helper->log('Loading Sheets "' . implode('" and "', $sheetnames) . '" only');
$reader->setLoadSheetsOnly($sheetnames);
$spreadsheet = $reader->load($inputFileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class MyReadFilter implements IReadFilter
{
public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
// Read rows 9 to 15 and columns A to E only
if ($row >= 9 && $row <= 15) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@

class MyReadFilter implements IReadFilter
{
private int $startRow = 0;

private int $endRow = 0;

private array $columns = [];

public function __construct(int $startRow, int $endRow, array $columns)
{
$this->startRow = $startRow;
$this->endRow = $endRow;
$this->columns = $columns;
public function __construct(
private int $startRow,
private int $endRow,
private array $columns
) {
}

public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
if ($row >= $this->startRow && $row <= $this->endRow) {
if (in_array($columnAddress, $this->columns)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/** Define a Read Filter class implementing IReadFilter */
class ChunkReadFilter implements IReadFilter
{
private int $startRow = 0;
private int $startRow;

private int $endRow = 0;
private int $endRow;

/**
* We expect a list of the rows that we want to read to be passed into the constructor.
Expand All @@ -26,7 +26,7 @@ public function __construct(int $startRow, int $chunkSize)
$this->endRow = $startRow + $chunkSize;
}

public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
// Only read the heading row, and the rows that were configured in the constructor
if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setRows(int $startRow, int $chunkSize): void
$this->endRow = $startRow + $chunkSize;
}

public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setRows(int $startRow, int $chunkSize): void
$this->endRow = $startRow + $chunkSize;
}

public function readCell($columnAddress, $row, $worksheetName = '')
public function readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
Expand Down
5 changes: 1 addition & 4 deletions src/PhpSpreadsheet/Calculation/ArrayEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

trait ArrayEnabled
{
/**
* @var ArrayArgumentHelper
*/
private static $arrayArgumentHelper;
private static ?ArrayArgumentHelper $arrayArgumentHelper = null;

/**
* @param array|false $arguments Can be changed to array for Php8.1+
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/BinaryComparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BinaryComparison
* @param null|string $str1 First string value for the comparison
* @param null|string $str2 Second string value for the comparison
*/
private static function strcmpLowercaseFirst($str1, $str2): int
private static function strcmpLowercaseFirst(?string $str1, ?string $str2): int
{
$inversedStr1 = StringHelper::strCaseReverse($str1 ?? '');
$inversedStr2 = StringHelper::strCaseReverse($str2 ?? '');
Expand All @@ -31,7 +31,7 @@ private static function strcmpLowercaseFirst($str1, $str2): int
* @param null|string $str1 First string value for the comparison
* @param null|string $str2 Second string value for the comparison
*/
private static function strcmpAllowNull($str1, $str2): int
private static function strcmpAllowNull(?string $str1, ?string $str2): int
{
return strcmp($str1 ?? '', $str2 ?? '');
}
Expand Down
Loading