Skip to content

Document Properties - Coverage and 32-bit-safe Timestamps #2113

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

Merged
merged 5 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 0 additions & 150 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2165,36 +2165,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/DefinedName.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:\\$created \\(int\\) does not accept int\\|false\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:\\$modified \\(int\\) does not accept int\\|false\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:identifyPropertyType\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:identifyPropertyType\\(\\) has parameter \\$propertyValue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:convertProperty\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:convertProperty\\(\\) has parameter \\$propertyValue with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Document/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\HashTable\\:\\:getIndexForHashCode\\(\\) should return int but returns int\\|string\\|false\\.$#"
count: 1
Expand Down Expand Up @@ -2640,16 +2610,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Ods/Properties.php

-
message: "#^Parameter \\#1 \\$timestamp of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setCreated\\(\\) expects int\\|string\\|null, int\\|false given\\.$#"
count: 2
path: src/PhpSpreadsheet/Reader/Ods/Properties.php

-
message: "#^Parameter \\#1 \\$timestamp of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setModified\\(\\) expects int\\|string\\|null, int\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Ods/Properties.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\Properties\\:\\:setMetaProperties\\(\\) has parameter \\$namespacesMeta with no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -2860,61 +2820,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$codePage of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\CodePage\\:\\:numberToName\\(\\) expects int, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$title of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setTitle\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$subject of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setSubject\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$creator of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setCreator\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$keywords of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setKeywords\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$description of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setDescription\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$modifier of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setLastModifiedBy\\(\\) expects string, int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$codePage of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\CodePage\\:\\:numberToName\\(\\) expects int, bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$category of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setCategory\\(\\) expects string, bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$manager of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setManager\\(\\) expects string, bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#1 \\$company of method PhpOffice\\\\PhpSpreadsheet\\\\Document\\\\Properties\\:\\:setCompany\\(\\) expects string, bool\\|int\\|string\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php

-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, int\\|string\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -4520,16 +4425,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#1 \\$time_1st of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root constructor expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#2 \\$time_2nd of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root constructor expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#1 \\$No of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS constructor expects int, null given\\.$#"
count: 1
Expand Down Expand Up @@ -4560,16 +4455,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#7 \\$time_1st of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS constructor expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#8 \\$time_2nd of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS constructor expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE.php

-
message: "#^Parameter \\#9 \\$data of class PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS constructor expects string, null given\\.$#"
count: 1
Expand Down Expand Up @@ -4640,16 +4525,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Shared/OLE/PPS/File.php

-
message: "#^Parameter \\#7 \\$time_1st of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:__construct\\(\\) expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE/PPS/File.php

-
message: "#^Parameter \\#8 \\$time_2nd of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:__construct\\(\\) expects int, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/OLE/PPS/File.php

-
message: "#^Parameter \\#1 \\$No of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:__construct\\(\\) expects int, null given\\.$#"
count: 1
Expand Down Expand Up @@ -4795,11 +4670,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Shared/StringHelper.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/TimeZone.php

-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:\\$goodnessOfFit has no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -7545,31 +7415,11 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php

-
message: "#^Parameter \\#1 \\$timeZone of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Date\\:\\:setDefaultTimezone\\(\\) expects DateTimeZone\\|string, DateTimeZone\\|null given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Shared/DateTest.php

-
message: "#^Parameter \\#1 \\$pValue of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:setCurrencyCode\\(\\) expects string, null given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Shared/StringHelperTest.php

-
message: "#^Parameter \\#1 \\$timeZone of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Date\\:\\:setDefaultTimezone\\(\\) expects DateTimeZone\\|string, DateTimeZone\\|null given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php

-
message: "#^Cannot call method getTimestamp\\(\\) on DateTime\\|false\\.$#"
count: 2
path: tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php

-
message: "#^Parameter \\#1 \\$timezone of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\TimeZone\\:\\:getTimeZoneAdjustment\\(\\) expects string, null given\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\SpreadsheetTest\\:\\:testGetSheetByName\\(\\) has parameter \\$index with no typehint specified\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion samples/Basic/01_Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
->setTitle('Simple');

// Save
$helper->write($spreadsheet, __FILE__);
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Ods']);
10 changes: 5 additions & 5 deletions samples/Reading_workbook_data/Properties.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;

require __DIR__ . '/../Header.php';

Expand All @@ -18,9 +19,8 @@

// Read the Date when the workbook was created (as a PHP timestamp value)
$creationDatestamp = $spreadsheet->getProperties()->getCreated();
// Format the date and time using the standard PHP date() function
$creationDate = date('l, d<\s\up>S</\s\up> F Y', $creationDatestamp);
$creationTime = date('g:i A', $creationDatestamp);
$creationDate = Date::formattedDateTimeFromTimestamp("$creationDatestamp", 'l, d<\s\up>S</\s\up> F Y');
$creationTime = Date::formattedDateTimeFromTimestamp("$creationDatestamp", 'g:i A');
$helper->log('<b>Created On: </b>' . $creationDate . ' at ' . $creationTime);

// Read the name of the last person to modify this workbook
Expand All @@ -30,8 +30,8 @@
// Read the Date when the workbook was last modified (as a PHP timestamp value)
$modifiedDatestamp = $spreadsheet->getProperties()->getModified();
// Format the date and time using the standard PHP date() function
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y', $modifiedDatestamp);
$modifiedTime = date('g:i A', $modifiedDatestamp);
$modifiedDate = Date::formattedDateTimeFromTimestamp("$modifiedDatestamp", 'l, d<\s\up>S</\s\up> F Y');
$modifiedTime = Date::formattedDateTimeFromTimestamp("$modifiedDatestamp", 'g:i A');
$helper->log('<b>Last Modified On: </b>' . $modifiedDate . ' at ' . $modifiedTime);

// Read the workbook title property
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4687,7 +4687,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
} else {
$this->executeNumericBinaryOperation($multiplier, $arg, '*', 'arrayTimesEquals', $stack);
}
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token, $matches)) {
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token ?? '', $matches)) {
$cellRef = null;

if (isset($matches[8])) {
Expand Down Expand Up @@ -4765,7 +4765,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
}

// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token, $matches)) {
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) {
if ($pCellParent) {
$pCell->attach($pCellParent);
}
Expand Down Expand Up @@ -4855,7 +4855,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
}
} else {
// if the token is a number, boolean, string or an Excel error, push it onto the stack
if (isset(self::$excelConstants[strtoupper($token)])) {
if (isset(self::$excelConstants[strtoupper($token ?? '')])) {
$excelConstant = strtoupper($token);
$stack->push('Constant Value', self::$excelConstants[$excelConstant]);
if (isset($storeKey)) {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/MathTrig/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Base
public static function evaluate($number, $radix, $minLength = null)
{
try {
$number = (int) Helpers::validateNumericNullBool($number);
$number = (float) floor(Helpers::validateNumericNullBool($number));
$radix = (int) Helpers::validateNumericNullBool($radix);
} catch (Exception $e) {
return $e->getMessage();
Expand All @@ -36,7 +36,7 @@ public static function evaluate($number, $radix, $minLength = null)
return Functions::NAN(); // Numeric range constraints
}

$outcome = strtoupper((string) base_convert((string) $number, 10, $radix));
$outcome = strtoupper((string) base_convert("$number", 10, $radix));
if ($minLength !== null) {
$outcome = str_pad($outcome, (int) $minLength, '0', STR_PAD_LEFT); // String padding
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Statistical.php
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ public static function PERCENTRANK($valueSet, $value, $significance = 3)
* @param int $numObjs Number of different objects
* @param int $numInSet Number of objects in each permutation
*
* @return int|string Number of permutations, or a string containing an error
* @return float|int|string Number of permutations, or a string containing an error
*/
public static function PERMUT($numObjs, $numInSet)
{
Expand Down
12 changes: 8 additions & 4 deletions src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Shared\IntOrFloat;

class Permutations
{
Expand All @@ -20,7 +21,7 @@ class Permutations
* @param mixed $numObjs Integer number of different objects
* @param mixed $numInSet Integer number of objects in each permutation
*
* @return int|string Number of permutations, or a string containing an error
* @return float|int|string Number of permutations, or a string containing an error
*/
public static function PERMUT($numObjs, $numInSet)
{
Expand All @@ -37,8 +38,9 @@ public static function PERMUT($numObjs, $numInSet)
if ($numObjs < $numInSet) {
return Functions::NAN();
}
$result = round(MathTrig\Factorial::fact($numObjs) / MathTrig\Factorial::fact($numObjs - $numInSet));

return (int) round(MathTrig\Factorial::fact($numObjs) / MathTrig\Factorial::fact($numObjs - $numInSet));
return IntOrFloat::evaluate($result);
}

/**
Expand All @@ -50,7 +52,7 @@ public static function PERMUT($numObjs, $numInSet)
* @param mixed $numObjs Integer number of different objects
* @param mixed $numInSet Integer number of objects in each permutation
*
* @return int|string Number of permutations, or a string containing an error
* @return float|int|string Number of permutations, or a string containing an error
*/
public static function PERMUTATIONA($numObjs, $numInSet)
{
Expand All @@ -68,6 +70,8 @@ public static function PERMUTATIONA($numObjs, $numInSet)
return Functions::NAN();
}

return (int) ($numObjs ** $numInSet);
$result = $numObjs ** $numInSet;

return IntOrFloat::evaluate($result);
}
}
Loading