Skip to content

Commit

Permalink
MDL-79667 lib: Upgrade OpenSpout to 4.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Mar 9, 2024
1 parent b2fa19f commit 73ac16f
Show file tree
Hide file tree
Showing 102 changed files with 790 additions and 408 deletions.
6 changes: 3 additions & 3 deletions lib/openspout/src/Common/Entity/Cell.php
Expand Up @@ -27,7 +27,7 @@ public function __construct(?Style $style)
$this->setStyle($style);
}

abstract public function getValue(): null|bool|string|int|float|DateTimeInterface|DateInterval;
abstract public function getValue(): null|bool|DateInterval|DateTimeInterface|float|int|string;

final public function setStyle(?Style $style): void
{
Expand All @@ -39,7 +39,7 @@ final public function getStyle(): Style
return $this->style;
}

final public static function fromValue(null|bool|string|int|float|DateTimeInterface|DateInterval $value, ?Style $style = null): self
final public static function fromValue(null|bool|DateInterval|DateTimeInterface|float|int|string $value, ?Style $style = null): self
{
if (\is_bool($value)) {
return new BooleanCell($value, $style);
Expand All @@ -57,7 +57,7 @@ final public static function fromValue(null|bool|string|int|float|DateTimeInterf
return new DateIntervalCell($value, $style);
}
if (isset($value[0]) && '=' === $value[0]) {
return new FormulaCell($value, $style);
return new FormulaCell($value, $style, null);
}

return new StringCell($value, $style);
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Cell/BooleanCell.php
Expand Up @@ -9,7 +9,7 @@

final class BooleanCell extends Cell
{
private bool $value;
private readonly bool $value;

public function __construct(bool $value, ?Style $style)
{
Expand Down
8 changes: 7 additions & 1 deletion lib/openspout/src/Common/Entity/Cell/DateIntervalCell.php
Expand Up @@ -10,8 +10,14 @@

final class DateIntervalCell extends Cell
{
private DateInterval $value;
private readonly DateInterval $value;

/**
* For Excel make sure to set a format onto the style (Style::setFormat()) with the left most unit enclosed with
* brackets: '[h]:mm', '[hh]:mm:ss', '[m]:ss', '[s]', etc.
* This makes sure excel knows what to do with the remaining time that exceeds this unit. Without brackets Excel
* will interpret the value as date time and not duration if it is greater or equal 1.
*/
public function __construct(DateInterval $value, ?Style $style)
{
$this->value = $value;
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Cell/DateTimeCell.php
Expand Up @@ -10,7 +10,7 @@

final class DateTimeCell extends Cell
{
private DateTimeInterface $value;
private readonly DateTimeInterface $value;

public function __construct(DateTimeInterface $value, ?Style $style)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Cell/EmptyCell.php
Expand Up @@ -9,7 +9,7 @@

final class EmptyCell extends Cell
{
private ?string $value;
private readonly ?string $value;

public function __construct(?string $value, ?Style $style)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Cell/ErrorCell.php
Expand Up @@ -9,7 +9,7 @@

final class ErrorCell extends Cell
{
private string $value;
private readonly string $value;

public function __construct(string $value, ?Style $style)
{
Expand Down
17 changes: 12 additions & 5 deletions lib/openspout/src/Common/Entity/Cell/FormulaCell.php
Expand Up @@ -4,21 +4,28 @@

namespace OpenSpout\Common\Entity\Cell;

use DateInterval;
use DateTimeImmutable;
use OpenSpout\Common\Entity\Cell;
use OpenSpout\Common\Entity\Style\Style;

final class FormulaCell extends Cell
{
private string $value;

public function __construct(string $value, ?Style $style)
{
$this->value = $value;
public function __construct(
private readonly string $value,
?Style $style,
private readonly null|DateInterval|DateTimeImmutable|float|int|string $computedValue = null,
) {
parent::__construct($style);
}

public function getValue(): string
{
return $this->value;
}

public function getComputedValue(): null|DateInterval|DateTimeImmutable|float|int|string
{
return $this->computedValue;
}
}
6 changes: 3 additions & 3 deletions lib/openspout/src/Common/Entity/Cell/NumericCell.php
Expand Up @@ -9,15 +9,15 @@

final class NumericCell extends Cell
{
private int|float $value;
private readonly float|int $value;

public function __construct(int|float $value, ?Style $style)
public function __construct(float|int $value, ?Style $style)
{
$this->value = $value;
parent::__construct($style);
}

public function getValue(): int|float
public function getValue(): float|int
{
return $this->value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Cell/StringCell.php
Expand Up @@ -9,7 +9,7 @@

final class StringCell extends Cell
{
private string $value;
private readonly string $value;

public function __construct(string $value, ?Style $style)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/openspout/src/Common/Entity/Row.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $cells, ?Style $style = null)
*/
public static function fromValues(array $cellValues = [], ?Style $rowStyle = null): self
{
$cells = array_map(static function (null|bool|string|int|float|DateTimeInterface|DateInterval $cellValue): Cell {
$cells = array_map(static function (null|bool|DateInterval|DateTimeInterface|float|int|string $cellValue): Cell {
return Cell::fromValue($cellValue);
}, $cellValues);

Expand Down Expand Up @@ -134,7 +134,7 @@ public function getHeight(): float
*/
public function toArray(): array
{
return array_map(static function (Cell $cell): null|bool|string|int|float|DateTimeInterface|DateInterval {
return array_map(static function (Cell $cell): null|bool|DateInterval|DateTimeInterface|float|int|string {
return $cell->getValue();
}, $this->cells);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/openspout/src/Common/Entity/Style/BorderPart.php
Expand Up @@ -31,10 +31,10 @@ final class BorderPart
Border::WIDTH_THICK,
];

private string $style;
private string $name;
private string $color;
private string $width;
private readonly string $style;
private readonly string $name;
private readonly string $color;
private readonly string $width;

/**
* @param string $name @see BorderPart::allowedNames
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Entity/Style/Color.php
Expand Up @@ -65,7 +65,7 @@ public static function toARGB(string $rgbColor): string
/**
* Throws an exception is the color component value is outside of bounds (0 - 255).
*
* @throws \OpenSpout\Common\Exception\InvalidColorException
* @throws InvalidColorException
*/
private static function throwIfInvalidColorComponentValue(int $colorComponent): void
{
Expand Down
Expand Up @@ -4,6 +4,4 @@

namespace OpenSpout\Common\Exception;

final class EncodingConversionException extends OpenSpoutException
{
}
final class EncodingConversionException extends OpenSpoutException {}
4 changes: 1 addition & 3 deletions lib/openspout/src/Common/Exception/IOException.php
Expand Up @@ -4,6 +4,4 @@

namespace OpenSpout\Common\Exception;

final class IOException extends OpenSpoutException
{
}
final class IOException extends OpenSpoutException {}
Expand Up @@ -4,6 +4,4 @@

namespace OpenSpout\Common\Exception;

final class InvalidArgumentException extends OpenSpoutException
{
}
final class InvalidArgumentException extends OpenSpoutException {}
4 changes: 1 addition & 3 deletions lib/openspout/src/Common/Exception/InvalidColorException.php
Expand Up @@ -4,6 +4,4 @@

namespace OpenSpout\Common\Exception;

final class InvalidColorException extends OpenSpoutException
{
}
final class InvalidColorException extends OpenSpoutException {}
4 changes: 1 addition & 3 deletions lib/openspout/src/Common/Exception/OpenSpoutException.php
Expand Up @@ -6,6 +6,4 @@

use Exception;

abstract class OpenSpoutException extends Exception
{
}
abstract class OpenSpoutException extends Exception {}
Expand Up @@ -4,6 +4,4 @@

namespace OpenSpout\Common\Exception;

final class UnsupportedTypeException extends OpenSpoutException
{
}
final class UnsupportedTypeException extends OpenSpoutException {}
10 changes: 5 additions & 5 deletions lib/openspout/src/Common/Helper/EncodingHelper.php
Expand Up @@ -33,9 +33,9 @@ final class EncodingHelper
/** @var array<string, string> Map representing the encodings supporting BOMs (key) and their associated BOM (value) */
private array $supportedEncodingsWithBom;

private bool $canUseIconv;
private readonly bool $canUseIconv;

private bool $canUseMbString;
private readonly bool $canUseMbString;

public function __construct(bool $canUseIconv, bool $canUseMbString)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public function getBytesOffsetToSkipBOM($filePointer, string $encoding): int
*
* @return string The converted, UTF-8 string
*
* @throws \OpenSpout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @throws EncodingConversionException If conversion is not supported or if the conversion failed
*/
public function attemptConversionToUTF8(?string $string, string $sourceEncoding): ?string
{
Expand All @@ -104,7 +104,7 @@ public function attemptConversionToUTF8(?string $string, string $sourceEncoding)
*
* @return string The converted string, encoded with the given encoding
*
* @throws \OpenSpout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @throws EncodingConversionException If conversion is not supported or if the conversion failed
*/
public function attemptConversionFromUTF8(?string $string, string $targetEncoding): ?string
{
Expand Down Expand Up @@ -145,7 +145,7 @@ private function hasBOM($filePointer, string $encoding): bool
*
* @return string The converted string, encoded with the given encoding
*
* @throws \OpenSpout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
* @throws EncodingConversionException If conversion is not supported or if the conversion failed
*/
private function attemptConversion(?string $string, string $sourceEncoding, string $targetEncoding): ?string
{
Expand Down
1 change: 1 addition & 0 deletions lib/openspout/src/Common/Helper/Escaper/XLSX.php
Expand Up @@ -33,6 +33,7 @@ public function escape(string $string): string
$this->initIfNeeded();

$escapedString = $this->escapeControlCharacters($string);

// @NOTE: Using ENT_QUOTES as XML entities ('<', '>', '&') as well as
// single/double quotes (for XML attributes) need to be encoded.
return htmlspecialchars($escapedString, ENT_QUOTES, 'UTF-8');
Expand Down
14 changes: 7 additions & 7 deletions lib/openspout/src/Common/Helper/FileSystemHelper.php
Expand Up @@ -14,7 +14,7 @@
final class FileSystemHelper implements FileSystemHelperInterface
{
/** @var string Real path of the base folder where all the I/O can occur */
private string $baseFolderRealPath;
private readonly string $baseFolderRealPath;

/**
* @param string $baseFolderPath The path of the base folder where all the I/O can occur
Expand All @@ -39,7 +39,7 @@ public function getBaseFolderRealPath(): string
*
* @return string Path of the created folder
*
* @throws \OpenSpout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
* @throws IOException If unable to create the folder or if the folder path is not inside of the base folder
*/
public function createFolder(string $parentFolderPath, string $folderName): string
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public function createFolder(string $parentFolderPath, string $folderName): stri
*
* @return string Path of the created file
*
* @throws \OpenSpout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
* @throws IOException If unable to create the file or if the file path is not inside of the base folder
*/
public function createFileWithContents(string $parentFolderPath, string $fileName, string $fileContents): string
{
Expand Down Expand Up @@ -102,7 +102,7 @@ public function createFileWithContents(string $parentFolderPath, string $fileNam
*
* @param string $filePath Path of the file to delete
*
* @throws \OpenSpout\Common\Exception\IOException If the file path is not inside of the base folder
* @throws IOException If the file path is not inside of the base folder
*/
public function deleteFile(string $filePath): void
{
Expand All @@ -118,7 +118,7 @@ public function deleteFile(string $filePath): void
*
* @param string $folderPath Path of the folder to delete
*
* @throws \OpenSpout\Common\Exception\IOException If the folder path is not inside of the base folder
* @throws IOException If the folder path is not inside of the base folder
*/
public function deleteFolderRecursively(string $folderPath): void
{
Expand Down Expand Up @@ -147,8 +147,8 @@ public function deleteFolderRecursively(string $folderPath): void
*
* @param string $operationFolderPath The path of the folder where the I/O operation should occur
*
* @throws \OpenSpout\Common\Exception\IOException If the folder where the I/O operation should occur
* is not inside the base folder or the base folder does not exist
* @throws IOException If the folder where the I/O operation should occur
* is not inside the base folder or the base folder does not exist
*/
private function throwIfOperationNotInBaseFolder(string $operationFolderPath): void
{
Expand Down
10 changes: 6 additions & 4 deletions lib/openspout/src/Common/Helper/FileSystemHelperInterface.php
Expand Up @@ -4,6 +4,8 @@

namespace OpenSpout\Common\Helper;

use OpenSpout\Common\Exception\IOException;

/**
* @internal
*/
Expand All @@ -17,7 +19,7 @@ interface FileSystemHelperInterface
*
* @return string Path of the created folder
*
* @throws \OpenSpout\Common\Exception\IOException If unable to create the folder or if the folder path is not inside of the base folder
* @throws IOException If unable to create the folder or if the folder path is not inside of the base folder
*/
public function createFolder(string $parentFolderPath, string $folderName): string;

Expand All @@ -31,7 +33,7 @@ public function createFolder(string $parentFolderPath, string $folderName): stri
*
* @return string Path of the created file
*
* @throws \OpenSpout\Common\Exception\IOException If unable to create the file or if the file path is not inside of the base folder
* @throws IOException If unable to create the file or if the file path is not inside of the base folder
*/
public function createFileWithContents(string $parentFolderPath, string $fileName, string $fileContents): string;

Expand All @@ -40,7 +42,7 @@ public function createFileWithContents(string $parentFolderPath, string $fileNam
*
* @param string $filePath Path of the file to delete
*
* @throws \OpenSpout\Common\Exception\IOException If the file path is not inside of the base folder
* @throws IOException If the file path is not inside of the base folder
*/
public function deleteFile(string $filePath): void;

Expand All @@ -49,7 +51,7 @@ public function deleteFile(string $filePath): void;
*
* @param string $folderPath Path of the folder to delete
*
* @throws \OpenSpout\Common\Exception\IOException If the folder path is not inside of the base folder
* @throws IOException If the folder path is not inside of the base folder
*/
public function deleteFolderRecursively(string $folderPath): void;
}
2 changes: 1 addition & 1 deletion lib/openspout/src/Common/Helper/StringHelper.php
Expand Up @@ -10,7 +10,7 @@
final class StringHelper
{
/** @var bool Whether the mbstring extension is loaded */
private bool $hasMbstringSupport;
private readonly bool $hasMbstringSupport;

public function __construct(bool $hasMbstringSupport)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/openspout/src/Reader/AbstractReader.php
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractReader implements ReaderInterface
*
* @param string $filePath Path of the file to be read
*
* @throws \OpenSpout\Common\Exception\IOException If the file at the given path does not exist, is not readable or is corrupted
* @throws IOException If the file at the given path does not exist, is not readable or is corrupted
*/
public function open(string $filePath): void
{
Expand Down

0 comments on commit 73ac16f

Please sign in to comment.