Skip to content

Commit

Permalink
Add readonly property to prevent modification (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k authored Sep 25, 2023
1 parent c2549bc commit b95a0ac
Show file tree
Hide file tree
Showing 52 changed files with 122 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/Common/Entity/Cell/BooleanCell.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Common/Entity/Cell/DateIntervalCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Entity/Cell/DateTimeCell.php
Original file line number Diff line number Diff line change
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 src/Common/Entity/Cell/EmptyCell.php
Original file line number Diff line number Diff line change
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 src/Common/Entity/Cell/ErrorCell.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Common/Entity/Cell/NumericCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Entity/Cell/StringCell.php
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions src/Common/Entity/Style/BorderPart.php
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/Common/Helper/EncodingHelper.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Common/Helper/FileSystemHelper.php
Original file line number Diff line number Diff line change
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 Down
2 changes: 1 addition & 1 deletion src/Common/Helper/StringHelper.php
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions src/Reader/CSV/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/CSV/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/CSV/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/CSV/SheetIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Common/XMLProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array{reflectionMethod: ReflectionMethod, reflectionObject: object}> Registered callbacks */
private array $callbacks = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Exception/InvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/ODS/Helper/CellValueFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/ODS/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Reader/ODS/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/Reader/ODS/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Reader/ODS/SheetIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, bool> Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */
private array $sheetsVisibility;
Expand Down
10 changes: 5 additions & 5 deletions src/Reader/XLSX/Helper/CellValueFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class MemoryLimit
{
private string $memoryLimit;
private readonly string $memoryLimit;

public function __construct(string $memoryLimit)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Reader/XLSX/Manager/SharedStringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Reader/XLSX/Manager/SheetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/XLSX/Manager/StyleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string> Array containing a mapping NUM_FMT_ID => FORMAT_CODE */
private array $customNumberFormats;
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/XLSX/Manager/WorkbookRelationshipsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */
private array $cachedWorkbookRelationships;
Expand Down
Loading

0 comments on commit b95a0ac

Please sign in to comment.