Skip to content

Commit 8417cfa

Browse files
committed
Remove a few mixed type
1 parent ae72efe commit 8417cfa

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

src/PhpSpreadsheet/Calculation/LookupRef/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Filter
88
{
9-
public static function filter(mixed $lookupArray, mixed $matchArray, mixed $ifEmpty = null): mixed
9+
public static function filter(array $lookupArray, mixed $matchArray, mixed $ifEmpty = null): mixed
1010
{
1111
if (!is_array($matchArray)) {
1212
return ExcelError::VALUE();

src/PhpSpreadsheet/Document/Properties.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Properties
8181
/**
8282
* Custom Properties.
8383
*
84-
* @var array{value: mixed, type: string}[]
84+
* @var array{value: bool|float|int|string, type: string}[]
8585
*/
8686
private array $customProperties = [];
8787

@@ -359,7 +359,7 @@ public function isCustomPropertySet(string $propertyName): bool
359359
/**
360360
* Get a Custom Property Value.
361361
*/
362-
public function getCustomPropertyValue(string $propertyName): mixed
362+
public function getCustomPropertyValue(string $propertyName): bool|int|float|string|null
363363
{
364364
if (isset($this->customProperties[$propertyName])) {
365365
return $this->customProperties[$propertyName]['value'];
@@ -376,7 +376,7 @@ public function getCustomPropertyType(string $propertyName): ?string
376376
return $this->customProperties[$propertyName]['type'] ?? null;
377377
}
378378

379-
private function identifyPropertyType(mixed $propertyValue): string
379+
private function identifyPropertyType(bool|int|float|string|null $propertyValue): string
380380
{
381381
if (is_float($propertyValue)) {
382382
return self::PROPERTY_TYPE_FLOAT;
@@ -398,7 +398,7 @@ private function identifyPropertyType(mixed $propertyValue): string
398398
*
399399
* @return $this
400400
*/
401-
public function setCustomProperty(string $propertyName, mixed $propertyValue = '', ?string $propertyType = null): self
401+
public function setCustomProperty(string $propertyName, bool|int|float|string|null $propertyValue = '', ?string $propertyType = null): self
402402
{
403403
if (($propertyType === null) || (!in_array($propertyType, self::VALID_PROPERTY_TYPE_LIST))) {
404404
$propertyType = $this->identifyPropertyType($propertyValue);
@@ -451,15 +451,15 @@ public function setCustomProperty(string $propertyName, mixed $propertyValue = '
451451
/**
452452
* Convert property to form desired by Excel.
453453
*/
454-
public static function convertProperty(mixed $propertyValue, string $propertyType): mixed
454+
public static function convertProperty(bool|int|float|string|null $propertyValue, string $propertyType): bool|int|float|string|null
455455
{
456456
return self::SPECIAL_TYPES[$propertyType] ?? self::convertProperty2($propertyValue, $propertyType);
457457
}
458458

459459
/**
460460
* Convert property to form desired by Excel.
461461
*/
462-
private static function convertProperty2(mixed $propertyValue, string $type): mixed
462+
private static function convertProperty2(bool|int|float|string|null $propertyValue, string $type): bool|int|float|string|null
463463
{
464464
$propertyType = self::convertPropertyType($type);
465465
switch ($propertyType) {

src/PhpSpreadsheet/Reader/Ods/Properties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function setMetaProperties(
101101
}
102102
}
103103

104-
private function setUserDefinedProperty(mixed $propertyValueAttributes, string $propertyValue, DocumentProperties $docProps): void
104+
private function setUserDefinedProperty(iterable $propertyValueAttributes, string $propertyValue, DocumentProperties $docProps): void
105105
{
106106
$propertyValueName = '';
107107
$propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING;

src/PhpSpreadsheet/Reader/Xlsx/Properties.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public function __construct(XmlScanner $securityScanner, DocumentProperties $doc
1919
$this->docProps = $docProps;
2020
}
2121

22-
private static function nullOrSimple(mixed $obj): ?SimpleXMLElement
23-
{
24-
return ($obj instanceof SimpleXMLElement) ? $obj : null;
25-
}
26-
2722
private function extractPropertyData(string $propertyData): ?SimpleXMLElement
2823
{
2924
// okay to omit namespace because everything will be processed by xpath
@@ -33,7 +28,7 @@ private function extractPropertyData(string $propertyData): ?SimpleXMLElement
3328
Settings::getLibXmlLoaderOptions()
3429
);
3530

36-
return self::nullOrSimple($obj);
31+
return $obj === false ? null : $obj;
3732
}
3833

3934
public function readCoreProperties(string $propertyData): void
@@ -45,15 +40,15 @@ public function readCoreProperties(string $propertyData): void
4540
$xmlCore->registerXPathNamespace('dcterms', Namespaces::DC_TERMS);
4641
$xmlCore->registerXPathNamespace('cp', Namespaces::CORE_PROPERTIES2);
4742

48-
$this->docProps->setCreator((string) self::getArrayItem($xmlCore->xpath('dc:creator')));
49-
$this->docProps->setLastModifiedBy((string) self::getArrayItem($xmlCore->xpath('cp:lastModifiedBy')));
50-
$this->docProps->setCreated((string) self::getArrayItem($xmlCore->xpath('dcterms:created'))); //! respect xsi:type
51-
$this->docProps->setModified((string) self::getArrayItem($xmlCore->xpath('dcterms:modified'))); //! respect xsi:type
52-
$this->docProps->setTitle((string) self::getArrayItem($xmlCore->xpath('dc:title')));
53-
$this->docProps->setDescription((string) self::getArrayItem($xmlCore->xpath('dc:description')));
54-
$this->docProps->setSubject((string) self::getArrayItem($xmlCore->xpath('dc:subject')));
55-
$this->docProps->setKeywords((string) self::getArrayItem($xmlCore->xpath('cp:keywords')));
56-
$this->docProps->setCategory((string) self::getArrayItem($xmlCore->xpath('cp:category')));
43+
$this->docProps->setCreator($this->getArrayItem($xmlCore->xpath('dc:creator')));
44+
$this->docProps->setLastModifiedBy($this->getArrayItem($xmlCore->xpath('cp:lastModifiedBy')));
45+
$this->docProps->setCreated($this->getArrayItem($xmlCore->xpath('dcterms:created'))); //! respect xsi:type
46+
$this->docProps->setModified($this->getArrayItem($xmlCore->xpath('dcterms:modified'))); //! respect xsi:type
47+
$this->docProps->setTitle($this->getArrayItem($xmlCore->xpath('dc:title')));
48+
$this->docProps->setDescription($this->getArrayItem($xmlCore->xpath('dc:description')));
49+
$this->docProps->setSubject($this->getArrayItem($xmlCore->xpath('dc:subject')));
50+
$this->docProps->setKeywords($this->getArrayItem($xmlCore->xpath('cp:keywords')));
51+
$this->docProps->setCategory($this->getArrayItem($xmlCore->xpath('cp:category')));
5752
}
5853
}
5954

@@ -96,8 +91,8 @@ public function readCustomProperties(string $propertyData): void
9691
}
9792
}
9893

99-
private static function getArrayItem(null|array|false $array, mixed $key = 0): ?SimpleXMLElement
94+
private function getArrayItem(null|array|false $array): string
10095
{
101-
return is_array($array) ? ($array[$key] ?? null) : null;
96+
return is_array($array) ? (string) ($array[0] ?? '') : '';
10297
}
10398
}

0 commit comments

Comments
 (0)