Skip to content

Commit

Permalink
Merge pull request #3793 from PHPOffice/powerkiki
Browse files Browse the repository at this point in the history
Add all missing native types
  • Loading branch information
PowerKiKi committed Jan 4, 2024
2 parents 2e4b8f8 + 76c5b98 commit a75022a
Show file tree
Hide file tree
Showing 502 changed files with 3,681 additions and 16,149 deletions.
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

0 comments on commit a75022a

Please sign in to comment.