Skip to content

Commit

Permalink
Remove a few mixed type
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Jan 8, 2024
1 parent ae72efe commit 8417cfa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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();
Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Document/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Properties
/**
* Custom Properties.
*
* @var array{value: mixed, type: string}[]
* @var array{value: bool|float|int|string, type: string}[]
*/
private array $customProperties = [];

Expand Down Expand Up @@ -359,7 +359,7 @@ public function isCustomPropertySet(string $propertyName): bool
/**
* 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'];
Expand All @@ -376,7 +376,7 @@ public function getCustomPropertyType(string $propertyName): ?string
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;
Expand All @@ -398,7 +398,7 @@ private function identifyPropertyType(mixed $propertyValue): string
*
* @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);
Expand Down Expand Up @@ -451,15 +451,15 @@ public function setCustomProperty(string $propertyName, mixed $propertyValue = '
/**
* 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);
}

/**
* 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Ods/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function setMetaProperties(
}
}

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;
Expand Down
29 changes: 12 additions & 17 deletions src/PhpSpreadsheet/Reader/Xlsx/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public function __construct(XmlScanner $securityScanner, DocumentProperties $doc
$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
Expand All @@ -33,7 +28,7 @@ private function extractPropertyData(string $propertyData): ?SimpleXMLElement
Settings::getLibXmlLoaderOptions()
);

return self::nullOrSimple($obj);
return $obj === false ? null : $obj;
}

public function readCoreProperties(string $propertyData): void
Expand All @@ -45,15 +40,15 @@ public function readCoreProperties(string $propertyData): void
$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')));
}
}

Expand Down Expand Up @@ -96,8 +91,8 @@ public function readCustomProperties(string $propertyData): void
}
}

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] ?? '') : '';
}
}

0 comments on commit 8417cfa

Please sign in to comment.