From b95a0ac62a05e2394c15c4c393175939b68714a2 Mon Sep 17 00:00:00 2001 From: "Chun-Sheng, Li" Date: Mon, 25 Sep 2023 19:58:07 +0800 Subject: [PATCH] Add readonly property to prevent modification (#185) --- src/Common/Entity/Cell/BooleanCell.php | 2 +- src/Common/Entity/Cell/DateIntervalCell.php | 2 +- src/Common/Entity/Cell/DateTimeCell.php | 2 +- src/Common/Entity/Cell/EmptyCell.php | 2 +- src/Common/Entity/Cell/ErrorCell.php | 2 +- src/Common/Entity/Cell/NumericCell.php | 2 +- src/Common/Entity/Cell/StringCell.php | 2 +- src/Common/Entity/Style/BorderPart.php | 8 ++++---- src/Common/Helper/EncodingHelper.php | 4 ++-- src/Common/Helper/FileSystemHelper.php | 2 +- src/Common/Helper/StringHelper.php | 2 +- src/Reader/CSV/Reader.php | 6 +++--- src/Reader/CSV/RowIterator.php | 4 ++-- src/Reader/CSV/Sheet.php | 2 +- src/Reader/CSV/SheetIterator.php | 2 +- src/Reader/Common/XMLProcessor.php | 2 +- src/Reader/Exception/InvalidValueException.php | 2 +- src/Reader/ODS/Helper/CellValueFormatter.php | 4 ++-- src/Reader/ODS/Reader.php | 2 +- src/Reader/ODS/RowIterator.php | 6 +++--- src/Reader/ODS/Sheet.php | 10 +++++----- src/Reader/ODS/SheetIterator.php | 10 +++++----- src/Reader/XLSX/Helper/CellValueFormatter.php | 10 +++++----- .../CachingStrategyFactory.php | 2 +- .../SharedStringsCaching/FileBasedStrategy.php | 6 +++--- .../Manager/SharedStringsCaching/MemoryLimit.php | 2 +- src/Reader/XLSX/Manager/SharedStringsManager.php | 8 ++++---- src/Reader/XLSX/Manager/SheetManager.php | 8 ++++---- src/Reader/XLSX/Manager/StyleManager.php | 4 ++-- .../XLSX/Manager/WorkbookRelationshipsManager.php | 2 +- src/Reader/XLSX/Reader.php | 4 ++-- src/Reader/XLSX/RowIterator.php | 14 +++++++------- src/Reader/XLSX/Sheet.php | 12 ++++++------ src/Reader/XLSX/SheetHeaderReader.php | 8 ++++---- src/Writer/CSV/Writer.php | 2 +- src/Writer/Common/Entity/Sheet.php | 6 +++--- src/Writer/Common/Entity/Workbook.php | 2 +- src/Writer/Common/Entity/Worksheet.php | 4 ++-- .../Common/Manager/AbstractWorkbookManager.php | 4 ++-- src/Writer/Common/Manager/RegisteredStyle.php | 4 ++-- src/Writer/Common/Manager/SheetManager.php | 2 +- .../Common/Manager/Style/PossiblyUpdatedStyle.php | 4 ++-- src/Writer/ODS/Helper/FileSystemHelper.php | 8 ++++---- src/Writer/ODS/Manager/Style/StyleManager.php | 2 +- src/Writer/ODS/Manager/WorksheetManager.php | 6 +++--- src/Writer/ODS/Writer.php | 2 +- src/Writer/XLSX/Helper/FileSystemHelper.php | 10 +++++----- src/Writer/XLSX/Manager/CommentsManager.php | 4 ++-- src/Writer/XLSX/Manager/SharedStringsManager.php | 2 +- src/Writer/XLSX/Manager/WorksheetManager.php | 14 +++++++------- src/Writer/XLSX/Writer.php | 2 +- tests/TestUsingResource.php | 6 +++--- 52 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/Common/Entity/Cell/BooleanCell.php b/src/Common/Entity/Cell/BooleanCell.php index 120a72b8..ecba8e8c 100644 --- a/src/Common/Entity/Cell/BooleanCell.php +++ b/src/Common/Entity/Cell/BooleanCell.php @@ -9,7 +9,7 @@ final class BooleanCell extends Cell { - private bool $value; + private readonly bool $value; public function __construct(bool $value, ?Style $style) { diff --git a/src/Common/Entity/Cell/DateIntervalCell.php b/src/Common/Entity/Cell/DateIntervalCell.php index a3ce8a01..65d30861 100644 --- a/src/Common/Entity/Cell/DateIntervalCell.php +++ b/src/Common/Entity/Cell/DateIntervalCell.php @@ -10,7 +10,7 @@ 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 diff --git a/src/Common/Entity/Cell/DateTimeCell.php b/src/Common/Entity/Cell/DateTimeCell.php index 7065abf5..bced4006 100644 --- a/src/Common/Entity/Cell/DateTimeCell.php +++ b/src/Common/Entity/Cell/DateTimeCell.php @@ -10,7 +10,7 @@ final class DateTimeCell extends Cell { - private DateTimeInterface $value; + private readonly DateTimeInterface $value; public function __construct(DateTimeInterface $value, ?Style $style) { diff --git a/src/Common/Entity/Cell/EmptyCell.php b/src/Common/Entity/Cell/EmptyCell.php index 8d3e4139..72678b96 100644 --- a/src/Common/Entity/Cell/EmptyCell.php +++ b/src/Common/Entity/Cell/EmptyCell.php @@ -9,7 +9,7 @@ final class EmptyCell extends Cell { - private ?string $value; + private readonly ?string $value; public function __construct(?string $value, ?Style $style) { diff --git a/src/Common/Entity/Cell/ErrorCell.php b/src/Common/Entity/Cell/ErrorCell.php index 2c1d677b..53a445e9 100644 --- a/src/Common/Entity/Cell/ErrorCell.php +++ b/src/Common/Entity/Cell/ErrorCell.php @@ -9,7 +9,7 @@ final class ErrorCell extends Cell { - private string $value; + private readonly string $value; public function __construct(string $value, ?Style $style) { diff --git a/src/Common/Entity/Cell/NumericCell.php b/src/Common/Entity/Cell/NumericCell.php index 810fe111..b0710924 100644 --- a/src/Common/Entity/Cell/NumericCell.php +++ b/src/Common/Entity/Cell/NumericCell.php @@ -9,7 +9,7 @@ final class NumericCell extends Cell { - private int|float $value; + private readonly int|float $value; public function __construct(int|float $value, ?Style $style) { diff --git a/src/Common/Entity/Cell/StringCell.php b/src/Common/Entity/Cell/StringCell.php index 94ffa8fa..85397945 100644 --- a/src/Common/Entity/Cell/StringCell.php +++ b/src/Common/Entity/Cell/StringCell.php @@ -9,7 +9,7 @@ final class StringCell extends Cell { - private string $value; + private readonly string $value; public function __construct(string $value, ?Style $style) { diff --git a/src/Common/Entity/Style/BorderPart.php b/src/Common/Entity/Style/BorderPart.php index e5819e36..8bd9a1ab 100644 --- a/src/Common/Entity/Style/BorderPart.php +++ b/src/Common/Entity/Style/BorderPart.php @@ -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 diff --git a/src/Common/Helper/EncodingHelper.php b/src/Common/Helper/EncodingHelper.php index d1fc51f1..672b8652 100644 --- a/src/Common/Helper/EncodingHelper.php +++ b/src/Common/Helper/EncodingHelper.php @@ -33,9 +33,9 @@ final class EncodingHelper /** @var array 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) { diff --git a/src/Common/Helper/FileSystemHelper.php b/src/Common/Helper/FileSystemHelper.php index 0fb223bb..a742925e 100644 --- a/src/Common/Helper/FileSystemHelper.php +++ b/src/Common/Helper/FileSystemHelper.php @@ -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 diff --git a/src/Common/Helper/StringHelper.php b/src/Common/Helper/StringHelper.php index dfc6d56d..fb5bada0 100644 --- a/src/Common/Helper/StringHelper.php +++ b/src/Common/Helper/StringHelper.php @@ -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) { diff --git a/src/Reader/CSV/Reader.php b/src/Reader/CSV/Reader.php index ac92b53e..bad8abdc 100644 --- a/src/Reader/CSV/Reader.php +++ b/src/Reader/CSV/Reader.php @@ -22,10 +22,10 @@ final class Reader extends AbstractReader private string $originalAutoDetectLineEndings; /** @var bool Whether the code is running with PHP >= 8.1 */ - private bool $isRunningAtLeastPhp81; + private readonly bool $isRunningAtLeastPhp81; - private Options $options; - private EncodingHelper $encodingHelper; + private readonly Options $options; + private readonly EncodingHelper $encodingHelper; public function __construct( ?Options $options = null, diff --git a/src/Reader/CSV/RowIterator.php b/src/Reader/CSV/RowIterator.php index a8b3c7e6..0b665924 100644 --- a/src/Reader/CSV/RowIterator.php +++ b/src/Reader/CSV/RowIterator.php @@ -31,10 +31,10 @@ final class RowIterator implements RowIteratorInterface /** @var bool Indicates whether all rows have been read */ private bool $hasReachedEndOfFile = false; - private Options $options; + private readonly Options $options; /** @var EncodingHelper Helper to work with different encodings */ - private EncodingHelper $encodingHelper; + private readonly EncodingHelper $encodingHelper; /** * @param resource $filePointer Pointer to the CSV file to read diff --git a/src/Reader/CSV/Sheet.php b/src/Reader/CSV/Sheet.php index f4e1be1c..142e6255 100644 --- a/src/Reader/CSV/Sheet.php +++ b/src/Reader/CSV/Sheet.php @@ -12,7 +12,7 @@ final class Sheet implements SheetInterface { /** @var RowIterator To iterate over the CSV's rows */ - private RowIterator $rowIterator; + private readonly RowIterator $rowIterator; /** * @param RowIterator $rowIterator Corresponding row iterator diff --git a/src/Reader/CSV/SheetIterator.php b/src/Reader/CSV/SheetIterator.php index 7bba3aa0..5a2b9153 100644 --- a/src/Reader/CSV/SheetIterator.php +++ b/src/Reader/CSV/SheetIterator.php @@ -12,7 +12,7 @@ final class SheetIterator implements SheetIteratorInterface { /** @var Sheet The CSV unique "sheet" */ - private Sheet $sheet; + private readonly Sheet $sheet; /** @var bool Whether the unique "sheet" has already been read */ private bool $hasReadUniqueSheet = false; diff --git a/src/Reader/Common/XMLProcessor.php b/src/Reader/Common/XMLProcessor.php index 85dff666..af14e16c 100644 --- a/src/Reader/Common/XMLProcessor.php +++ b/src/Reader/Common/XMLProcessor.php @@ -25,7 +25,7 @@ final class XMLProcessor public const PROCESSING_STOP = 2; /** @var XMLReader The XMLReader object that will help read sheet's XML data */ - private XMLReader $xmlReader; + private readonly XMLReader $xmlReader; /** @var array Registered callbacks */ private array $callbacks = []; diff --git a/src/Reader/Exception/InvalidValueException.php b/src/Reader/Exception/InvalidValueException.php index 3f5c4b04..4475e512 100644 --- a/src/Reader/Exception/InvalidValueException.php +++ b/src/Reader/Exception/InvalidValueException.php @@ -8,7 +8,7 @@ final class InvalidValueException extends ReaderException { - private string $invalidValue; + private readonly string $invalidValue; public function __construct(string $invalidValue, string $message = '', int $code = 0, ?Throwable $previous = null) { diff --git a/src/Reader/ODS/Helper/CellValueFormatter.php b/src/Reader/ODS/Helper/CellValueFormatter.php index 3202e6e2..4a16a93e 100644 --- a/src/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Reader/ODS/Helper/CellValueFormatter.php @@ -61,10 +61,10 @@ final class CellValueFormatter ]; /** @var bool Whether date/time values should be returned as PHP objects or be formatted as strings */ - private bool $shouldFormatDates; + private readonly bool $shouldFormatDates; /** @var ODS Used to unescape XML data */ - private ODS $escaper; + private readonly ODS $escaper; /** * @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings diff --git a/src/Reader/ODS/Reader.php b/src/Reader/ODS/Reader.php index 80a6852b..8cb1813c 100644 --- a/src/Reader/ODS/Reader.php +++ b/src/Reader/ODS/Reader.php @@ -17,7 +17,7 @@ final class Reader extends AbstractReader { private ZipArchive $zip; - private Options $options; + private readonly Options $options; /** @var SheetIterator To iterator over the ODS sheets */ private SheetIterator $sheetIterator; diff --git a/src/Reader/ODS/RowIterator.php b/src/Reader/ODS/RowIterator.php index 5a2be91f..caf7666b 100644 --- a/src/Reader/ODS/RowIterator.php +++ b/src/Reader/ODS/RowIterator.php @@ -30,13 +30,13 @@ final class RowIterator implements RowIteratorInterface public const XML_ATTRIBUTE_NUM_ROWS_REPEATED = 'table:number-rows-repeated'; public const XML_ATTRIBUTE_NUM_COLUMNS_REPEATED = 'table:number-columns-repeated'; - private Options $options; + private readonly Options $options; /** @var XMLProcessor Helper Object to process XML nodes */ - private XMLProcessor $xmlProcessor; + private readonly XMLProcessor $xmlProcessor; /** @var Helper\CellValueFormatter Helper to format cell values */ - private Helper\CellValueFormatter $cellValueFormatter; + private readonly Helper\CellValueFormatter $cellValueFormatter; /** @var bool Whether the iterator has already been rewound once */ private bool $hasAlreadyBeenRewound = false; diff --git a/src/Reader/ODS/Sheet.php b/src/Reader/ODS/Sheet.php index 7f71d0a0..52917b58 100644 --- a/src/Reader/ODS/Sheet.php +++ b/src/Reader/ODS/Sheet.php @@ -12,19 +12,19 @@ final class Sheet implements SheetWithVisibilityInterface { /** @var RowIterator To iterate over sheet's rows */ - private RowIterator $rowIterator; + private readonly RowIterator $rowIterator; /** @var int Index of the sheet, based on order in the workbook (zero-based) */ - private int $index; + private readonly int $index; /** @var string Name of the sheet */ - private string $name; + private readonly string $name; /** @var bool Whether the sheet was the active one */ - private bool $isActive; + private readonly bool $isActive; /** @var bool Whether the sheet is visible */ - private bool $isVisible; + private readonly bool $isVisible; /** * @param RowIterator $rowIterator The corresponding row iterator diff --git a/src/Reader/ODS/SheetIterator.php b/src/Reader/ODS/SheetIterator.php index 9d66d106..84b840ea 100644 --- a/src/Reader/ODS/SheetIterator.php +++ b/src/Reader/ODS/SheetIterator.php @@ -35,15 +35,15 @@ final class SheetIterator implements SheetIteratorInterface public const XML_ATTRIBUTE_TABLE_DISPLAY = 'table:display'; /** @var string Path of the file to be read */ - private string $filePath; + private readonly string $filePath; - private Options $options; + private readonly Options $options; /** @var XMLReader The XMLReader object that will help read sheet's XML data */ - private XMLReader $xmlReader; + private readonly XMLReader $xmlReader; /** @var ODS Used to unescape XML data */ - private ODS $escaper; + private readonly ODS $escaper; /** @var bool Whether there are still at least a sheet to be read */ private bool $hasFoundSheet; @@ -52,7 +52,7 @@ final class SheetIterator implements SheetIteratorInterface private int $currentSheetIndex; /** @var string The name of the sheet that was defined as active */ - private ?string $activeSheetName; + private readonly ?string $activeSheetName; /** @var array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */ private array $sheetsVisibility; diff --git a/src/Reader/XLSX/Helper/CellValueFormatter.php b/src/Reader/XLSX/Helper/CellValueFormatter.php index 14ccb44a..540fad7a 100644 --- a/src/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Reader/XLSX/Helper/CellValueFormatter.php @@ -48,19 +48,19 @@ final class CellValueFormatter public const NUM_SECONDS_IN_ONE_DAY = 86400; /** @var SharedStringsManager Manages shared strings */ - private SharedStringsManager $sharedStringsManager; + private readonly SharedStringsManager $sharedStringsManager; /** @var StyleManagerInterface Manages styles */ - private StyleManagerInterface $styleManager; + private readonly StyleManagerInterface $styleManager; /** @var bool Whether date/time values should be returned as PHP objects or be formatted as strings */ - private bool $shouldFormatDates; + private readonly bool $shouldFormatDates; /** @var bool Whether date/time values should use a calendar starting in 1904 instead of 1900 */ - private bool $shouldUse1904Dates; + private readonly bool $shouldUse1904Dates; /** @var XLSX Used to unescape XML data */ - private XLSX $escaper; + private readonly XLSX $escaper; /** * @param SharedStringsManager $sharedStringsManager Manages shared strings diff --git a/src/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php b/src/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php index ac1a71d6..749e6285 100644 --- a/src/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php +++ b/src/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php @@ -50,7 +50,7 @@ final class CachingStrategyFactory implements CachingStrategyFactoryInterface */ public const MAX_NUM_STRINGS_PER_TEMP_FILE = 10000; - private MemoryLimit $memoryLimit; + private readonly MemoryLimit $memoryLimit; public function __construct(MemoryLimit $memoryLimit) { diff --git a/src/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php b/src/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php index c956064d..f6e3fea1 100644 --- a/src/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php +++ b/src/Reader/XLSX/Manager/SharedStringsCaching/FileBasedStrategy.php @@ -22,17 +22,17 @@ final class FileBasedStrategy implements CachingStrategyInterface public const ESCAPED_LINE_FEED_CHARACTER = '_x000A_'; /** @var FileSystemHelper Helper to perform file system operations */ - private FileSystemHelper $fileSystemHelper; + private readonly FileSystemHelper $fileSystemHelper; /** @var string Temporary folder where the temporary files will be created */ - private string $tempFolder; + private readonly string $tempFolder; /** * @var int Maximum number of strings that can be stored in one temp file * * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE */ - private int $maxNumStringsPerTempFile; + private readonly int $maxNumStringsPerTempFile; /** @var null|resource Pointer to the last temp file a shared string was written to */ private $tempFilePointer; diff --git a/src/Reader/XLSX/Manager/SharedStringsCaching/MemoryLimit.php b/src/Reader/XLSX/Manager/SharedStringsCaching/MemoryLimit.php index e9d76286..5645908f 100644 --- a/src/Reader/XLSX/Manager/SharedStringsCaching/MemoryLimit.php +++ b/src/Reader/XLSX/Manager/SharedStringsCaching/MemoryLimit.php @@ -9,7 +9,7 @@ */ final class MemoryLimit { - private string $memoryLimit; + private readonly string $memoryLimit; public function __construct(string $memoryLimit) { diff --git a/src/Reader/XLSX/Manager/SharedStringsManager.php b/src/Reader/XLSX/Manager/SharedStringsManager.php index 9a129a18..1cc9e00d 100644 --- a/src/Reader/XLSX/Manager/SharedStringsManager.php +++ b/src/Reader/XLSX/Manager/SharedStringsManager.php @@ -34,15 +34,15 @@ final class SharedStringsManager public const XML_ATTRIBUTE_VALUE_PRESERVE = 'preserve'; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; - private Options $options; + private readonly Options $options; /** @var WorkbookRelationshipsManager Helps retrieving workbook relationships */ - private WorkbookRelationshipsManager $workbookRelationshipsManager; + private readonly WorkbookRelationshipsManager $workbookRelationshipsManager; /** @var CachingStrategyFactoryInterface Factory to create shared strings caching strategies */ - private CachingStrategyFactoryInterface $cachingStrategyFactory; + private readonly CachingStrategyFactoryInterface $cachingStrategyFactory; /** @var CachingStrategyInterface The best caching strategy for storing shared strings */ private CachingStrategyInterface $cachingStrategy; diff --git a/src/Reader/XLSX/Manager/SheetManager.php b/src/Reader/XLSX/Manager/SheetManager.php index 296cba3f..b344b01d 100644 --- a/src/Reader/XLSX/Manager/SheetManager.php +++ b/src/Reader/XLSX/Manager/SheetManager.php @@ -51,15 +51,15 @@ final class SheetManager public const SHEET_STATE_HIDDEN = 'hidden'; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; - private Options $options; + private readonly Options $options; /** @var SharedStringsManager Manages shared strings */ - private SharedStringsManager $sharedStringsManager; + private readonly SharedStringsManager $sharedStringsManager; /** @var XLSX Used to unescape XML data */ - private XLSX $escaper; + private readonly XLSX $escaper; /** @var Sheet[] List of sheets */ private array $sheets; diff --git a/src/Reader/XLSX/Manager/StyleManager.php b/src/Reader/XLSX/Manager/StyleManager.php index a646dc43..ece3c010 100644 --- a/src/Reader/XLSX/Manager/StyleManager.php +++ b/src/Reader/XLSX/Manager/StyleManager.php @@ -52,10 +52,10 @@ class StyleManager implements StyleManagerInterface ]; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; /** @var null|string Path of the styles XML file */ - private ?string $stylesXMLFilePath; + private readonly ?string $stylesXMLFilePath; /** @var array Array containing a mapping NUM_FMT_ID => FORMAT_CODE */ private array $customNumberFormats; diff --git a/src/Reader/XLSX/Manager/WorkbookRelationshipsManager.php b/src/Reader/XLSX/Manager/WorkbookRelationshipsManager.php index 1c3e209c..316620e5 100644 --- a/src/Reader/XLSX/Manager/WorkbookRelationshipsManager.php +++ b/src/Reader/XLSX/Manager/WorkbookRelationshipsManager.php @@ -35,7 +35,7 @@ final class WorkbookRelationshipsManager public const XML_ATTRIBUTE_TARGET = 'Target'; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; /** @var array Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */ private array $cachedWorkbookRelationships; diff --git a/src/Reader/XLSX/Reader.php b/src/Reader/XLSX/Reader.php index a87b78e1..7ba06994 100644 --- a/src/Reader/XLSX/Reader.php +++ b/src/Reader/XLSX/Reader.php @@ -28,8 +28,8 @@ final class Reader extends AbstractReader /** @var SheetIterator To iterator over the XLSX sheets */ private SheetIterator $sheetIterator; - private Options $options; - private CachingStrategyFactoryInterface $cachingStrategyFactory; + private readonly Options $options; + private readonly CachingStrategyFactoryInterface $cachingStrategyFactory; public function __construct( ?Options $options = null, diff --git a/src/Reader/XLSX/RowIterator.php b/src/Reader/XLSX/RowIterator.php index 44871339..d5e58a81 100644 --- a/src/Reader/XLSX/RowIterator.php +++ b/src/Reader/XLSX/RowIterator.php @@ -34,22 +34,22 @@ final class RowIterator implements RowIteratorInterface public const XML_ATTRIBUTE_CELL_INDEX = 'r'; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; /** @var string Path of the sheet data XML file as in [Content_Types].xml */ - private string $sheetDataXMLFilePath; + private readonly string $sheetDataXMLFilePath; /** @var XMLReader The XMLReader object that will help read sheet's XML data */ - private XMLReader $xmlReader; + private readonly XMLReader $xmlReader; /** @var XMLProcessor Helper Object to process XML nodes */ - private XMLProcessor $xmlProcessor; + private readonly XMLProcessor $xmlProcessor; /** @var Helper\CellValueFormatter Helper to format cell values */ - private Helper\CellValueFormatter $cellValueFormatter; + private readonly Helper\CellValueFormatter $cellValueFormatter; /** @var RowManager Manages rows */ - private RowManager $rowManager; + private readonly RowManager $rowManager; /** * TODO: This variable can be deleted when row indices get preserved. @@ -71,7 +71,7 @@ final class RowIterator implements RowIteratorInterface private int $numColumns = 0; /** @var bool Whether empty rows should be returned or skipped */ - private bool $shouldPreserveEmptyRows; + private readonly bool $shouldPreserveEmptyRows; /** @var int Last row index processed (one-based) */ private int $lastRowIndexProcessed = 0; diff --git a/src/Reader/XLSX/Sheet.php b/src/Reader/XLSX/Sheet.php index dc671234..504b20ed 100644 --- a/src/Reader/XLSX/Sheet.php +++ b/src/Reader/XLSX/Sheet.php @@ -13,22 +13,22 @@ final class Sheet implements SheetWithVisibilityInterface { /** @var RowIterator To iterate over sheet's rows */ - private RowIterator $rowIterator; + private readonly RowIterator $rowIterator; /** @var SheetHeaderReader To read the header of the sheet, containing for instance the col widths */ - private SheetHeaderReader $headerReader; + private readonly SheetHeaderReader $headerReader; /** @var int Index of the sheet, based on order in the workbook (zero-based) */ - private int $index; + private readonly int $index; /** @var string Name of the sheet */ - private string $name; + private readonly string $name; /** @var bool Whether the sheet was the active one */ - private bool $isActive; + private readonly bool $isActive; /** @var bool Whether the sheet is visible */ - private bool $isVisible; + private readonly bool $isVisible; /** * @param RowIterator $rowIterator The corresponding row iterator diff --git a/src/Reader/XLSX/SheetHeaderReader.php b/src/Reader/XLSX/SheetHeaderReader.php index ea4be2bb..5c6b4296 100644 --- a/src/Reader/XLSX/SheetHeaderReader.php +++ b/src/Reader/XLSX/SheetHeaderReader.php @@ -18,16 +18,16 @@ final class SheetHeaderReader public const XML_ATTRIBUTE_WIDTH = 'width'; /** @var string Path of the XLSX file being read */ - private string $filePath; + private readonly string $filePath; /** @var string Path of the sheet data XML file as in [Content_Types].xml */ - private string $sheetDataXMLFilePath; + private readonly string $sheetDataXMLFilePath; /** @var XMLReader The XMLReader object that will help read sheet's XML data */ - private XMLReader $xmlReader; + private readonly XMLReader $xmlReader; /** @var XMLProcessor Helper Object to process XML nodes */ - private XMLProcessor $xmlProcessor; + private readonly XMLProcessor $xmlProcessor; /** @var ColumnWidth[] The widths of the columns in the sheet, if specified */ private array $columnWidths = []; diff --git a/src/Writer/CSV/Writer.php b/src/Writer/CSV/Writer.php index f3d94e48..98cdcf0e 100644 --- a/src/Writer/CSV/Writer.php +++ b/src/Writer/CSV/Writer.php @@ -15,7 +15,7 @@ final class Writer extends AbstractWriter /** @var string Content-Type value for the header */ protected static string $headerContentType = 'text/csv; charset=UTF-8'; - private Options $options; + private readonly Options $options; private int $lastWrittenRowIndex = 0; diff --git a/src/Writer/Common/Entity/Sheet.php b/src/Writer/Common/Entity/Sheet.php index fb41a722..9fe0c837 100644 --- a/src/Writer/Common/Entity/Sheet.php +++ b/src/Writer/Common/Entity/Sheet.php @@ -17,10 +17,10 @@ final class Sheet public const DEFAULT_SHEET_NAME_PREFIX = 'Sheet'; /** @var 0|positive-int Index of the sheet, based on order in the workbook (zero-based) */ - private int $index; + private readonly int $index; /** @var string ID of the sheet's associated workbook. Used to restrict sheet name uniqueness enforcement to a single workbook */ - private string $associatedWorkbookId; + private readonly string $associatedWorkbookId; /** @var string Name of the sheet */ private string $name; @@ -29,7 +29,7 @@ final class Sheet private bool $isVisible; /** @var SheetManager Sheet manager */ - private SheetManager $sheetManager; + private readonly SheetManager $sheetManager; private ?SheetView $sheetView = null; diff --git a/src/Writer/Common/Entity/Workbook.php b/src/Writer/Common/Entity/Workbook.php index e179c513..85950863 100644 --- a/src/Writer/Common/Entity/Workbook.php +++ b/src/Writer/Common/Entity/Workbook.php @@ -13,7 +13,7 @@ final class Workbook private array $worksheets = []; /** @var string Timestamp based unique ID identifying the workbook */ - private string $internalId; + private readonly string $internalId; /** * Workbook constructor. diff --git a/src/Writer/Common/Entity/Worksheet.php b/src/Writer/Common/Entity/Worksheet.php index 71de8874..f1db1cbf 100644 --- a/src/Writer/Common/Entity/Worksheet.php +++ b/src/Writer/Common/Entity/Worksheet.php @@ -10,13 +10,13 @@ final class Worksheet { /** @var string Path to the XML file that will contain the sheet data */ - private string $filePath; + private readonly string $filePath; /** @var null|resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */ private $filePointer; /** @var Sheet The "external" sheet */ - private Sheet $externalSheet; + private readonly Sheet $externalSheet; /** @var int Maximum number of columns among all the written rows */ private int $maxNumColumns = 0; diff --git a/src/Writer/Common/Manager/AbstractWorkbookManager.php b/src/Writer/Common/Manager/AbstractWorkbookManager.php index 3411b140..2a8ba3b3 100644 --- a/src/Writer/Common/Manager/AbstractWorkbookManager.php +++ b/src/Writer/Common/Manager/AbstractWorkbookManager.php @@ -32,10 +32,10 @@ abstract class AbstractWorkbookManager implements WorkbookManagerInterface protected AbstractOptions $options; /** @var Workbook The workbook to manage */ - private Workbook $workbook; + private readonly Workbook $workbook; /** @var StyleMerger Helper to merge styles */ - private StyleMerger $styleMerger; + private readonly StyleMerger $styleMerger; /** @var Worksheet The worksheet where data will be written to */ private Worksheet $currentWorksheet; diff --git a/src/Writer/Common/Manager/RegisteredStyle.php b/src/Writer/Common/Manager/RegisteredStyle.php index 1144cee5..ff7fe380 100644 --- a/src/Writer/Common/Manager/RegisteredStyle.php +++ b/src/Writer/Common/Manager/RegisteredStyle.php @@ -13,9 +13,9 @@ */ final class RegisteredStyle { - private Style $style; + private readonly Style $style; - private bool $isMatchingRowStyle; + private readonly bool $isMatchingRowStyle; public function __construct(Style $style, bool $isMatchingRowStyle) { diff --git a/src/Writer/Common/Manager/SheetManager.php b/src/Writer/Common/Manager/SheetManager.php index 937093f4..8f0571a5 100644 --- a/src/Writer/Common/Manager/SheetManager.php +++ b/src/Writer/Common/Manager/SheetManager.php @@ -26,7 +26,7 @@ final class SheetManager /** @var array> Associative array [WORKBOOK_ID] => [[SHEET_INDEX] => [SHEET_NAME]] keeping track of sheets' name to enforce uniqueness per workbook */ private static array $SHEETS_NAME_USED = []; - private StringHelper $stringHelper; + private readonly StringHelper $stringHelper; /** * SheetManager constructor. diff --git a/src/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php b/src/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php index c147c35a..ac6ae858 100644 --- a/src/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php +++ b/src/Writer/Common/Manager/Style/PossiblyUpdatedStyle.php @@ -11,8 +11,8 @@ */ final class PossiblyUpdatedStyle { - private Style $style; - private bool $isUpdated; + private readonly Style $style; + private readonly bool $isUpdated; public function __construct(Style $style, bool $isUpdated) { diff --git a/src/Writer/ODS/Helper/FileSystemHelper.php b/src/Writer/ODS/Helper/FileSystemHelper.php index a2545eae..0459f97a 100644 --- a/src/Writer/ODS/Helper/FileSystemHelper.php +++ b/src/Writer/ODS/Helper/FileSystemHelper.php @@ -27,11 +27,11 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface public const MIMETYPE_FILE_NAME = 'mimetype'; public const STYLES_XML_FILE_NAME = 'styles.xml'; - private string $baseFolderRealPath; + private readonly string $baseFolderRealPath; /** @var string document creator */ - private string $creator; - private CommonFileSystemHelper $baseFileSystemHelper; + private readonly string $creator; + private readonly CommonFileSystemHelper $baseFileSystemHelper; /** @var string Path to the root folder inside the temp folder where the files to create the ODS will be stored */ private string $rootFolder; @@ -43,7 +43,7 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface private string $sheetsContentTempFolder; /** @var ZipHelper Helper to perform tasks with Zip archive */ - private ZipHelper $zipHelper; + private readonly ZipHelper $zipHelper; /** * @param string $baseFolderPath The path of the base folder where all the I/O can occur diff --git a/src/Writer/ODS/Manager/Style/StyleManager.php b/src/Writer/ODS/Manager/Style/StyleManager.php index 967d33de..ca516d6e 100644 --- a/src/Writer/ODS/Manager/Style/StyleManager.php +++ b/src/Writer/ODS/Manager/Style/StyleManager.php @@ -22,7 +22,7 @@ */ final class StyleManager extends CommonStyleManager { - private AbstractOptions $options; + private readonly AbstractOptions $options; public function __construct(StyleRegistry $styleRegistry, AbstractOptions $options) { diff --git a/src/Writer/ODS/Manager/WorksheetManager.php b/src/Writer/ODS/Manager/WorksheetManager.php index c77f72f4..1a388dbd 100644 --- a/src/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Writer/ODS/Manager/WorksheetManager.php @@ -25,13 +25,13 @@ final class WorksheetManager implements WorksheetManagerInterface { /** @var ODSEscaper Strings escaper */ - private ODSEscaper $stringsEscaper; + private readonly ODSEscaper $stringsEscaper; /** @var StyleManager Manages styles */ - private StyleManager $styleManager; + private readonly StyleManager $styleManager; /** @var StyleMerger Helper to merge styles together */ - private StyleMerger $styleMerger; + private readonly StyleMerger $styleMerger; /** * WorksheetManager constructor. diff --git a/src/Writer/ODS/Writer.php b/src/Writer/ODS/Writer.php index 665e186b..fbbb56c0 100644 --- a/src/Writer/ODS/Writer.php +++ b/src/Writer/ODS/Writer.php @@ -19,7 +19,7 @@ final class Writer extends AbstractWriterMultiSheets { /** @var string Content-Type value for the header */ protected static string $headerContentType = 'application/vnd.oasis.opendocument.spreadsheet'; - private Options $options; + private readonly Options $options; public function __construct(?Options $options = null) { diff --git a/src/Writer/XLSX/Helper/FileSystemHelper.php b/src/Writer/XLSX/Helper/FileSystemHelper.php index 4f0c8106..545dd576 100644 --- a/src/Writer/XLSX/Helper/FileSystemHelper.php +++ b/src/Writer/XLSX/Helper/FileSystemHelper.php @@ -40,17 +40,17 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface EOD; - private string $baseFolderRealPath; - private CommonFileSystemHelper $baseFileSystemHelper; + private readonly string $baseFolderRealPath; + private readonly CommonFileSystemHelper $baseFileSystemHelper; /** @var ZipHelper Helper to perform tasks with Zip archive */ - private ZipHelper $zipHelper; + private readonly ZipHelper $zipHelper; /** @var string document creator */ - private string $creator; + private readonly string $creator; /** @var XLSX Used to escape XML data */ - private XLSX $escaper; + private readonly XLSX $escaper; /** @var string Path to the root folder inside the temp folder where the files to create the XLSX will be stored */ private string $rootFolder; diff --git a/src/Writer/XLSX/Manager/CommentsManager.php b/src/Writer/XLSX/Manager/CommentsManager.php index 525289c3..b86c1a47 100644 --- a/src/Writer/XLSX/Manager/CommentsManager.php +++ b/src/Writer/XLSX/Manager/CommentsManager.php @@ -64,11 +64,11 @@ final class CommentsManager */ private array $drawingFilePointers = []; - private string $xlFolder; + private readonly string $xlFolder; private int $shapeId = 1024; - private Escaper\XLSX $stringsEscaper; + private readonly Escaper\XLSX $stringsEscaper; /** * @param string $xlFolder Path to the "xl" folder diff --git a/src/Writer/XLSX/Manager/SharedStringsManager.php b/src/Writer/XLSX/Manager/SharedStringsManager.php index 3b232c7b..8f472ebb 100644 --- a/src/Writer/XLSX/Manager/SharedStringsManager.php +++ b/src/Writer/XLSX/Manager/SharedStringsManager.php @@ -31,7 +31,7 @@ final class SharedStringsManager private int $numSharedStrings = 0; /** @var Escaper\XLSX Strings escaper */ - private Escaper\XLSX $stringsEscaper; + private readonly Escaper\XLSX $stringsEscaper; /** * @param string $xlFolder Path to the "xl" folder diff --git a/src/Writer/XLSX/Manager/WorksheetManager.php b/src/Writer/XLSX/Manager/WorksheetManager.php index 6143c376..94ca09c8 100644 --- a/src/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Writer/XLSX/Manager/WorksheetManager.php @@ -36,24 +36,24 @@ final class WorksheetManager implements WorksheetManagerInterface public const MAX_CHARACTERS_PER_CELL = 32767; /** @var CommentsManager Manages comments */ - private CommentsManager $commentsManager; + private readonly CommentsManager $commentsManager; - private Options $options; + private readonly Options $options; /** @var StyleManager Manages styles */ - private StyleManager $styleManager; + private readonly StyleManager $styleManager; /** @var StyleMerger Helper to merge styles together */ - private StyleMerger $styleMerger; + private readonly StyleMerger $styleMerger; /** @var SharedStringsManager Helper to write shared strings */ - private SharedStringsManager $sharedStringsManager; + private readonly SharedStringsManager $sharedStringsManager; /** @var XLSXEscaper Strings escaper */ - private XLSXEscaper $stringsEscaper; + private readonly XLSXEscaper $stringsEscaper; /** @var StringHelper String helper */ - private StringHelper $stringHelper; + private readonly StringHelper $stringHelper; /** * WorksheetManager constructor. diff --git a/src/Writer/XLSX/Writer.php b/src/Writer/XLSX/Writer.php index 3fdbecb5..cab0676a 100644 --- a/src/Writer/XLSX/Writer.php +++ b/src/Writer/XLSX/Writer.php @@ -23,7 +23,7 @@ final class Writer extends AbstractWriterMultiSheets /** @var string Content-Type value for the header */ protected static string $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - private Options $options; + private readonly Options $options; public function __construct(?Options $options = null) { diff --git a/tests/TestUsingResource.php b/tests/TestUsingResource.php index beb07aed..83bad3de 100644 --- a/tests/TestUsingResource.php +++ b/tests/TestUsingResource.php @@ -16,13 +16,13 @@ final class TestUsingResource private const RESOURCES_PATH = 'tests/resources'; /** @var string Path to the test generated resources folder */ - private string $generatedResourcesPath; + private readonly string $generatedResourcesPath; /** @var string Path to the test resources folder, that does not have writing permissions */ - private string $generatedUnwritableResourcesPath; + private readonly string $generatedUnwritableResourcesPath; /** @var string Path to the test temp folder */ - private string $tempFolderPath; + private readonly string $tempFolderPath; public function __construct() {