mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-16 21:16:57 +00:00
Merge pull request #3860 from PHPOffice/powerkiki
Remove a few mixed type
This commit is contained in:
@@ -38,7 +38,7 @@ foreach ($customPropertyList as $customPropertyName) {
|
||||
|
||||
break;
|
||||
case 'd': // date
|
||||
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A', $propertyValue);
|
||||
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A', (int) $propertyValue);
|
||||
$propertyType = 'date';
|
||||
|
||||
break;
|
||||
|
||||
@@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||
|
||||
class Filter
|
||||
{
|
||||
public static function filter(mixed $lookupArray, mixed $matchArray, mixed $ifEmpty = null): mixed
|
||||
public static function filter(array $lookupArray, mixed $matchArray, mixed $ifEmpty = null): mixed
|
||||
{
|
||||
if (!is_array($matchArray)) {
|
||||
return ExcelError::VALUE();
|
||||
|
||||
@@ -81,7 +81,7 @@ class Properties
|
||||
/**
|
||||
* Custom Properties.
|
||||
*
|
||||
* @var array{value: mixed, type: string}[]
|
||||
* @var array{value: null|bool|float|int|string, type: string}[]
|
||||
*/
|
||||
private array $customProperties = [];
|
||||
|
||||
@@ -359,7 +359,7 @@ class Properties
|
||||
/**
|
||||
* Get a Custom Property Value.
|
||||
*/
|
||||
public function getCustomPropertyValue(string $propertyName): mixed
|
||||
public function getCustomPropertyValue(string $propertyName): bool|int|float|string|null
|
||||
{
|
||||
if (isset($this->customProperties[$propertyName])) {
|
||||
return $this->customProperties[$propertyName]['value'];
|
||||
@@ -376,7 +376,7 @@ class Properties
|
||||
return $this->customProperties[$propertyName]['type'] ?? null;
|
||||
}
|
||||
|
||||
private function identifyPropertyType(mixed $propertyValue): string
|
||||
private function identifyPropertyType(bool|int|float|string|null $propertyValue): string
|
||||
{
|
||||
if (is_float($propertyValue)) {
|
||||
return self::PROPERTY_TYPE_FLOAT;
|
||||
@@ -398,18 +398,16 @@ class Properties
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomProperty(string $propertyName, mixed $propertyValue = '', ?string $propertyType = null): self
|
||||
public function setCustomProperty(string $propertyName, bool|int|float|string|null $propertyValue = '', ?string $propertyType = null): self
|
||||
{
|
||||
if (($propertyType === null) || (!in_array($propertyType, self::VALID_PROPERTY_TYPE_LIST))) {
|
||||
$propertyType = $this->identifyPropertyType($propertyValue);
|
||||
}
|
||||
|
||||
if (!is_object($propertyValue)) {
|
||||
$this->customProperties[$propertyName] = [
|
||||
'value' => self::convertProperty($propertyValue, $propertyType),
|
||||
'type' => $propertyType,
|
||||
];
|
||||
}
|
||||
$this->customProperties[$propertyName] = [
|
||||
'value' => self::convertProperty($propertyValue, $propertyType),
|
||||
'type' => $propertyType,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -451,7 +449,7 @@ class Properties
|
||||
/**
|
||||
* Convert property to form desired by Excel.
|
||||
*/
|
||||
public static function convertProperty(mixed $propertyValue, string $propertyType): mixed
|
||||
public static function convertProperty(bool|int|float|string|null $propertyValue, string $propertyType): bool|int|float|string|null
|
||||
{
|
||||
return self::SPECIAL_TYPES[$propertyType] ?? self::convertProperty2($propertyValue, $propertyType);
|
||||
}
|
||||
@@ -459,7 +457,7 @@ class Properties
|
||||
/**
|
||||
* Convert property to form desired by Excel.
|
||||
*/
|
||||
private static function convertProperty2(mixed $propertyValue, string $type): mixed
|
||||
private static function convertProperty2(bool|int|float|string|null $propertyValue, string $type): bool|int|float|string|null
|
||||
{
|
||||
$propertyType = self::convertPropertyType($type);
|
||||
switch ($propertyType) {
|
||||
@@ -470,7 +468,7 @@ class Properties
|
||||
case self::PROPERTY_TYPE_FLOAT:
|
||||
return (float) $propertyValue;
|
||||
case self::PROPERTY_TYPE_DATE:
|
||||
return self::intOrFloatTimestamp($propertyValue);
|
||||
return self::intOrFloatTimestamp($propertyValue); // @phpstan-ignore-line
|
||||
case self::PROPERTY_TYPE_BOOLEAN:
|
||||
return is_bool($propertyValue) ? $propertyValue : ($propertyValue === 'true');
|
||||
default: // includes string
|
||||
|
||||
@@ -101,7 +101,7 @@ class Properties
|
||||
}
|
||||
}
|
||||
|
||||
private function setUserDefinedProperty(mixed $propertyValueAttributes, string $propertyValue, DocumentProperties $docProps): void
|
||||
private function setUserDefinedProperty(iterable $propertyValueAttributes, string $propertyValue, DocumentProperties $docProps): void
|
||||
{
|
||||
$propertyValueName = '';
|
||||
$propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING;
|
||||
|
||||
@@ -19,11 +19,6 @@ class Properties
|
||||
$this->docProps = $docProps;
|
||||
}
|
||||
|
||||
private static function nullOrSimple(mixed $obj): ?SimpleXMLElement
|
||||
{
|
||||
return ($obj instanceof SimpleXMLElement) ? $obj : null;
|
||||
}
|
||||
|
||||
private function extractPropertyData(string $propertyData): ?SimpleXMLElement
|
||||
{
|
||||
// okay to omit namespace because everything will be processed by xpath
|
||||
@@ -33,7 +28,7 @@ class Properties
|
||||
Settings::getLibXmlLoaderOptions()
|
||||
);
|
||||
|
||||
return self::nullOrSimple($obj);
|
||||
return $obj === false ? null : $obj;
|
||||
}
|
||||
|
||||
public function readCoreProperties(string $propertyData): void
|
||||
@@ -45,15 +40,15 @@ class Properties
|
||||
$xmlCore->registerXPathNamespace('dcterms', Namespaces::DC_TERMS);
|
||||
$xmlCore->registerXPathNamespace('cp', Namespaces::CORE_PROPERTIES2);
|
||||
|
||||
$this->docProps->setCreator((string) self::getArrayItem($xmlCore->xpath('dc:creator')));
|
||||
$this->docProps->setLastModifiedBy((string) self::getArrayItem($xmlCore->xpath('cp:lastModifiedBy')));
|
||||
$this->docProps->setCreated((string) self::getArrayItem($xmlCore->xpath('dcterms:created'))); //! respect xsi:type
|
||||
$this->docProps->setModified((string) self::getArrayItem($xmlCore->xpath('dcterms:modified'))); //! respect xsi:type
|
||||
$this->docProps->setTitle((string) self::getArrayItem($xmlCore->xpath('dc:title')));
|
||||
$this->docProps->setDescription((string) self::getArrayItem($xmlCore->xpath('dc:description')));
|
||||
$this->docProps->setSubject((string) self::getArrayItem($xmlCore->xpath('dc:subject')));
|
||||
$this->docProps->setKeywords((string) self::getArrayItem($xmlCore->xpath('cp:keywords')));
|
||||
$this->docProps->setCategory((string) self::getArrayItem($xmlCore->xpath('cp:category')));
|
||||
$this->docProps->setCreator($this->getArrayItem($xmlCore->xpath('dc:creator')));
|
||||
$this->docProps->setLastModifiedBy($this->getArrayItem($xmlCore->xpath('cp:lastModifiedBy')));
|
||||
$this->docProps->setCreated($this->getArrayItem($xmlCore->xpath('dcterms:created'))); //! respect xsi:type
|
||||
$this->docProps->setModified($this->getArrayItem($xmlCore->xpath('dcterms:modified'))); //! respect xsi:type
|
||||
$this->docProps->setTitle($this->getArrayItem($xmlCore->xpath('dc:title')));
|
||||
$this->docProps->setDescription($this->getArrayItem($xmlCore->xpath('dc:description')));
|
||||
$this->docProps->setSubject($this->getArrayItem($xmlCore->xpath('dc:subject')));
|
||||
$this->docProps->setKeywords($this->getArrayItem($xmlCore->xpath('cp:keywords')));
|
||||
$this->docProps->setCategory($this->getArrayItem($xmlCore->xpath('cp:category')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +91,8 @@ class Properties
|
||||
}
|
||||
}
|
||||
|
||||
private static function getArrayItem(null|array|false $array, mixed $key = 0): ?SimpleXMLElement
|
||||
private function getArrayItem(null|array|false $array): string
|
||||
{
|
||||
return is_array($array) ? ($array[$key] ?? null) : null;
|
||||
return is_array($array) ? (string) ($array[0] ?? '') : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class Meta extends WriterPart
|
||||
private static function writeDocPropsCustom(XMLWriter $objWriter, Spreadsheet $spreadsheet): void
|
||||
{
|
||||
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
|
||||
foreach ($customPropertyList as $key => $customProperty) {
|
||||
foreach ($customPropertyList as $customProperty) {
|
||||
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
|
||||
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
|
||||
|
||||
@@ -96,7 +96,7 @@ class Meta extends WriterPart
|
||||
case Properties::PROPERTY_TYPE_INTEGER:
|
||||
case Properties::PROPERTY_TYPE_FLOAT:
|
||||
$objWriter->writeAttribute('meta:value-type', 'float');
|
||||
$objWriter->writeRawData($propertyValue);
|
||||
$objWriter->writeRawData($propertyValue); // @phpstan-ignore-line
|
||||
|
||||
break;
|
||||
case Properties::PROPERTY_TYPE_BOOLEAN:
|
||||
@@ -106,12 +106,12 @@ class Meta extends WriterPart
|
||||
break;
|
||||
case Properties::PROPERTY_TYPE_DATE:
|
||||
$objWriter->writeAttribute('meta:value-type', 'date');
|
||||
$dtobj = Date::dateTimeFromTimestamp($propertyValue ?? 0);
|
||||
$dtobj = Date::dateTimeFromTimestamp($propertyValue ?? 0); // @phpstan-ignore-line
|
||||
$objWriter->writeRawData($dtobj->format(DATE_W3C));
|
||||
|
||||
break;
|
||||
default:
|
||||
$objWriter->writeRawData($propertyValue);
|
||||
$objWriter->writeRawData($propertyValue); // @phpstan-ignore-line
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class DocProps extends WriterPart
|
||||
|
||||
switch ($propertyType) {
|
||||
case Properties::PROPERTY_TYPE_INTEGER:
|
||||
$objWriter->writeElement('vt:i4', $propertyValue);
|
||||
$objWriter->writeElement('vt:i4', $propertyValue); // @phpstan-ignore-line
|
||||
|
||||
break;
|
||||
case Properties::PROPERTY_TYPE_FLOAT:
|
||||
@@ -235,7 +235,7 @@ class DocProps extends WriterPart
|
||||
|
||||
break;
|
||||
default:
|
||||
$objWriter->writeElement('vt:lpwstr', $propertyValue);
|
||||
$objWriter->writeElement('vt:lpwstr', $propertyValue); // @phpstan-ignore-line
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user