From 5179781ab9ee4eed817edee37c0619ee798ccb96 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 30 Oct 2020 10:48:54 +0100 Subject: [PATCH 01/41] Starting work on ensuring that all methods are properly typehinted (arguments and returns) and that all argument names for public methods are meaningful (in readiness for PHP8 named arguments) --- src/PhpSpreadsheet/Comment.php | 80 ++++++++++++++++++------------ src/PhpSpreadsheet/IOFactory.php | 17 ++++--- src/PhpSpreadsheet/Settings.php | 12 ++--- src/PhpSpreadsheet/Style/Color.php | 55 +++++++++++++------- src/PhpSpreadsheet/Style/Style.php | 2 +- 5 files changed, 103 insertions(+), 63 deletions(-) diff --git a/src/PhpSpreadsheet/Comment.php b/src/PhpSpreadsheet/Comment.php index 31f76640..12fb0e22 100644 --- a/src/PhpSpreadsheet/Comment.php +++ b/src/PhpSpreadsheet/Comment.php @@ -3,6 +3,8 @@ namespace PhpOffice\PhpSpreadsheet; use PhpOffice\PhpSpreadsheet\RichText\RichText; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Color; class Comment implements IComparable { @@ -58,7 +60,7 @@ class Comment implements IComparable /** * Comment fill color. * - * @var Style\Color + * @var Color */ private $fillColor; @@ -77,8 +79,8 @@ class Comment implements IComparable // Initialise variables $this->author = 'Author'; $this->text = new RichText(); - $this->fillColor = new Style\Color('FFFFFFE1'); - $this->alignment = Style\Alignment::HORIZONTAL_GENERAL; + $this->fillColor = new Color('FFFFFFE1'); + $this->alignment = Alignment::HORIZONTAL_GENERAL; } /** @@ -86,7 +88,7 @@ class Comment implements IComparable * * @return string */ - public function getAuthor() + public function getAuthor(): string { return $this->author; } @@ -98,7 +100,7 @@ class Comment implements IComparable * * @return $this */ - public function setAuthor($author) + public function setAuthor(string $author) { $this->author = $author; @@ -110,7 +112,7 @@ class Comment implements IComparable * * @return RichText */ - public function getText() + public function getText(): RichText { return $this->text; } @@ -118,11 +120,13 @@ class Comment implements IComparable /** * Set Rich text comment. * + * @param RichText $text + * * @return $this */ - public function setText(RichText $pValue) + public function setText(RichText $text) { - $this->text = $pValue; + $this->text = $text; return $this; } @@ -132,7 +136,7 @@ class Comment implements IComparable * * @return string */ - public function getWidth() + public function getWidth(): string { return $this->width; } @@ -140,11 +144,11 @@ class Comment implements IComparable /** * Set comment width (CSS style, i.e. XXpx or YYpt). * - * @param string $width + * @param string $width including units (px or pt) * * @return $this */ - public function setWidth($width) + public function setWidth(string $width) { $this->width = $width; @@ -156,7 +160,7 @@ class Comment implements IComparable * * @return string */ - public function getHeight() + public function getHeight(): string { return $this->height; } @@ -164,13 +168,13 @@ class Comment implements IComparable /** * Set comment height (CSS style, i.e. XXpx or YYpt). * - * @param string $value + * @param string $height including units (px or pt) * * @return $this */ - public function setHeight($value) + public function setHeight(string $height) { - $this->height = $value; + $this->height = $height; return $this; } @@ -180,7 +184,7 @@ class Comment implements IComparable * * @return string */ - public function getMarginLeft() + public function getMarginLeft(): string { return $this->marginLeft; } @@ -188,13 +192,13 @@ class Comment implements IComparable /** * Set left margin (CSS style, i.e. XXpx or YYpt). * - * @param string $value + * @param string $margin including units (px or pt) * * @return $this */ - public function setMarginLeft($value) + public function setMarginLeft(string $margin) { - $this->marginLeft = $value; + $this->marginLeft = $margin; return $this; } @@ -204,7 +208,7 @@ class Comment implements IComparable * * @return string */ - public function getMarginTop() + public function getMarginTop(): string { return $this->marginTop; } @@ -212,13 +216,13 @@ class Comment implements IComparable /** * Set top margin (CSS style, i.e. XXpx or YYpt). * - * @param string $value + * @param string $margin including units (px or pt) * * @return $this */ - public function setMarginTop($value) + public function setMarginTop(string $margin) { - $this->marginTop = $value; + $this->marginTop = $margin; return $this; } @@ -228,7 +232,7 @@ class Comment implements IComparable * * @return bool */ - public function getVisible() + public function getVisible(): bool { return $this->visible; } @@ -236,13 +240,27 @@ class Comment implements IComparable /** * Set comment default visibility. * - * @param bool $value + * @param bool $visibility * * @return $this */ - public function setVisible($value) + public function setVisible(bool $visibility) { - $this->visible = $value; + $this->visible = $visibility; + + return $this; + } + + /** + * Set fill color. + * + * @param Color $color + * + * @return $this + */ + public function setFillColor(Color $color) + { + $this->fillColor = $color; return $this; } @@ -250,9 +268,9 @@ class Comment implements IComparable /** * Get fill color. * - * @return Style\Color + * @return Color */ - public function getFillColor() + public function getFillColor(): Color { return $this->fillColor; } @@ -260,11 +278,11 @@ class Comment implements IComparable /** * Set Alignment. * - * @param string $alignment see Style\Alignment::HORIZONTAL_* + * @param string $alignment see Alignment::HORIZONTAL_* * * @return $this */ - public function setAlignment($alignment) + public function setAlignment(string $alignment): string { $this->alignment = $alignment; diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index ab04e969..f3ce6a30 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet; use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Writer\IWriter; /** * Factory to create readers and writers easily. @@ -41,7 +42,7 @@ abstract class IOFactory * * @return Writer\IWriter */ - public static function createWriter(Spreadsheet $spreadsheet, $writerType) + public static function createWriter(Spreadsheet $spreadsheet, string $writerType): Writer\IWriter { if (!isset(self::$writers[$writerType])) { throw new Writer\Exception("No writer found for type $writerType"); @@ -60,7 +61,7 @@ abstract class IOFactory * * @return Reader\IReader */ - public static function createReader($readerType) + public static function createReader(string $readerType): Reader\IReader { if (!isset(self::$readers[$readerType])) { throw new Reader\Exception("No reader found for type $readerType"); @@ -79,7 +80,7 @@ abstract class IOFactory * * @return Spreadsheet */ - public static function load($pFilename) + public static function load(string $pFilename): Spreadsheet { $reader = self::createReaderForFile($pFilename); @@ -93,7 +94,7 @@ abstract class IOFactory * * @return string */ - public static function identify($pFilename) + public static function identify(string $pFilename): string { $reader = self::createReaderForFile($pFilename); $className = get_class($reader); @@ -110,7 +111,7 @@ abstract class IOFactory * * @return Reader\IReader */ - public static function createReaderForFile($filename) + public static function createReaderForFile(string $filename): Reader\IReader { File::assertFile($filename); @@ -147,7 +148,7 @@ abstract class IOFactory * * @return null|string */ - private static function getReaderTypeFromExtension($filename) + private static function getReaderTypeFromExtension(string $filename): ?string { $pathinfo = pathinfo($filename); if (!isset($pathinfo['extension'])) { @@ -191,7 +192,7 @@ abstract class IOFactory * @param string $writerType * @param string $writerClass */ - public static function registerWriter($writerType, $writerClass): void + public static function registerWriter(string $writerType, string $writerClass): void { if (!is_a($writerClass, Writer\IWriter::class, true)) { throw new Writer\Exception('Registered writers must implement ' . Writer\IWriter::class); @@ -206,7 +207,7 @@ abstract class IOFactory * @param string $readerType * @param string $readerClass */ - public static function registerReader($readerType, $readerClass): void + public static function registerReader(string $readerType, string $readerClass): void { if (!is_a($readerClass, Reader\IReader::class, true)) { throw new Reader\Exception('Registered readers must implement ' . Reader\IReader::class); diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index cfa50573..1b760578 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -63,7 +63,7 @@ class Settings * * @return bool Success or failure */ - public static function setLocale($locale) + public static function setLocale(string $locale) { return Calculation::getInstance()->setLocale($locale); } @@ -74,7 +74,7 @@ class Settings * @param string $rendererClass Class name of the chart renderer * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph */ - public static function setChartRenderer($rendererClass): void + public static function setChartRenderer(string $rendererClass): void { if (!is_a($rendererClass, IRenderer::class, true)) { throw new Exception('Chart renderer must implement ' . IRenderer::class); @@ -89,7 +89,7 @@ class Settings * @return null|string Class name of the chart renderer * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph */ - public static function getChartRenderer() + public static function getChartRenderer(): string { return self::$chartRenderer; } @@ -113,7 +113,7 @@ class Settings * * @return int Default options for libxml loader */ - public static function getLibXmlLoaderOptions() + public static function getLibXmlLoaderOptions(): int { if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) { self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR); @@ -144,7 +144,7 @@ class Settings * * @return bool $state */ - public static function getLibXmlDisableEntityLoader() + public static function getLibXmlDisableEntityLoader(): bool { return self::$libXmlDisableEntityLoader; } @@ -162,7 +162,7 @@ class Settings * * @return CacheInterface */ - public static function getCache() + public static function getCache(): CacheInterface { if (!self::$cache) { self::$cache = new Memory(); diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index d8ba08b2..78c860fb 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -27,6 +27,9 @@ class Color extends Supervisor const COLOR_YELLOW = 'FFFFFF00'; const COLOR_DARKYELLOW = 'FF808000'; + const VALIDATE_ARGB = '/^[A-F0-9]{8}$/i'; + const VALIDATE_RGB = '/^[A-F0-9]{6}$/i'; + /** * Indexed colors array. * @@ -44,7 +47,7 @@ class Color extends Supervisor /** * Create a new Color. * - * @param string $pARGB ARGB value for the colour + * @param string $colorValue ARGB value for the colour, or named colour * @param bool $isSupervisor Flag indicating if this is a supervisor or not * Leave this value at default unless you understand exactly what * its ramifications are @@ -52,14 +55,14 @@ class Color extends Supervisor * Leave this value at default unless you understand exactly what * its ramifications are */ - public function __construct($pARGB = self::COLOR_BLACK, $isSupervisor = false, $isConditional = false) + public function __construct($colorValue = self::COLOR_BLACK, $isSupervisor = false, $isConditional = false) { // Supervisor? parent::__construct($isSupervisor); // Initialise values if (!$isConditional) { - $this->argb = $pARGB; + $this->argb = $this->setARGB($colorValue); } } @@ -125,7 +128,7 @@ class Color extends Supervisor * * @return string */ - public function getARGB() + public function getARGB(): ?string { if ($this->isSupervisor) { return $this->getSharedComponent()->getARGB(); @@ -134,23 +137,32 @@ class Color extends Supervisor return $this->argb; } + private function validateARGB(string $colorValue): bool + { + return in_array(ucfirst($colorValue), self::NAMED_COLORS) || + preg_match(self::VALIDATE_ARGB, $colorValue); + } + /** * Set ARGB. * - * @param string $pValue see self::COLOR_* + * @param string $colorValue ARGB value, or a named color * * @return $this */ - public function setARGB($pValue) + public function setARGB(string $colorValue) { - if ($pValue == '') { - $pValue = self::COLOR_BLACK; + if ($colorValue == '') { + $colorValue = self::COLOR_BLACK; + } elseif (!$this->validateARGB($colorValue)) { + return $this; } + if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['argb' => $pValue]); + $styleArray = $this->getStyleArray(['argb' => $colorValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->argb = $pValue; + $this->argb = $colorValue; } return $this; @@ -161,7 +173,7 @@ class Color extends Supervisor * * @return string */ - public function getRGB() + public function getRGB(): ?string { if ($this->isSupervisor) { return $this->getSharedComponent()->getRGB(); @@ -170,23 +182,32 @@ class Color extends Supervisor return substr($this->argb, 2); } + private function validateRGB(string $colorValue): bool + { + return in_array(ucfirst($colorValue), self::NAMED_COLORS) || + preg_match(self::VALIDATE_RGB, $colorValue); + } + /** * Set RGB. * - * @param string $pValue RGB value + * @param string $colorValue RGB value, or a named color * * @return $this */ - public function setRGB($pValue) + public function setRGB(string $colorValue) { - if ($pValue == '') { - $pValue = '000000'; + if ($colorValue == '') { + $colorValue = '000000'; + } elseif (!$this->validateRGB($colorValue)) { + return $this; } + if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['argb' => 'FF' . $pValue]); + $styleArray = $this->getStyleArray(['argb' => 'FF' . $colorValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->argb = 'FF' . $pValue; + $this->argb = 'FF' . $colorValue; } return $this; diff --git a/src/PhpSpreadsheet/Style/Style.php b/src/PhpSpreadsheet/Style/Style.php index 533a7c38..012677f4 100644 --- a/src/PhpSpreadsheet/Style/Style.php +++ b/src/PhpSpreadsheet/Style/Style.php @@ -110,7 +110,7 @@ class Style extends Supervisor * * @return Style */ - public function getSharedComponent() + public function getSharedComponent(): Style { $activeSheet = $this->getActiveSheet(); $selectedCell = $this->getActiveCell(); // e.g. 'A1' From 7b750e3bf524a89d1254ce79cd669df06d77fea2 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 30 Oct 2020 11:15:37 +0100 Subject: [PATCH 02/41] Fix default colour validation for supervisor --- src/PhpSpreadsheet/Style/Color.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 78c860fb..913747b0 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -62,7 +62,7 @@ class Color extends Supervisor // Initialise values if (!$isConditional) { - $this->argb = $this->setARGB($colorValue); + $this->argb = $this->validateARGB($colorValue) ? $colorValue : self::COLOR_BLACK; } } From 6966c2fed3b99838784f2e3ba4b5dee32d0a2b13 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 30 Oct 2020 11:30:28 +0100 Subject: [PATCH 03/41] Allow for null value when setting colour values --- src/PhpSpreadsheet/Style/Color.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 913747b0..589a696e 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -150,9 +150,9 @@ class Color extends Supervisor * * @return $this */ - public function setARGB(string $colorValue) + public function setARGB(?string $colorValue) { - if ($colorValue == '') { + if ($colorValue === '' || $colorValue === null) { $colorValue = self::COLOR_BLACK; } elseif (!$this->validateARGB($colorValue)) { return $this; @@ -195,9 +195,9 @@ class Color extends Supervisor * * @return $this */ - public function setRGB(string $colorValue) + public function setRGB(?string $colorValue) { - if ($colorValue == '') { + if ($colorValue === '' || $colorValue === null) { $colorValue = '000000'; } elseif (!$this->validateRGB($colorValue)) { return $this; From 64802436106b3fa722d141bc5ec00d4bc827bc8e Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 30 Oct 2020 12:50:30 +0100 Subject: [PATCH 04/41] Remove redundant docblocks now that we've started typehinting --- src/PhpSpreadsheet/Comment.php | 80 +++++------------------------- src/PhpSpreadsheet/IOFactory.php | 53 +++++--------------- src/PhpSpreadsheet/Settings.php | 4 +- src/PhpSpreadsheet/Style/Style.php | 4 +- 4 files changed, 26 insertions(+), 115 deletions(-) diff --git a/src/PhpSpreadsheet/Comment.php b/src/PhpSpreadsheet/Comment.php index 12fb0e22..ca6e6c57 100644 --- a/src/PhpSpreadsheet/Comment.php +++ b/src/PhpSpreadsheet/Comment.php @@ -85,8 +85,6 @@ class Comment implements IComparable /** * Get Author. - * - * @return string */ public function getAuthor(): string { @@ -95,12 +93,8 @@ class Comment implements IComparable /** * Set Author. - * - * @param string $author - * - * @return $this */ - public function setAuthor(string $author) + public function setAuthor(string $author): self { $this->author = $author; @@ -109,8 +103,6 @@ class Comment implements IComparable /** * Get Rich text comment. - * - * @return RichText */ public function getText(): RichText { @@ -119,12 +111,8 @@ class Comment implements IComparable /** * Set Rich text comment. - * - * @param RichText $text - * - * @return $this */ - public function setText(RichText $text) + public function setText(RichText $text): self { $this->text = $text; @@ -133,8 +121,6 @@ class Comment implements IComparable /** * Get comment width (CSS style, i.e. XXpx or YYpt). - * - * @return string */ public function getWidth(): string { @@ -143,12 +129,8 @@ class Comment implements IComparable /** * Set comment width (CSS style, i.e. XXpx or YYpt). - * - * @param string $width including units (px or pt) - * - * @return $this */ - public function setWidth(string $width) + public function setWidth(string $width): self { $this->width = $width; @@ -157,8 +139,6 @@ class Comment implements IComparable /** * Get comment height (CSS style, i.e. XXpx or YYpt). - * - * @return string */ public function getHeight(): string { @@ -167,12 +147,8 @@ class Comment implements IComparable /** * Set comment height (CSS style, i.e. XXpx or YYpt). - * - * @param string $height including units (px or pt) - * - * @return $this */ - public function setHeight(string $height) + public function setHeight(string $height): self { $this->height = $height; @@ -181,8 +157,6 @@ class Comment implements IComparable /** * Get left margin (CSS style, i.e. XXpx or YYpt). - * - * @return string */ public function getMarginLeft(): string { @@ -191,12 +165,8 @@ class Comment implements IComparable /** * Set left margin (CSS style, i.e. XXpx or YYpt). - * - * @param string $margin including units (px or pt) - * - * @return $this */ - public function setMarginLeft(string $margin) + public function setMarginLeft(string $margin): self { $this->marginLeft = $margin; @@ -205,8 +175,6 @@ class Comment implements IComparable /** * Get top margin (CSS style, i.e. XXpx or YYpt). - * - * @return string */ public function getMarginTop(): string { @@ -215,12 +183,8 @@ class Comment implements IComparable /** * Set top margin (CSS style, i.e. XXpx or YYpt). - * - * @param string $margin including units (px or pt) - * - * @return $this */ - public function setMarginTop(string $margin) + public function setMarginTop(string $margin): self { $this->marginTop = $margin; @@ -229,8 +193,6 @@ class Comment implements IComparable /** * Is the comment visible by default? - * - * @return bool */ public function getVisible(): bool { @@ -239,12 +201,8 @@ class Comment implements IComparable /** * Set comment default visibility. - * - * @param bool $visibility - * - * @return $this */ - public function setVisible(bool $visibility) + public function setVisible(bool $visibility): self { $this->visible = $visibility; @@ -253,12 +211,8 @@ class Comment implements IComparable /** * Set fill color. - * - * @param Color $color - * - * @return $this */ - public function setFillColor(Color $color) + public function setFillColor(Color $color): self { $this->fillColor = $color; @@ -267,8 +221,6 @@ class Comment implements IComparable /** * Get fill color. - * - * @return Color */ public function getFillColor(): Color { @@ -277,12 +229,8 @@ class Comment implements IComparable /** * Set Alignment. - * - * @param string $alignment see Alignment::HORIZONTAL_* - * - * @return $this */ - public function setAlignment(string $alignment): string + public function setAlignment(string $alignment): self { $this->alignment = $alignment; @@ -294,17 +242,15 @@ class Comment implements IComparable * * @return string */ - public function getAlignment() + public function getAlignment(): string { return $this->alignment; } /** * Get hash code. - * - * @return string Hash code */ - public function getHashCode() + public function getHashCode(): string { return md5( $this->author . @@ -337,10 +283,8 @@ class Comment implements IComparable /** * Convert to string. - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->text->getPlainText(); } diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index f3ce6a30..4f20ac93 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet; use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Reader\IReader; use PhpOffice\PhpSpreadsheet\Writer\IWriter; /** @@ -37,12 +38,8 @@ abstract class IOFactory /** * Create Writer\IWriter. - * - * @param string $writerType Example: Xlsx - * - * @return Writer\IWriter */ - public static function createWriter(Spreadsheet $spreadsheet, string $writerType): Writer\IWriter + public static function createWriter(Spreadsheet $spreadsheet, string $writerType): IWriter { if (!isset(self::$writers[$writerType])) { throw new Writer\Exception("No writer found for type $writerType"); @@ -55,13 +52,9 @@ abstract class IOFactory } /** - * Create Reader\IReader. - * - * @param string $readerType Example: Xlsx - * - * @return Reader\IReader + * Create IReader. */ - public static function createReader(string $readerType): Reader\IReader + public static function createReader(string $readerType): IReader { if (!isset(self::$readers[$readerType])) { throw new Reader\Exception("No reader found for type $readerType"); @@ -74,11 +67,7 @@ abstract class IOFactory } /** - * Loads Spreadsheet from file using automatic Reader\IReader resolution. - * - * @param string $pFilename The name of the spreadsheet file - * - * @return Spreadsheet + * Loads Spreadsheet from file using automatic IReader resolution. */ public static function load(string $pFilename): Spreadsheet { @@ -88,11 +77,7 @@ abstract class IOFactory } /** - * Identify file type using automatic Reader\IReader resolution. - * - * @param string $pFilename The name of the spreadsheet file to identify - * - * @return string + * Identify file type using automatic IReader resolution. */ public static function identify(string $pFilename): string { @@ -105,13 +90,9 @@ abstract class IOFactory } /** - * Create Reader\IReader for file using automatic Reader\IReader resolution. - * - * @param string $filename The name of the spreadsheet file - * - * @return Reader\IReader + * Create Reader\IReader for file using automatic IReader resolution. */ - public static function createReaderForFile(string $filename): Reader\IReader + public static function createReaderForFile(string $filename): IReader { File::assertFile($filename); @@ -143,10 +124,6 @@ abstract class IOFactory /** * Guess a reader type from the file extension, if any. - * - * @param string $filename - * - * @return null|string */ private static function getReaderTypeFromExtension(string $filename): ?string { @@ -188,14 +165,11 @@ abstract class IOFactory /** * Register a writer with its type and class name. - * - * @param string $writerType - * @param string $writerClass */ public static function registerWriter(string $writerType, string $writerClass): void { - if (!is_a($writerClass, Writer\IWriter::class, true)) { - throw new Writer\Exception('Registered writers must implement ' . Writer\IWriter::class); + if (!is_a($writerClass, IWriter::class, true)) { + throw new Writer\Exception('Registered writers must implement ' . IWriter::class); } self::$writers[$writerType] = $writerClass; @@ -203,14 +177,11 @@ abstract class IOFactory /** * Register a reader with its type and class name. - * - * @param string $readerType - * @param string $readerClass */ public static function registerReader(string $readerType, string $readerClass): void { - if (!is_a($readerClass, Reader\IReader::class, true)) { - throw new Reader\Exception('Registered readers must implement ' . Reader\IReader::class); + if (!is_a($readerClass, IReader::class, true)) { + throw new Reader\Exception('Registered readers must implement ' . IReader::class); } self::$readers[$readerType] = $readerClass; diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index 1b760578..d6223528 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -158,9 +158,7 @@ class Settings } /** - * Gets the implementation of cache that should be used for cell collection. - * - * @return CacheInterface + * Gets the implementation of cache that is being used for cell collection. */ public static function getCache(): CacheInterface { diff --git a/src/PhpSpreadsheet/Style/Style.php b/src/PhpSpreadsheet/Style/Style.php index 012677f4..0a048e03 100644 --- a/src/PhpSpreadsheet/Style/Style.php +++ b/src/PhpSpreadsheet/Style/Style.php @@ -107,10 +107,8 @@ class Style extends Supervisor /** * Get the shared style component for the currently active cell in currently active sheet. * Only used for style supervisor. - * - * @return Style */ - public function getSharedComponent(): Style + public function getSharedComponent(): self { $activeSheet = $this->getActiveSheet(); $selectedCell = $this->getActiveCell(); // e.g. 'A1' From 212fc75e3187dd9e046125d64188ec52c7eb11ea Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 30 Oct 2020 13:02:15 +0100 Subject: [PATCH 05/41] Remove redundant docblocks now that we've started typehinting --- src/PhpSpreadsheet/Comment.php | 2 -- src/PhpSpreadsheet/IOFactory.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Comment.php b/src/PhpSpreadsheet/Comment.php index ca6e6c57..a4d38974 100644 --- a/src/PhpSpreadsheet/Comment.php +++ b/src/PhpSpreadsheet/Comment.php @@ -239,8 +239,6 @@ class Comment implements IComparable /** * Get Alignment. - * - * @return string */ public function getAlignment(): string { diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index 4f20ac93..60995c34 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -2,8 +2,8 @@ namespace PhpOffice\PhpSpreadsheet; -use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Reader\IReader; +use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Writer\IWriter; /** From 613a0b96aea8f478a155a366d29160ea1b741852 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 1 Nov 2020 12:09:51 +0100 Subject: [PATCH 06/41] Adjust colour validation calls --- src/PhpSpreadsheet/Style/Color.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 589a696e..6f7d14ea 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -27,8 +27,9 @@ class Color extends Supervisor const COLOR_YELLOW = 'FFFFFF00'; const COLOR_DARKYELLOW = 'FF808000'; - const VALIDATE_ARGB = '/^[A-F0-9]{8}$/i'; - const VALIDATE_RGB = '/^[A-F0-9]{6}$/i'; + const VALIDATE_ARGB_SIZE = 8; + const VALIDATE_RGB_SIZE = 6; + const VALIDATE_COLOR_VALUE = '/^[A-F0-9]{%d}$/i'; /** * Indexed colors array. @@ -62,7 +63,7 @@ class Color extends Supervisor // Initialise values if (!$isConditional) { - $this->argb = $this->validateARGB($colorValue) ? $colorValue : self::COLOR_BLACK; + $this->argb = $this->validateColour($colorValue) ? $colorValue : self::COLOR_BLACK; } } @@ -137,10 +138,10 @@ class Color extends Supervisor return $this->argb; } - private function validateARGB(string $colorValue): bool + private function validateColour(string $colorValue, int $size): bool { return in_array(ucfirst($colorValue), self::NAMED_COLORS) || - preg_match(self::VALIDATE_ARGB, $colorValue); + preg_match(sprintf(self::VALIDATE_COLOR_VALUE, $size), $colorValue); } /** @@ -154,7 +155,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = self::COLOR_BLACK; - } elseif (!$this->validateARGB($colorValue)) { + } elseif (!$this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE)) { return $this; } @@ -182,12 +183,6 @@ class Color extends Supervisor return substr($this->argb, 2); } - private function validateRGB(string $colorValue): bool - { - return in_array(ucfirst($colorValue), self::NAMED_COLORS) || - preg_match(self::VALIDATE_RGB, $colorValue); - } - /** * Set RGB. * @@ -199,7 +194,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = '000000'; - } elseif (!$this->validateRGB($colorValue)) { + } elseif (!$this->validateColour($colorValue, self::VALIDATE_RGB_SIZE)) { return $this; } From 414c5217b81f0bf7e26f57dfe9d0686f7b69ed40 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 1 Nov 2020 12:12:28 +0100 Subject: [PATCH 07/41] Adjust colour validation calls --- src/PhpSpreadsheet/Style/Color.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 6f7d14ea..faf55dea 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -63,7 +63,7 @@ class Color extends Supervisor // Initialise values if (!$isConditional) { - $this->argb = $this->validateColour($colorValue) ? $colorValue : self::COLOR_BLACK; + $this->argb = $this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE) ? $colorValue : self::COLOR_BLACK; } } From 4107783e274052916d793201445c346286f8b4ef Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 1 Nov 2020 14:23:11 +0100 Subject: [PATCH 08/41] Additional unit tests for Style Color --- src/PhpSpreadsheet/Style/Alignment.php | 86 +++++++++---------- src/PhpSpreadsheet/Style/Border.php | 20 ++--- src/PhpSpreadsheet/Style/Color.php | 64 +++++++------- tests/PhpSpreadsheetTests/Style/ColorTest.php | 75 +++++++++++++++- .../{ => Color}/ColorChangeBrightness.php | 0 tests/data/Style/{ => Color}/ColorGetBlue.php | 0 .../data/Style/{ => Color}/ColorGetGreen.php | 0 tests/data/Style/{ => Color}/ColorGetRed.php | 0 8 files changed, 154 insertions(+), 91 deletions(-) rename tests/data/Style/{ => Color}/ColorChangeBrightness.php (100%) rename tests/data/Style/{ => Color}/ColorGetBlue.php (100%) rename tests/data/Style/{ => Color}/ColorGetGreen.php (100%) rename tests/data/Style/{ => Color}/ColorGetRed.php (100%) diff --git a/src/PhpSpreadsheet/Style/Alignment.php b/src/PhpSpreadsheet/Style/Alignment.php index 4d97dd2c..1c01a82d 100644 --- a/src/PhpSpreadsheet/Style/Alignment.php +++ b/src/PhpSpreadsheet/Style/Alignment.php @@ -189,21 +189,21 @@ class Alignment extends Supervisor /** * Set Horizontal. * - * @param string $pValue see self::HORIZONTAL_* + * @param string $horizontalAlignment see self::HORIZONTAL_* * * @return $this */ - public function setHorizontal($pValue) + public function setHorizontal(string $horizontalAlignment) { - if ($pValue == '') { - $pValue = self::HORIZONTAL_GENERAL; + if ($horizontalAlignment == '') { + $horizontalAlignment = self::HORIZONTAL_GENERAL; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['horizontal' => $pValue]); + $styleArray = $this->getStyleArray(['horizontal' => $horizontalAlignment]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->horizontal = $pValue; + $this->horizontal = $horizontalAlignment; } return $this; @@ -226,21 +226,21 @@ class Alignment extends Supervisor /** * Set Vertical. * - * @param string $pValue see self::VERTICAL_* + * @param string $verticalAlignment see self::VERTICAL_* * * @return $this */ - public function setVertical($pValue) + public function setVertical($verticalAlignment) { - if ($pValue == '') { - $pValue = self::VERTICAL_BOTTOM; + if ($verticalAlignment == '') { + $verticalAlignment = self::VERTICAL_BOTTOM; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['vertical' => $pValue]); + $styleArray = $this->getStyleArray(['vertical' => $verticalAlignment]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->vertical = $pValue; + $this->vertical = $verticalAlignment; } return $this; @@ -263,24 +263,24 @@ class Alignment extends Supervisor /** * Set TextRotation. * - * @param int $pValue + * @param int $rotation * * @return $this */ - public function setTextRotation($pValue) + public function setTextRotation($rotation) { // Excel2007 value 255 => PhpSpreadsheet value -165 - if ($pValue == 255) { - $pValue = -165; + if ($rotation == 255) { + $rotation = -165; } // Set rotation - if (($pValue >= -90 && $pValue <= 90) || $pValue == -165) { + if (($rotation >= -90 && $rotation <= 90) || $rotation == -165) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['textRotation' => $pValue]); + $styleArray = $this->getStyleArray(['textRotation' => $rotation]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->textRotation = $pValue; + $this->textRotation = $rotation; } } else { throw new PhpSpreadsheetException('Text rotation should be a value between -90 and 90.'); @@ -306,20 +306,20 @@ class Alignment extends Supervisor /** * Set Wrap Text. * - * @param bool $pValue + * @param bool $wrapped * * @return $this */ - public function setWrapText($pValue) + public function setWrapText($wrapped) { - if ($pValue == '') { - $pValue = false; + if ($wrapped == '') { + $wrapped = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['wrapText' => $pValue]); + $styleArray = $this->getStyleArray(['wrapText' => $wrapped]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->wrapText = $pValue; + $this->wrapText = $wrapped; } return $this; @@ -342,20 +342,20 @@ class Alignment extends Supervisor /** * Set Shrink to fit. * - * @param bool $pValue + * @param bool $shrink * * @return $this */ - public function setShrinkToFit($pValue) + public function setShrinkToFit($shrink) { - if ($pValue == '') { - $pValue = false; + if ($shrink == '') { + $shrink = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['shrinkToFit' => $pValue]); + $styleArray = $this->getStyleArray(['shrinkToFit' => $shrink]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->shrinkToFit = $pValue; + $this->shrinkToFit = $shrink; } return $this; @@ -378,26 +378,26 @@ class Alignment extends Supervisor /** * Set indent. * - * @param int $pValue + * @param int $indent * * @return $this */ - public function setIndent($pValue) + public function setIndent($indent) { - if ($pValue > 0) { + if ($indent > 0) { if ( $this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT ) { - $pValue = 0; // indent not supported + $indent = 0; // indent not supported } } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['indent' => $pValue]); + $styleArray = $this->getStyleArray(['indent' => $indent]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->indent = $pValue; + $this->indent = $indent; } return $this; @@ -420,20 +420,20 @@ class Alignment extends Supervisor /** * Set read order. * - * @param int $pValue + * @param int $readOrder * * @return $this */ - public function setReadOrder($pValue) + public function setReadOrder($readOrder) { - if ($pValue < 0 || $pValue > 2) { - $pValue = 0; + if ($readOrder < 0 || $readOrder > 2) { + $readOrder = 0; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['readOrder' => $pValue]); + $styleArray = $this->getStyleArray(['readOrder' => $readOrder]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->readOrder = $pValue; + $this->readOrder = $readOrder; } return $this; diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index 78ad8b26..184f808f 100644 --- a/src/PhpSpreadsheet/Style/Border.php +++ b/src/PhpSpreadsheet/Style/Border.php @@ -158,24 +158,24 @@ class Border extends Supervisor /** * Set Border style. * - * @param bool|string $pValue + * @param bool|string $style * When passing a boolean, FALSE equates Border::BORDER_NONE * and TRUE to Border::BORDER_MEDIUM * * @return $this */ - public function setBorderStyle($pValue) + public function setBorderStyle($style) { - if (empty($pValue)) { - $pValue = self::BORDER_NONE; - } elseif (is_bool($pValue) && $pValue) { - $pValue = self::BORDER_MEDIUM; + if (empty($style)) { + $style = self::BORDER_NONE; + } elseif (is_bool($style) && $style) { + $style = self::BORDER_MEDIUM; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['borderStyle' => $pValue]); + $styleArray = $this->getStyleArray(['borderStyle' => $style]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->borderStyle = $pValue; + $this->borderStyle = $style; } return $this; @@ -196,10 +196,10 @@ class Border extends Supervisor * * @return $this */ - public function setColor(Color $pValue) + public function setColor(Color $color) { // make sure parameter is a real color and not a supervisor - $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color; if ($this->isSupervisor) { $styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]); diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index faf55dea..956efb9e 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -104,26 +104,32 @@ class Color extends Supervisor * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']); * * - * @param array $pStyles Array containing style information + * @param array $styles Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styles) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styles)); } else { - if (isset($pStyles['rgb'])) { - $this->setRGB($pStyles['rgb']); + if (isset($styles['rgb'])) { + $this->setRGB($styles['rgb']); } - if (isset($pStyles['argb'])) { - $this->setARGB($pStyles['argb']); + if (isset($styles['argb'])) { + $this->setARGB($styles['argb']); } } return $this; } + private function validateColour(string $colorValue, int $size): bool + { + return in_array(ucfirst($colorValue), self::NAMED_COLORS) || + preg_match(sprintf(self::VALIDATE_COLOR_VALUE, $size), $colorValue); + } + /** * Get ARGB. * @@ -138,12 +144,6 @@ class Color extends Supervisor return $this->argb; } - private function validateColour(string $colorValue, int $size): bool - { - return in_array(ucfirst($colorValue), self::NAMED_COLORS) || - preg_match(sprintf(self::VALIDATE_COLOR_VALUE, $size), $colorValue); - } - /** * Set ARGB. * @@ -151,7 +151,7 @@ class Color extends Supervisor * * @return $this */ - public function setARGB(?string $colorValue) + public function setARGB(?string $colorValue = self::COLOR_BLACK) { if ($colorValue === '' || $colorValue === null) { $colorValue = self::COLOR_BLACK; @@ -190,7 +190,7 @@ class Color extends Supervisor * * @return $this */ - public function setRGB(?string $colorValue) + public function setRGB(?string $colorValue = self::COLOR_BLACK) { if ($colorValue === '' || $colorValue === null) { $colorValue = '000000'; @@ -270,18 +270,18 @@ class Color extends Supervisor /** * Adjust the brightness of a color. * - * @param string $hex The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE) + * @param string $hexColourValue The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE) * @param float $adjustPercentage The percentage by which to adjust the colour as a float from -1 to 1 * * @return string The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE) */ - public static function changeBrightness($hex, $adjustPercentage) + public static function changeBrightness($hexColourValue, $adjustPercentage) { - $rgba = (strlen($hex) === 8); + $rgba = (strlen($hexColourValue) === 8); - $red = self::getRed($hex, false); - $green = self::getGreen($hex, false); - $blue = self::getBlue($hex, false); + $red = self::getRed($hexColourValue, false); + $green = self::getGreen($hexColourValue, false); + $blue = self::getBlue($hexColourValue, false); if ($adjustPercentage > 0) { $red += (255 - $red) * $adjustPercentage; $green += (255 - $green) * $adjustPercentage; @@ -320,16 +320,16 @@ class Color extends Supervisor /** * Get indexed color. * - * @param int $pIndex Index entry point into the colour array + * @param int $colorIndex Index entry point into the colour array * @param bool $background Flag to indicate whether default background or foreground colour - * should be returned if the indexed colour doesn't exist + * should be returned if the indexed colour doesn't exist * - * @return self + * @return string */ - public static function indexedColor($pIndex, $background = false) + public static function indexedColor($colorIndex, $background = false) { // Clean parameter - $pIndex = (int) $pIndex; + $colorIndex = (int) $colorIndex; // Indexed colors if (self::$indexedColors === null) { @@ -393,15 +393,11 @@ class Color extends Supervisor ]; } - if (isset(self::$indexedColors[$pIndex])) { - return new self(self::$indexedColors[$pIndex]); + if (isset(self::$indexedColors[$colorIndex])) { + return new self(self::$indexedColors[$colorIndex]); } - if ($background) { - return new self(self::COLOR_WHITE); - } - - return new self(self::COLOR_BLACK); + return ($background) ? new self(self::COLOR_WHITE): new self(self::COLOR_BLACK); } /** @@ -409,7 +405,7 @@ class Color extends Supervisor * * @return string Hash code */ - public function getHashCode() + public function getHashCode(): string { if ($this->isSupervisor) { return $this->getSharedComponent()->getHashCode(); diff --git a/tests/PhpSpreadsheetTests/Style/ColorTest.php b/tests/PhpSpreadsheetTests/Style/ColorTest.php index 9b524e93..0f1092bd 100644 --- a/tests/PhpSpreadsheetTests/Style/ColorTest.php +++ b/tests/PhpSpreadsheetTests/Style/ColorTest.php @@ -7,6 +7,73 @@ use PHPUnit\Framework\TestCase; class ColorTest extends TestCase { + public function testNewColor() + { + $color = new Color('FF123456'); + self::assertEquals('FF123456', $color->getARGB()); + self::assertEquals('123456', $color->getRGB()); + } + + public function testARGBSetter() + { + $color = new Color(); + $color->setARGB('80123456'); + self::assertEquals('80123456', $color->getARGB()); + self::assertEquals('123456', $color->getRGB()); + } + + public function testARGBSetterEmpty() + { + $color = new Color(); + $color->setARGB(); + self::assertEquals(Color::COLOR_BLACK, $color->getARGB()); + } + + public function testARGBSetterInvalid() + { + $color = new Color('80123456'); + $color->setARGB('INVALID COLOR'); + self::assertEquals('80123456', $color->getARGB()); + } + + public function testRGBSetter() + { + $color = new Color(); + $color->setRGB('123456'); + self::assertEquals('123456', $color->getRGB()); + self::assertEquals('FF123456', $color->getARGB()); + } + + public function testRGBSetterEmpty() + { + $color = new Color(); + $color->setRGB(); + self::assertEquals(Color::COLOR_BLACK, $color->getARGB()); + } + + public function testRGBSetterInvalid() + { + $color = new Color('80123456'); + $color->setRGB('INVALID COLOR'); + self::assertEquals('123456', $color->getRGB()); + } + + public function testARGBFromArray() + { + $color = new Color(); + $color->applyFromArray(['argb' => '80123456']); + self::assertEquals('80123456', $color->getARGB()); + self::assertEquals('123456', $color->getRGB()); + } + + public function testRGBFromArray() + { + $color = new Color(); + $color->applyFromArray(['rgb' => '123456']); + self::assertEquals('123456', $color->getRGB()); + self::assertEquals('FF123456', $color->getARGB()); + } + /** * @dataProvider providerColorGetRed * @@ -20,7 +87,7 @@ class ColorTest extends TestCase public function providerColorGetRed() { - return require 'tests/data/Style/ColorGetRed.php'; + return require 'tests/data/Style/Color/ColorGetRed.php'; } /** @@ -36,7 +103,7 @@ class ColorTest extends TestCase public function providerColorGetGreen() { - return require 'tests/data/Style/ColorGetGreen.php'; + return require 'tests/data/Style/Color/ColorGetGreen.php'; } /** @@ -52,7 +119,7 @@ class ColorTest extends TestCase public function providerColorGetBlue() { - return require 'tests/data/Style/ColorGetBlue.php'; + return require 'tests/data/Style/Color/ColorGetBlue.php'; } /** @@ -68,6 +135,6 @@ class ColorTest extends TestCase public function providerColorChangeBrightness() { - return require 'tests/data/Style/ColorChangeBrightness.php'; + return require 'tests/data/Style/Color/ColorChangeBrightness.php'; } } diff --git a/tests/data/Style/ColorChangeBrightness.php b/tests/data/Style/Color/ColorChangeBrightness.php similarity index 100% rename from tests/data/Style/ColorChangeBrightness.php rename to tests/data/Style/Color/ColorChangeBrightness.php diff --git a/tests/data/Style/ColorGetBlue.php b/tests/data/Style/Color/ColorGetBlue.php similarity index 100% rename from tests/data/Style/ColorGetBlue.php rename to tests/data/Style/Color/ColorGetBlue.php diff --git a/tests/data/Style/ColorGetGreen.php b/tests/data/Style/Color/ColorGetGreen.php similarity index 100% rename from tests/data/Style/ColorGetGreen.php rename to tests/data/Style/Color/ColorGetGreen.php diff --git a/tests/data/Style/ColorGetRed.php b/tests/data/Style/Color/ColorGetRed.php similarity index 100% rename from tests/data/Style/ColorGetRed.php rename to tests/data/Style/Color/ColorGetRed.php From dc5a5670a0c976a07f0c9ba9f20ae7ee7d561708 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 1 Nov 2020 14:32:38 +0100 Subject: [PATCH 09/41] Style fixes --- src/PhpSpreadsheet/Style/Color.php | 2 +- tests/PhpSpreadsheetTests/Style/ColorTest.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 956efb9e..d308c5c7 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -397,7 +397,7 @@ class Color extends Supervisor return new self(self::$indexedColors[$colorIndex]); } - return ($background) ? new self(self::COLOR_WHITE): new self(self::COLOR_BLACK); + return ($background) ? new self(self::COLOR_WHITE) : new self(self::COLOR_BLACK); } /** diff --git a/tests/PhpSpreadsheetTests/Style/ColorTest.php b/tests/PhpSpreadsheetTests/Style/ColorTest.php index 0f1092bd..8ae6518a 100644 --- a/tests/PhpSpreadsheetTests/Style/ColorTest.php +++ b/tests/PhpSpreadsheetTests/Style/ColorTest.php @@ -7,14 +7,14 @@ use PHPUnit\Framework\TestCase; class ColorTest extends TestCase { - public function testNewColor() + public function testNewColor(): void { $color = new Color('FF123456'); self::assertEquals('FF123456', $color->getARGB()); self::assertEquals('123456', $color->getRGB()); } - public function testARGBSetter() + public function testARGBSetter(): void { $color = new Color(); $color->setARGB('80123456'); @@ -22,21 +22,21 @@ class ColorTest extends TestCase self::assertEquals('123456', $color->getRGB()); } - public function testARGBSetterEmpty() + public function testARGBSetterEmpty(): void { $color = new Color(); $color->setARGB(); self::assertEquals(Color::COLOR_BLACK, $color->getARGB()); } - public function testARGBSetterInvalid() + public function testARGBSetterInvalid(): void { $color = new Color('80123456'); $color->setARGB('INVALID COLOR'); self::assertEquals('80123456', $color->getARGB()); } - public function testRGBSetter() + public function testRGBSetter(): void { $color = new Color(); $color->setRGB('123456'); @@ -44,21 +44,21 @@ class ColorTest extends TestCase self::assertEquals('FF123456', $color->getARGB()); } - public function testRGBSetterEmpty() + public function testRGBSetterEmpty(): void { $color = new Color(); $color->setRGB(); self::assertEquals(Color::COLOR_BLACK, $color->getARGB()); } - public function testRGBSetterInvalid() + public function testRGBSetterInvalid(): void { $color = new Color('80123456'); $color->setRGB('INVALID COLOR'); self::assertEquals('123456', $color->getRGB()); } - public function testARGBFromArray() + public function testARGBFromArray(): void { $color = new Color(); $color->applyFromArray(['argb' => '80123456']); @@ -66,7 +66,7 @@ class ColorTest extends TestCase self::assertEquals('123456', $color->getRGB()); } - public function testRGBFromArray() + public function testRGBFromArray(): void { $color = new Color(); $color->applyFromArray(['rgb' => '123456']); From b75551f0eb667b2562a0b2b4d423526c81122184 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 1 Nov 2020 21:11:20 +0100 Subject: [PATCH 10/41] Adjustment for border style --- src/PhpSpreadsheet/Style/Border.php | 5 +++-- src/PhpSpreadsheet/Style/Color.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index b7b179f2..a09078a4 100644 --- a/src/PhpSpreadsheet/Style/Border.php +++ b/src/PhpSpreadsheet/Style/Border.php @@ -162,9 +162,10 @@ class Border extends Supervisor { if (empty($style)) { $style = self::BORDER_NONE; - } elseif (is_bool($style) && $style) { - $style = self::BORDER_MEDIUM; + } elseif (is_bool($style)) { + $style = $style ? self::BORDER_MEDIUM : self::BORDER_NONE; } + if ($this->isSupervisor) { $styleArray = $this->getStyleArray(['borderStyle' => $style]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index b8182a25..1cb141a8 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -309,9 +309,9 @@ class Color extends Supervisor * @param bool $background Flag to indicate whether default background or foreground colour * should be returned if the indexed colour doesn't exist * - * @return string + * @return Color */ - public static function indexedColor($colorIndex, $background = false) + public static function indexedColor($colorIndex, $background = false): self { // Clean parameter $colorIndex = (int) $colorIndex; From 5e4288958c13731f64fe305e36e755d4eae756cd Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 14:55:28 +0100 Subject: [PATCH 11/41] Additional unit tests for comments --- src/PhpSpreadsheet/Style/Color.php | 10 +-- tests/PhpSpreadsheetTests/CommentTest.php | 76 +++++++++++++++++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 tests/PhpSpreadsheetTests/CommentTest.php diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 1cb141a8..534bcc9f 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -63,7 +63,7 @@ class Color extends Supervisor // Initialise values if (!$isConditional) { - $this->argb = $this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE) ? $colorValue : self::COLOR_BLACK; + $this->argb = $this->validateColor($colorValue, self::VALIDATE_ARGB_SIZE) ? $colorValue : self::COLOR_BLACK; } } @@ -124,9 +124,9 @@ class Color extends Supervisor return $this; } - private function validateColour(string $colorValue, int $size): bool + private function validateColor(string $colorValue, int $size): bool { - return in_array(ucfirst($colorValue), self::NAMED_COLORS) || + return in_array(ucfirst(strtolower($colorValue)), self::NAMED_COLORS) || preg_match(sprintf(self::VALIDATE_COLOR_VALUE, $size), $colorValue); } @@ -155,7 +155,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = self::COLOR_BLACK; - } elseif (!$this->validateColour($colorValue, self::VALIDATE_ARGB_SIZE)) { + } elseif (!$this->validateColor($colorValue, self::VALIDATE_ARGB_SIZE)) { return $this; } @@ -194,7 +194,7 @@ class Color extends Supervisor { if ($colorValue === '' || $colorValue === null) { $colorValue = '000000'; - } elseif (!$this->validateColour($colorValue, self::VALIDATE_RGB_SIZE)) { + } elseif (!$this->validateColor($colorValue, self::VALIDATE_RGB_SIZE)) { return $this; } diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php new file mode 100644 index 00000000..3fd22854 --- /dev/null +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -0,0 +1,76 @@ +getAuthor()); + self::assertEquals('96pt', $comment->getWidth()); + self::assertEquals('59.25pt', $comment->getMarginLeft()); + self::assertEquals('1.5pt', $comment->getMarginTop()); + self::assertEquals('55.5pt', $comment->getHeight()); + self::assertInstanceOf(Color::class, $comment->getFillColor()); + self::assertEquals('FFFFFFE1', $comment->getFillColor()->getARGB()); + self::assertInstanceOf(RichText::class, $comment->getText()); + self::assertEquals(Alignment::HORIZONTAL_GENERAL, $comment->getAlignment()); + self::assertFalse($comment->getVisible()); + } + + public function testSetAuthor() + { + $comment = new Comment(); + $comment->setAuthor('Mark Baker'); + self::assertEquals('Mark Baker', $comment->getAuthor()); + } + + public function testSetMarginLeft() + { + $comment = new Comment(); + $comment->setMarginLeft('20pt'); + self::assertEquals('20pt', $comment->getMarginLeft()); + } + + public function testSetMarginTop() + { + $comment = new Comment(); + $comment->setMarginTop('2.5pt'); + self::assertEquals('2.5pt', $comment->getMarginTop()); + } + + public function testSetWidth() + { + $comment = new Comment(); + $comment->setWidth('120pt'); + self::assertEquals('120pt', $comment->getWidth()); + } + + public function testSetHeight() + { + $comment = new Comment(); + $comment->setHeight('60pt'); + self::assertEquals('60pt', $comment->getHeight()); + } + + public function testSetFillColor() + { + $comment = new Comment(); + $comment->setFillColor(new Color('RED')); + self::assertEquals('RED', $comment->getFillColor()->getARGB()); + } + + public function testSetAlignment() + { + $comment = new Comment(); + $comment->setAlignment(Alignment::HORIZONTAL_CENTER); + self::assertEquals(Alignment::HORIZONTAL_CENTER, $comment->getAlignment()); + } +} From 3a960d62a6488588f41fa04c53e2a600d89e70a8 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 15:16:40 +0100 Subject: [PATCH 12/41] Remember return typehints for unit tests --- tests/PhpSpreadsheetTests/CommentTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php index 3fd22854..f7c1290b 100644 --- a/tests/PhpSpreadsheetTests/CommentTest.php +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase; class CommentTest extends TestCase { - public function testCreateComment() + public function testCreateComment(): void { $comment = new Comment(); self::assertEquals('Author', $comment->getAuthor()); @@ -25,49 +25,49 @@ class CommentTest extends TestCase self::assertFalse($comment->getVisible()); } - public function testSetAuthor() + public function testSetAuthor(): void { $comment = new Comment(); $comment->setAuthor('Mark Baker'); self::assertEquals('Mark Baker', $comment->getAuthor()); } - public function testSetMarginLeft() + public function testSetMarginLeft(): void { $comment = new Comment(); $comment->setMarginLeft('20pt'); self::assertEquals('20pt', $comment->getMarginLeft()); } - public function testSetMarginTop() + public function testSetMarginTop(): void { $comment = new Comment(); $comment->setMarginTop('2.5pt'); self::assertEquals('2.5pt', $comment->getMarginTop()); } - public function testSetWidth() + public function testSetWidth(): void { $comment = new Comment(); $comment->setWidth('120pt'); self::assertEquals('120pt', $comment->getWidth()); } - public function testSetHeight() + public function testSetHeight(): void { $comment = new Comment(); $comment->setHeight('60pt'); self::assertEquals('60pt', $comment->getHeight()); } - public function testSetFillColor() + public function testSetFillColor(): void { $comment = new Comment(); $comment->setFillColor(new Color('RED')); self::assertEquals('RED', $comment->getFillColor()->getARGB()); } - public function testSetAlignment() + public function testSetAlignment(): void { $comment = new Comment(); $comment->setAlignment(Alignment::HORIZONTAL_CENTER); From 93fe84da715b3913bf3de591417b7277d1178f86 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 20:14:44 +0100 Subject: [PATCH 13/41] Additional unit tests --- tests/PhpSpreadsheetTests/CommentTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php index f7c1290b..c41267e6 100644 --- a/tests/PhpSpreadsheetTests/CommentTest.php +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\Comment; use PhpOffice\PhpSpreadsheet\RichText\RichText; +use PhpOffice\PhpSpreadsheet\RichText\TextElement; use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Color; use PHPUnit\Framework\TestCase; @@ -73,4 +74,13 @@ class CommentTest extends TestCase $comment->setAlignment(Alignment::HORIZONTAL_CENTER); self::assertEquals(Alignment::HORIZONTAL_CENTER, $comment->getAlignment()); } + + public function testSetText(): void + { + $comment = new Comment(); + $test = new RichText(); + $test->addText(new TextElement('This is a test comment')); + $comment->setText($test); + self::assertEquals('This is a test comment', (string) $comment); + } } From 0502fd3e7fe9af87ccbcc2ce71f718bbfd1ddb94 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 21:24:27 +0100 Subject: [PATCH 14/41] Size validator for comment dimensions and margins --- src/PhpSpreadsheet/Comment.php | 21 ++++++++++--- src/PhpSpreadsheet/Helper/Size.php | 38 +++++++++++++++++++++++ tests/PhpSpreadsheetTests/CommentTest.php | 4 +-- 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/PhpSpreadsheet/Helper/Size.php diff --git a/src/PhpSpreadsheet/Comment.php b/src/PhpSpreadsheet/Comment.php index a4d38974..e2fcd83e 100644 --- a/src/PhpSpreadsheet/Comment.php +++ b/src/PhpSpreadsheet/Comment.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet; +use PhpOffice\PhpSpreadsheet\Helper\Size; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Color; @@ -132,7 +133,10 @@ class Comment implements IComparable */ public function setWidth(string $width): self { - $this->width = $width; + $result = new Size($width); + if ($result->valid()) { + $this->width = $result->size() . $result->unit(); + } return $this; } @@ -150,7 +154,10 @@ class Comment implements IComparable */ public function setHeight(string $height): self { - $this->height = $height; + $result = new Size($height); + if ($result->valid()) { + $this->height = $result->size() . $result->unit(); + } return $this; } @@ -168,7 +175,10 @@ class Comment implements IComparable */ public function setMarginLeft(string $margin): self { - $this->marginLeft = $margin; + $result = new Size($margin); + if ($result->valid()) { + $this->marginLeft = $result->size() . $result->unit(); + } return $this; } @@ -186,7 +196,10 @@ class Comment implements IComparable */ public function setMarginTop(string $margin): self { - $this->marginTop = $margin; + $result = new Size($margin); + if ($result->valid()) { + $this->marginTop = $result->size() . $result->unit(); + } return $this; } diff --git a/src/PhpSpreadsheet/Helper/Size.php b/src/PhpSpreadsheet/Helper/Size.php new file mode 100644 index 00000000..e1a4d869 --- /dev/null +++ b/src/PhpSpreadsheet/Helper/Size.php @@ -0,0 +1,38 @@ +\d*\.?\d+)(?Ppt|px|em)?$/i'; + + protected $valid; + + protected $size = ''; + + protected $unit = ''; + + public function __construct(string $size) + { + $this->valid = preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches); + if ($this->valid) { + $this->size = $matches['size']; + $this->unit = $matches['unit'] ?? 'pt'; + } + } + + public function valid(): bool + { + return $this->valid; + } + + public function size() + { + return $this->size; + } + + public function unit() + { + return $this->unit; + } +} diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php index c41267e6..f21efdf0 100644 --- a/tests/PhpSpreadsheetTests/CommentTest.php +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -57,8 +57,8 @@ class CommentTest extends TestCase public function testSetHeight(): void { $comment = new Comment(); - $comment->setHeight('60pt'); - self::assertEquals('60pt', $comment->getHeight()); + $comment->setHeight('60px'); + self::assertEquals('60px', $comment->getHeight()); } public function testSetFillColor(): void From a16badbcc4e91f1b988138cd6c22578600d29927 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 22:18:33 +0100 Subject: [PATCH 15/41] Size validator for comment dimensions and margins --- src/PhpSpreadsheet/Helper/Size.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Helper/Size.php b/src/PhpSpreadsheet/Helper/Size.php index e1a4d869..27d5e62c 100644 --- a/src/PhpSpreadsheet/Helper/Size.php +++ b/src/PhpSpreadsheet/Helper/Size.php @@ -14,7 +14,7 @@ class Size public function __construct(string $size) { - $this->valid = preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches); + $this->valid = preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches); if ($this->valid) { $this->size = $matches['size']; $this->unit = $matches['unit'] ?? 'pt'; @@ -26,12 +26,12 @@ class Size return $this->valid; } - public function size() + public function size(): string { return $this->size; } - public function unit() + public function unit(): string { return $this->unit; } From 06f7d3c8bdab0095bf869f98c0fe27d91c8d0261 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 2 Nov 2020 23:48:57 +0100 Subject: [PATCH 16/41] Size validator for comment dimensions and margins --- CHANGELOG.md | 2 +- src/PhpSpreadsheet/Comment.php | 32 +++++++++++++++--------------- src/PhpSpreadsheet/Helper/Size.php | 5 +++++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3f149df..b704582d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Added -- Nothing. +- Provided a Size Helper class to validate size values (pt, px, em) ### Changed diff --git a/src/PhpSpreadsheet/Comment.php b/src/PhpSpreadsheet/Comment.php index e2fcd83e..7aaf9759 100644 --- a/src/PhpSpreadsheet/Comment.php +++ b/src/PhpSpreadsheet/Comment.php @@ -129,13 +129,13 @@ class Comment implements IComparable } /** - * Set comment width (CSS style, i.e. XXpx or YYpt). + * Set comment width (CSS style, i.e. XXpx or YYpt). Default unit is pt. */ public function setWidth(string $width): self { - $result = new Size($width); - if ($result->valid()) { - $this->width = $result->size() . $result->unit(); + $width = new Size($width); + if ($width->valid()) { + $this->width = (string) $width; } return $this; @@ -150,13 +150,13 @@ class Comment implements IComparable } /** - * Set comment height (CSS style, i.e. XXpx or YYpt). + * Set comment height (CSS style, i.e. XXpx or YYpt). Default unit is pt. */ public function setHeight(string $height): self { - $result = new Size($height); - if ($result->valid()) { - $this->height = $result->size() . $result->unit(); + $height = new Size($height); + if ($height->valid()) { + $this->height = (string) $height; } return $this; @@ -171,13 +171,13 @@ class Comment implements IComparable } /** - * Set left margin (CSS style, i.e. XXpx or YYpt). + * Set left margin (CSS style, i.e. XXpx or YYpt). Default unit is pt. */ public function setMarginLeft(string $margin): self { - $result = new Size($margin); - if ($result->valid()) { - $this->marginLeft = $result->size() . $result->unit(); + $margin = new Size($margin); + if ($margin->valid()) { + $this->marginLeft = (string) $margin; } return $this; @@ -192,13 +192,13 @@ class Comment implements IComparable } /** - * Set top margin (CSS style, i.e. XXpx or YYpt). + * Set top margin (CSS style, i.e. XXpx or YYpt). Default unit is pt. */ public function setMarginTop(string $margin): self { - $result = new Size($margin); - if ($result->valid()) { - $this->marginTop = $result->size() . $result->unit(); + $margin = new Size($margin); + if ($margin->valid()) { + $this->marginTop = (string) $margin; } return $this; diff --git a/src/PhpSpreadsheet/Helper/Size.php b/src/PhpSpreadsheet/Helper/Size.php index 27d5e62c..12bccaad 100644 --- a/src/PhpSpreadsheet/Helper/Size.php +++ b/src/PhpSpreadsheet/Helper/Size.php @@ -35,4 +35,9 @@ class Size { return $this->unit; } + + public function __toString() + { + return $this->size . $this->unit; + } } From 7e4248d67fd19a90a9913af4424b0154c8afafd2 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 11:06:12 +0100 Subject: [PATCH 17/41] Sane argument names in the IO Factory --- src/PhpSpreadsheet/DefinedName.php | 20 ++++++------ src/PhpSpreadsheet/HashTable.php | 52 +++++++++++++++--------------- src/PhpSpreadsheet/IOFactory.php | 10 +++--- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/PhpSpreadsheet/DefinedName.php b/src/PhpSpreadsheet/DefinedName.php index dbadd4ce..74ee0551 100644 --- a/src/PhpSpreadsheet/DefinedName.php +++ b/src/PhpSpreadsheet/DefinedName.php @@ -167,9 +167,9 @@ abstract class DefinedName /** * Set worksheet. */ - public function setWorksheet(?Worksheet $value): self + public function setWorksheet(?Worksheet $worksheet): self { - $this->worksheet = $value; + $this->worksheet = $worksheet; return $this; } @@ -203,10 +203,10 @@ abstract class DefinedName /** * Set localOnly. */ - public function setLocalOnly(bool $value): self + public function setLocalOnly(bool $localScope): self { - $this->localOnly = $value; - $this->scope = $value ? $this->worksheet : null; + $this->localOnly = $localScope; + $this->scope = $localScope ? $this->worksheet : null; return $this; } @@ -222,10 +222,10 @@ abstract class DefinedName /** * Set scope. */ - public function setScope(?Worksheet $value): self + public function setScope(?Worksheet $worksheet): self { - $this->scope = $value; - $this->localOnly = $value !== null; + $this->scope = $worksheet; + $this->localOnly = $worksheet !== null; return $this; } @@ -241,9 +241,9 @@ abstract class DefinedName /** * Resolve a named range to a regular cell range or formula. */ - public static function resolveName(string $pDefinedName, Worksheet $pSheet): ?self + public static function resolveName(string $definedName, Worksheet $worksheet): ?self { - return $pSheet->getParent()->getDefinedName($pDefinedName, $pSheet); + return $worksheet->getParent()->getDefinedName($definedName, $worksheet); } /** diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index 90ea806b..e615b060 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -21,29 +21,29 @@ class HashTable /** * Create a new \PhpOffice\PhpSpreadsheet\HashTable. * - * @param IComparable[] $pSource Optional source array to create HashTable from + * @param IComparable[] $source Optional source array to create HashTable from */ - public function __construct($pSource = null) + public function __construct($source = null) { - if ($pSource !== null) { + if ($source !== null) { // Create HashTable - $this->addFromSource($pSource); + $this->addFromSource($source); } } /** * Add HashTable items from source. * - * @param IComparable[] $pSource Source array to create HashTable from + * @param IComparable[] $source Source array to create HashTable from */ - public function addFromSource(?array $pSource = null): void + public function addFromSource(?array $source = null): void { // Check if an array was passed - if ($pSource == null) { + if ($source == null) { return; } - foreach ($pSource as $item) { + foreach ($source as $item) { $this->add($item); } } @@ -51,13 +51,13 @@ class HashTable /** * Add HashTable item. * - * @param IComparable $pSource Item to add + * @param IComparable $source Item to add */ - public function add(IComparable $pSource): void + public function add(IComparable $source): void { - $hash = $pSource->getHashCode(); + $hash = $source->getHashCode(); if (!isset($this->items[$hash])) { - $this->items[$hash] = $pSource; + $this->items[$hash] = $source; $this->keyMap[count($this->items) - 1] = $hash; } } @@ -65,11 +65,11 @@ class HashTable /** * Remove HashTable item. * - * @param IComparable $pSource Item to remove + * @param IComparable $source Item to remove */ - public function remove(IComparable $pSource): void + public function remove(IComparable $source): void { - $hash = $pSource->getHashCode(); + $hash = $source->getHashCode(); if (isset($this->items[$hash])) { unset($this->items[$hash]); @@ -109,26 +109,26 @@ class HashTable /** * Get index for hash code. * - * @param string $pHashCode + * @param string $hashCode * * @return int Index */ - public function getIndexForHashCode($pHashCode) + public function getIndexForHashCode($hashCode) { - return array_search($pHashCode, $this->keyMap); + return array_search($hashCode, $this->keyMap); } /** * Get by index. * - * @param int $pIndex + * @param int $index * * @return IComparable */ - public function getByIndex($pIndex) + public function getByIndex($index) { - if (isset($this->keyMap[$pIndex])) { - return $this->getByHashCode($this->keyMap[$pIndex]); + if (isset($this->keyMap[$index])) { + return $this->getByHashCode($this->keyMap[$index]); } return null; @@ -137,14 +137,14 @@ class HashTable /** * Get by hashcode. * - * @param string $pHashCode + * @param string $hashCode * * @return IComparable */ - public function getByHashCode($pHashCode) + public function getByHashCode($hashCode) { - if (isset($this->items[$pHashCode])) { - return $this->items[$pHashCode]; + if (isset($this->items[$hashCode])) { + return $this->items[$hashCode]; } return null; diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index 60995c34..0fb0e89b 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -69,19 +69,19 @@ abstract class IOFactory /** * Loads Spreadsheet from file using automatic IReader resolution. */ - public static function load(string $pFilename): Spreadsheet + public static function load(string $filename): Spreadsheet { - $reader = self::createReaderForFile($pFilename); + $reader = self::createReaderForFile($filename); - return $reader->load($pFilename); + return $reader->load($filename); } /** * Identify file type using automatic IReader resolution. */ - public static function identify(string $pFilename): string + public static function identify(string $filename): string { - $reader = self::createReaderForFile($pFilename); + $reader = self::createReaderForFile($filename); $className = get_class($reader); $classType = explode('\\', $className); unset($reader); From af3918cac89935a86d357c144470d0d991433615 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 17:45:12 +0100 Subject: [PATCH 18/41] Sane argument names in the Reference Helper, Settings and Spreadsheet classes --- src/PhpSpreadsheet/ReferenceHelper.php | 450 ++++++++++++------------- src/PhpSpreadsheet/Settings.php | 8 +- src/PhpSpreadsheet/Spreadsheet.php | 238 ++++++------- 3 files changed, 349 insertions(+), 347 deletions(-) diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 13f7cf71..09b88b25 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -119,26 +119,26 @@ class ReferenceHelper * * @param string $cellAddress Address of the cell we're testing * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfCols Number of columns to insert/delete (negative values indicate deletion) * * @return bool */ - private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols) + private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfCols) { [$cellColumn, $cellRow] = Coordinate::coordinateFromString($cellAddress); $cellColumnIndex = Coordinate::columnIndexFromString($cellColumn); // Is cell within the range of rows/columns if we're deleting if ( - $pNumRows < 0 && - ($cellRow >= ($beforeRow + $pNumRows)) && + $numberOfRows < 0 && + ($cellRow >= ($beforeRow + $numberOfRows)) && ($cellRow < $beforeRow) ) { return true; } elseif ( - $pNumCols < 0 && - ($cellColumnIndex >= ($beforeColumnIndex + $pNumCols)) && + $numberOfCols < 0 && + ($cellColumnIndex >= ($beforeColumnIndex + $numberOfCols)) && ($cellColumnIndex < $beforeColumnIndex) ) { return true; @@ -150,30 +150,30 @@ class ReferenceHelper /** * Update page breaks when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustPageBreaks(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustPageBreaks(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aBreaks = $pSheet->getBreaks(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aBreaks = $worksheet->getBreaks(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aBreaks, ['self', 'cellReverseSort']) : uksort($aBreaks, ['self', 'cellSort']); foreach ($aBreaks as $key => $value) { - if (self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { + if (self::cellAddressInDeleteRange($key, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfColumns)) { // If we're deleting, then clear any defined breaks that are within the range // of rows/columns that we're deleting - $pSheet->setBreak($key, Worksheet::BREAK_NONE); + $worksheet->setBreak($key, Worksheet::BREAK_NONE); } else { // Otherwise update any affected breaks by inserting a new break at the appropriate point // and removing the old affected break - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->setBreak($newReference, $value) + $worksheet->setBreak($newReference, $value) ->setBreak($key, Worksheet::BREAK_NONE); } } @@ -183,51 +183,51 @@ class ReferenceHelper /** * Update cell comments when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aComments = $pSheet->getComments(); + $aComments = $worksheet->getComments(); $aNewComments = []; // the new array of all comments foreach ($aComments as $key => &$value) { // Any comments inside a deleted range will be ignored - if (!self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { + if (!self::cellAddressInDeleteRange($key, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfColumns)) { // Otherwise build a new array of comments indexed by the adjusted cell reference - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); $aNewComments[$newReference] = $value; } } // Replace the comments array with the new set of comments - $pSheet->setComments($aNewComments); + $worksheet->setComments($aNewComments); } /** * Update hyperlinks when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aHyperlinkCollection = $pSheet->getHyperlinkCollection(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aHyperlinkCollection = $worksheet->getHyperlinkCollection(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aHyperlinkCollection, ['self', 'cellReverseSort']) : uksort($aHyperlinkCollection, ['self', 'cellSort']); foreach ($aHyperlinkCollection as $key => $value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->setHyperlink($newReference, $value); - $pSheet->setHyperlink($key, null); + $worksheet->setHyperlink($newReference, $value); + $worksheet->setHyperlink($key, null); } } } @@ -242,7 +242,7 @@ class ReferenceHelper * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustDataValidations(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void { $aDataValidationCollection = $pSheet->getDataValidationCollection(); ($pNumCols > 0 || $pNumRows > 0) ? @@ -260,44 +260,44 @@ class ReferenceHelper /** * Update merged cells when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustMergeCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aMergeCells = $pSheet->getMergeCells(); + $aMergeCells = $worksheet->getMergeCells(); $aNewMergeCells = []; // the new array of all merge cells foreach ($aMergeCells as $key => &$value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); $aNewMergeCells[$newReference] = $newReference; } - $pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array + $worksheet->setMergeCells($aNewMergeCells); // replace the merge cells array } /** * Update protected cells when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustProtectedCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aProtectedCells = $pSheet->getProtectedCells(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aProtectedCells = $worksheet->getProtectedCells(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aProtectedCells, ['self', 'cellReverseSort']) : uksort($aProtectedCells, ['self', 'cellSort']); foreach ($aProtectedCells as $key => $value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->protectCells($newReference, $value, true); - $pSheet->unprotectCells($key); + $worksheet->protectCells($newReference, $value, true); + $worksheet->unprotectCells($key); } } } @@ -305,54 +305,54 @@ class ReferenceHelper /** * Update column dimensions when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustColumnDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true); + $aColumnDimensions = array_reverse($worksheet->getColumnDimensions(), true); if (!empty($aColumnDimensions)) { foreach ($aColumnDimensions as $objColumnDimension) { - $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $beforeCellAddress, $numberOfColumns, $numberOfRows); [$newReference] = Coordinate::coordinateFromString($newReference); if ($objColumnDimension->getColumnIndex() != $newReference) { $objColumnDimension->setColumnIndex($newReference); } } - $pSheet->refreshColumnDimensions(); + $worksheet->refreshColumnDimensions(); } } /** * Update row dimensions when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustRowDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aRowDimensions = array_reverse($pSheet->getRowDimensions(), true); + $aRowDimensions = array_reverse($worksheet->getRowDimensions(), true); if (!empty($aRowDimensions)) { foreach ($aRowDimensions as $objRowDimension) { - $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $beforeCellAddress, $numberOfColumns, $numberOfRows); [, $newReference] = Coordinate::coordinateFromString($newReference); if ($objRowDimension->getRowIndex() != $newReference) { $objRowDimension->setRowIndex($newReference); } } - $pSheet->refreshRowDimensions(); + $worksheet->refreshRowDimensions(); - $copyDimension = $pSheet->getRowDimension($beforeRow - 1); - for ($i = $beforeRow; $i <= $beforeRow - 1 + $pNumRows; ++$i) { - $newDimension = $pSheet->getRowDimension($i); + $copyDimension = $worksheet->getRowDimension($beforeRow - 1); + for ($i = $beforeRow; $i <= $beforeRow - 1 + $numberOfRows; ++$i) { + $newDimension = $worksheet->getRowDimension($i); $newDimension->setRowHeight($copyDimension->getRowHeight()); $newDimension->setVisible($copyDimension->getVisible()); $newDimension->setOutlineLevel($copyDimension->getOutlineLevel()); @@ -364,47 +364,47 @@ class ReferenceHelper /** * Insert a new column or row, updating all possible related data. * - * @param string $pBefore Insert before this cell address (e.g. 'A1') - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) - * @param Worksheet $pSheet The worksheet that we're editing + * @param string $beforeCellAddress Insert before this cell address (e.g. 'A1') + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) + * @param Worksheet $worksheet The worksheet that we're editing */ - public function insertNewBefore($pBefore, $pNumCols, $pNumRows, Worksheet $pSheet): void + public function insertNewBefore($beforeCellAddress, $numberOfColumns, $numberOfRows, Worksheet $worksheet): void { - $remove = ($pNumCols < 0 || $pNumRows < 0); - $allCoordinates = $pSheet->getCoordinates(); + $remove = ($numberOfColumns < 0 || $numberOfRows < 0); + $allCoordinates = $worksheet->getCoordinates(); // Get coordinate of $pBefore - [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($pBefore); + [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($beforeCellAddress); $beforeColumnIndex = Coordinate::columnIndexFromString($beforeColumn); // Clear cells if we are removing columns or rows - $highestColumn = $pSheet->getHighestColumn(); - $highestRow = $pSheet->getHighestRow(); + $highestColumn = $worksheet->getHighestColumn(); + $highestRow = $worksheet->getHighestRow(); // 1. Clear column strips if we are removing columns - if ($pNumCols < 0 && $beforeColumnIndex - 2 + $pNumCols > 0) { + if ($numberOfColumns < 0 && $beforeColumnIndex - 2 + $numberOfColumns > 0) { for ($i = 1; $i <= $highestRow - 1; ++$i) { - for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 2; ++$j) { + for ($j = $beforeColumnIndex - 1 + $numberOfColumns; $j <= $beforeColumnIndex - 2; ++$j) { $coordinate = Coordinate::stringFromColumnIndex($j + 1) . $i; - $pSheet->removeConditionalStyles($coordinate); - if ($pSheet->cellExists($coordinate)) { - $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); - $pSheet->getCell($coordinate)->setXfIndex(0); + $worksheet->removeConditionalStyles($coordinate); + if ($worksheet->cellExists($coordinate)) { + $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setXfIndex(0); } } } } // 2. Clear row strips if we are removing rows - if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) { + if ($numberOfRows < 0 && $beforeRow - 1 + $numberOfRows > 0) { for ($i = $beforeColumnIndex - 1; $i <= Coordinate::columnIndexFromString($highestColumn) - 1; ++$i) { - for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) { + for ($j = $beforeRow + $numberOfRows; $j <= $beforeRow - 1; ++$j) { $coordinate = Coordinate::stringFromColumnIndex($i + 1) . $j; - $pSheet->removeConditionalStyles($coordinate); - if ($pSheet->cellExists($coordinate)) { - $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); - $pSheet->getCell($coordinate)->setXfIndex(0); + $worksheet->removeConditionalStyles($coordinate); + if ($worksheet->cellExists($coordinate)) { + $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setXfIndex(0); } } } @@ -416,85 +416,85 @@ class ReferenceHelper $allCoordinates = array_reverse($allCoordinates); } while ($coordinate = array_pop($allCoordinates)) { - $cell = $pSheet->getCell($coordinate); + $cell = $worksheet->getCell($coordinate); $cellIndex = Coordinate::columnIndexFromString($cell->getColumn()); - if ($cellIndex - 1 + $pNumCols < 0) { + if ($cellIndex - 1 + $numberOfColumns < 0) { continue; } // New coordinate - $newCoordinate = Coordinate::stringFromColumnIndex($cellIndex + $pNumCols) . ($cell->getRow() + $pNumRows); + $newCoordinate = Coordinate::stringFromColumnIndex($cellIndex + $numberOfColumns) . ($cell->getRow() + $numberOfRows); // Should the cell be updated? Move value and cellXf index from one cell to another. if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) { // Update cell styles - $pSheet->getCell($newCoordinate)->setXfIndex($cell->getXfIndex()); + $worksheet->getCell($newCoordinate)->setXfIndex($cell->getXfIndex()); // Insert this cell at its new location if ($cell->getDataType() == DataType::TYPE_FORMULA) { // Formula should be adjusted - $pSheet->getCell($newCoordinate) - ->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); + $worksheet->getCell($newCoordinate) + ->setValue($this->updateFormulaReferences($cell->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows, $worksheet->getTitle())); } else { // Formula should not be adjusted - $pSheet->getCell($newCoordinate)->setValue($cell->getValue()); + $worksheet->getCell($newCoordinate)->setValue($cell->getValue()); } // Clear the original cell - $pSheet->getCellCollection()->delete($coordinate); + $worksheet->getCellCollection()->delete($coordinate); } else { /* We don't need to update styles for rows/columns before our insertion position, but we do still need to adjust any formulae in those cells */ if ($cell->getDataType() == DataType::TYPE_FORMULA) { // Formula should be adjusted - $cell->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); + $cell->setValue($this->updateFormulaReferences($cell->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows, $worksheet->getTitle())); } } } // Duplicate styles for the newly inserted cells - $highestColumn = $pSheet->getHighestColumn(); - $highestRow = $pSheet->getHighestRow(); + $highestColumn = $worksheet->getHighestColumn(); + $highestRow = $worksheet->getHighestRow(); - if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) { + if ($numberOfColumns > 0 && $beforeColumnIndex - 2 > 0) { for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) { // Style $coordinate = Coordinate::stringFromColumnIndex($beforeColumnIndex - 1) . $i; - if ($pSheet->cellExists($coordinate)) { - $xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); - $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? - $pSheet->getConditionalStyles($coordinate) : false; - for ($j = $beforeColumnIndex; $j <= $beforeColumnIndex - 1 + $pNumCols; ++$j) { - $pSheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex); + if ($worksheet->cellExists($coordinate)) { + $xfIndex = $worksheet->getCell($coordinate)->getXfIndex(); + $conditionalStyles = $worksheet->conditionalStylesExists($coordinate) ? + $worksheet->getConditionalStyles($coordinate) : false; + for ($j = $beforeColumnIndex; $j <= $beforeColumnIndex - 1 + $numberOfColumns; ++$j) { + $worksheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex); if ($conditionalStyles) { $cloned = []; foreach ($conditionalStyles as $conditionalStyle) { $cloned[] = clone $conditionalStyle; } - $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($j) . $i, $cloned); + $worksheet->setConditionalStyles(Coordinate::stringFromColumnIndex($j) . $i, $cloned); } } } } } - if ($pNumRows > 0 && $beforeRow - 1 > 0) { + if ($numberOfRows > 0 && $beforeRow - 1 > 0) { for ($i = $beforeColumnIndex; $i <= Coordinate::columnIndexFromString($highestColumn); ++$i) { // Style $coordinate = Coordinate::stringFromColumnIndex($i) . ($beforeRow - 1); - if ($pSheet->cellExists($coordinate)) { - $xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); - $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? - $pSheet->getConditionalStyles($coordinate) : false; - for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) { - $pSheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); + if ($worksheet->cellExists($coordinate)) { + $xfIndex = $worksheet->getCell($coordinate)->getXfIndex(); + $conditionalStyles = $worksheet->conditionalStylesExists($coordinate) ? + $worksheet->getConditionalStyles($coordinate) : false; + for ($j = $beforeRow; $j <= $beforeRow - 1 + $numberOfRows; ++$j) { + $worksheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); if ($conditionalStyles) { $cloned = []; foreach ($conditionalStyles as $conditionalStyle) { $cloned[] = clone $conditionalStyle; } - $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($i) . $j, $cloned); + $worksheet->setConditionalStyles(Coordinate::stringFromColumnIndex($i) . $j, $cloned); } } } @@ -502,47 +502,47 @@ class ReferenceHelper } // Update worksheet: column dimensions - $this->adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustColumnDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: row dimensions - $this->adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustRowDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: page breaks - $this->adjustPageBreaks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustPageBreaks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: comments - $this->adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: hyperlinks - $this->adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: data validations - $this->adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustDataValidations($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: merge cells - $this->adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustMergeCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: protected cells - $this->adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustProtectedCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: autofilter - $autoFilter = $pSheet->getAutoFilter(); + $autoFilter = $worksheet->getAutoFilter(); $autoFilterRange = $autoFilter->getRange(); if (!empty($autoFilterRange)) { - if ($pNumCols != 0) { + if ($numberOfColumns != 0) { $autoFilterColumns = $autoFilter->getColumns(); if (count($autoFilterColumns) > 0) { $column = ''; $row = 0; - sscanf($pBefore, '%[A-Z]%d', $column, $row); + sscanf($beforeCellAddress, '%[A-Z]%d', $column, $row); $columnIndex = Coordinate::columnIndexFromString($column); [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($autoFilterRange); if ($columnIndex <= $rangeEnd[0]) { - if ($pNumCols < 0) { + if ($numberOfColumns < 0) { // If we're actually deleting any columns that fall within the autofilter range, // then we delete any rules for those columns - $deleteColumn = $columnIndex + $pNumCols - 1; - $deleteCount = abs($pNumCols); + $deleteColumn = $columnIndex + $numberOfColumns - 1; + $deleteCount = abs($numberOfColumns); for ($i = 1; $i <= $deleteCount; ++$i) { if (isset($autoFilterColumns[Coordinate::stringFromColumnIndex($deleteColumn + 1)])) { $autoFilter->clearColumn(Coordinate::stringFromColumnIndex($deleteColumn + 1)); @@ -553,10 +553,10 @@ class ReferenceHelper $startCol = ($columnIndex > $rangeStart[0]) ? $columnIndex : $rangeStart[0]; // Shuffle columns in autofilter range - if ($pNumCols > 0) { + if ($numberOfColumns > 0) { $startColRef = $startCol; $endColRef = $rangeEnd[0]; - $toColRef = $rangeEnd[0] + $pNumCols; + $toColRef = $rangeEnd[0] + $numberOfColumns; do { $autoFilter->shiftColumn(Coordinate::stringFromColumnIndex($endColRef), Coordinate::stringFromColumnIndex($toColRef)); @@ -566,7 +566,7 @@ class ReferenceHelper } else { // For delete, we shuffle from beginning to end to avoid overwriting $startColID = Coordinate::stringFromColumnIndex($startCol); - $toColID = Coordinate::stringFromColumnIndex($startCol + $pNumCols); + $toColID = Coordinate::stringFromColumnIndex($startCol + $numberOfColumns); $endColID = Coordinate::stringFromColumnIndex($rangeEnd[0] + 1); do { $autoFilter->shiftColumn($startColID, $toColID); @@ -577,62 +577,62 @@ class ReferenceHelper } } } - $pSheet->setAutoFilter($this->updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows)); + $worksheet->setAutoFilter($this->updateCellReference($autoFilterRange, $beforeCellAddress, $numberOfColumns, $numberOfRows)); } // Update worksheet: freeze pane - if ($pSheet->getFreezePane()) { - $splitCell = $pSheet->getFreezePane(); - $topLeftCell = $pSheet->getTopLeftCell(); + if ($worksheet->getFreezePane()) { + $splitCell = $worksheet->getFreezePane(); + $topLeftCell = $worksheet->getTopLeftCell(); - $splitCell = $this->updateCellReference($splitCell, $pBefore, $pNumCols, $pNumRows); - $topLeftCell = $this->updateCellReference($topLeftCell, $pBefore, $pNumCols, $pNumRows); + $splitCell = $this->updateCellReference($splitCell, $beforeCellAddress, $numberOfColumns, $numberOfRows); + $topLeftCell = $this->updateCellReference($topLeftCell, $beforeCellAddress, $numberOfColumns, $numberOfRows); - $pSheet->freezePane($splitCell, $topLeftCell); + $worksheet->freezePane($splitCell, $topLeftCell); } // Page setup - if ($pSheet->getPageSetup()->isPrintAreaSet()) { - $pSheet->getPageSetup()->setPrintArea($this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows)); + if ($worksheet->getPageSetup()->isPrintAreaSet()) { + $worksheet->getPageSetup()->setPrintArea($this->updateCellReference($worksheet->getPageSetup()->getPrintArea(), $beforeCellAddress, $numberOfColumns, $numberOfRows)); } // Update worksheet: drawings - $aDrawings = $pSheet->getDrawingCollection(); + $aDrawings = $worksheet->getDrawingCollection(); foreach ($aDrawings as $objDrawing) { - $newReference = $this->updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($objDrawing->getCoordinates(), $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($objDrawing->getCoordinates() != $newReference) { $objDrawing->setCoordinates($newReference); } } // Update workbook: define names - if (count($pSheet->getParent()->getDefinedNames()) > 0) { - foreach ($pSheet->getParent()->getDefinedNames() as $definedName) { - if ($definedName->getWorksheet()->getHashCode() === $pSheet->getHashCode()) { - $definedName->setValue($this->updateCellReference($definedName->getValue(), $pBefore, $pNumCols, $pNumRows)); + if (count($worksheet->getParent()->getDefinedNames()) > 0) { + foreach ($worksheet->getParent()->getDefinedNames() as $definedName) { + if ($definedName->getWorksheet()->getHashCode() === $worksheet->getHashCode()) { + $definedName->setValue($this->updateCellReference($definedName->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows)); } } } // Garbage collect - $pSheet->garbageCollect(); + $worksheet->garbageCollect(); } /** * Update references within formulas. * - * @param string $pFormula Formula to update - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to insert - * @param int $pNumRows Number of rows to insert - * @param string $sheetName Worksheet name/title + * @param string $formula Formula to update + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to insert + * @param int $numberOfRows Number of rows to insert + * @param string $worksheetName Worksheet name/title * * @return string Updated formula */ - public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, $sheetName = '') + public function updateFormulaReferences($formula = '', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0, $worksheetName = '') { // Update cell references in the formula - $formulaBlocks = explode('"', $pFormula); + $formulaBlocks = explode('"', $formula); $i = false; foreach ($formulaBlocks as &$formulaBlock) { // Ignore blocks that were enclosed in quotes (alternating entries in the $formulaBlocks array after the explode) @@ -645,11 +645,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = substr($this->updateCellReference('$A' . $match[3], $pBefore, $pNumCols, $pNumRows), 2); - $modified4 = substr($this->updateCellReference('$A' . $match[4], $pBefore, $pNumCols, $pNumRows), 2); + $modified3 = substr($this->updateCellReference('$A' . $match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows), 2); + $modified4 = substr($this->updateCellReference('$A' . $match[4], $beforeCellAddress, $numberOfColumns, $numberOfRows), 2); if ($match[3] . ':' . $match[4] !== $modified3 . ':' . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more @@ -670,11 +670,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = substr($this->updateCellReference($match[3] . '$1', $pBefore, $pNumCols, $pNumRows), 0, -2); - $modified4 = substr($this->updateCellReference($match[4] . '$1', $pBefore, $pNumCols, $pNumRows), 0, -2); + $modified3 = substr($this->updateCellReference($match[3] . '$1', $beforeCellAddress, $numberOfColumns, $numberOfRows), 0, -2); + $modified4 = substr($this->updateCellReference($match[4] . '$1', $beforeCellAddress, $numberOfColumns, $numberOfRows), 0, -2); if ($match[3] . ':' . $match[4] !== $modified3 . ':' . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more @@ -695,11 +695,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); - $modified4 = $this->updateCellReference($match[4], $pBefore, $pNumCols, $pNumRows); + $modified3 = $this->updateCellReference($match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows); + $modified4 = $this->updateCellReference($match[4], $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($match[3] . $match[4] !== $modified3 . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; [$column, $row] = Coordinate::coordinateFromString($match[3]); @@ -723,9 +723,9 @@ class ReferenceHelper $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3]; - $modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); + $modified3 = $this->updateCellReference($match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($match[3] !== $modified3) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3; [$column, $row] = Coordinate::coordinateFromString($match[3]); @@ -742,7 +742,7 @@ class ReferenceHelper } } if ($adjustCount > 0) { - if ($pNumCols > 0 || $pNumRows > 0) { + if ($numberOfColumns > 0 || $numberOfRows > 0) { krsort($cellTokens); krsort($newCellTokens); } else { @@ -762,22 +762,22 @@ class ReferenceHelper /** * Update all cell references within a formula, irrespective of worksheet. */ - public function updateFormulaReferencesAnyWorksheet(string $formula = '', int $insertColumns = 0, int $insertRows = 0): string + public function updateFormulaReferencesAnyWorksheet(string $formula = '', int $numberOfColumns = 0, int $numberOfRows = 0): string { - $formula = $this->updateCellReferencesAllWorksheets($formula, $insertColumns, $insertRows); + $formula = $this->updateCellReferencesAllWorksheets($formula, $numberOfColumns, $numberOfRows); - if ($insertColumns !== 0) { - $formula = $this->updateColumnRangesAllWorksheets($formula, $insertColumns); + if ($numberOfColumns !== 0) { + $formula = $this->updateColumnRangesAllWorksheets($formula, $numberOfColumns); } - if ($insertRows !== 0) { - $formula = $this->updateRowRangesAllWorksheets($formula, $insertRows); + if ($numberOfRows !== 0) { + $formula = $this->updateRowRangesAllWorksheets($formula, $numberOfRows); } return $formula; } - private function updateCellReferencesAllWorksheets(string $formula, int $insertColumns, int $insertRows): string + private function updateCellReferencesAllWorksheets(string $formula, int $numberOfColumns, int $numberOfRows): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_CELLREF_RELATIVE . '/mui', @@ -804,11 +804,11 @@ class ReferenceHelper $row = $rows[$splitCount][0]; if (!empty($column) && $column[0] !== '$') { - $column = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($column) + $insertColumns); + $column = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($column) + $numberOfColumns); $formula = substr($formula, 0, $columnOffset) . $column . substr($formula, $columnOffset + $columnLength); } if (!empty($row) && $row[0] !== '$') { - $row += $insertRows; + $row += $numberOfRows; $formula = substr($formula, 0, $rowOffset) . $row . substr($formula, $rowOffset + $rowLength); } } @@ -816,7 +816,7 @@ class ReferenceHelper return $formula; } - private function updateColumnRangesAllWorksheets(string $formula, int $insertColumns): string + private function updateColumnRangesAllWorksheets(string $formula, int $numberOfColumns): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_COLUMNRANGE_RELATIVE . '/mui', @@ -843,11 +843,11 @@ class ReferenceHelper $toColumn = $toColumns[$splitCount][0]; if (!empty($fromColumn) && $fromColumn[0] !== '$') { - $fromColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($fromColumn) + $insertColumns); + $fromColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($fromColumn) + $numberOfColumns); $formula = substr($formula, 0, $fromColumnOffset) . $fromColumn . substr($formula, $fromColumnOffset + $fromColumnLength); } if (!empty($toColumn) && $toColumn[0] !== '$') { - $toColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($toColumn) + $insertColumns); + $toColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($toColumn) + $numberOfColumns); $formula = substr($formula, 0, $toColumnOffset) . $toColumn . substr($formula, $toColumnOffset + $toColumnLength); } } @@ -855,7 +855,7 @@ class ReferenceHelper return $formula; } - private function updateRowRangesAllWorksheets(string $formula, int $insertRows): string + private function updateRowRangesAllWorksheets(string $formula, int $numberOfRows): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_ROWRANGE_RELATIVE . '/mui', @@ -882,11 +882,11 @@ class ReferenceHelper $toRow = $toRows[$splitCount][0]; if (!empty($fromRow) && $fromRow[0] !== '$') { - $fromRow += $insertRows; + $fromRow += $numberOfRows; $formula = substr($formula, 0, $fromRowOffset) . $fromRow . substr($formula, $fromRowOffset + $fromRowLength); } if (!empty($toRow) && $toRow[0] !== '$') { - $toRow += $insertRows; + $toRow += $numberOfRows; $formula = substr($formula, 0, $toRowOffset) . $toRow . substr($formula, $toRowOffset + $toRowLength); } } @@ -897,29 +897,29 @@ class ReferenceHelper /** * Update cell reference. * - * @param string $pCellRange Cell range - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellReference Cell address or range of addresses + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell range */ - public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + public function updateCellReference($cellReference = 'A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { // Is it in another worksheet? Will not have to update anything. - if (strpos($pCellRange, '!') !== false) { - return $pCellRange; + if (strpos($cellReference, '!') !== false) { + return $cellReference; // Is it a range or a single cell? - } elseif (!Coordinate::coordinateIsRange($pCellRange)) { + } elseif (!Coordinate::coordinateIsRange($cellReference)) { // Single cell - return $this->updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows); - } elseif (Coordinate::coordinateIsRange($pCellRange)) { + return $this->updateSingleCellReference($cellReference, $beforeCellAddress, $numberOfColumns, $numberOfRows); + } elseif (Coordinate::coordinateIsRange($cellReference)) { // Range - return $this->updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows); + return $this->updateCellRange($cellReference, $beforeCellAddress, $numberOfColumns, $numberOfRows); } // Return original - return $pCellRange; + return $cellReference; } /** @@ -953,33 +953,33 @@ class ReferenceHelper /** * Update cell range. * - * @param string $pCellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell range */ - private function updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + private function updateCellRange($cellRange = 'A1:A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { - if (!Coordinate::coordinateIsRange($pCellRange)) { + if (!Coordinate::coordinateIsRange($cellRange)) { throw new Exception('Only cell ranges may be passed to this method.'); } // Update range - $range = Coordinate::splitRange($pCellRange); + $range = Coordinate::splitRange($cellRange); $ic = count($range); for ($i = 0; $i < $ic; ++$i) { $jc = count($range[$i]); for ($j = 0; $j < $jc; ++$j) { if (ctype_alpha($range[$i][$j])) { - $r = Coordinate::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $pBefore, $pNumCols, $pNumRows)); + $r = Coordinate::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $beforeCellAddress, $numberOfColumns, $numberOfRows)); $range[$i][$j] = $r[0]; } elseif (ctype_digit($range[$i][$j])) { - $r = Coordinate::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $pBefore, $pNumCols, $pNumRows)); + $r = Coordinate::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $beforeCellAddress, $numberOfColumns, $numberOfRows)); $range[$i][$j] = $r[1]; } else { - $range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); + $range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $beforeCellAddress, $numberOfColumns, $numberOfRows); } } } @@ -991,24 +991,24 @@ class ReferenceHelper /** * Update single cell reference. * - * @param string $pCellReference Single cell reference - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellReference Single cell reference + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell reference */ - private function updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + private function updateSingleCellReference($cellReference = 'A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { - if (Coordinate::coordinateIsRange($pCellReference)) { + if (Coordinate::coordinateIsRange($cellReference)) { throw new Exception('Only single cell references may be passed to this method.'); } - // Get coordinate of $pBefore - [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($pBefore); + // Get coordinate of $beforeCellAddress + [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($beforeCellAddress); - // Get coordinate of $pCellReference - [$newColumn, $newRow] = Coordinate::coordinateFromString($pCellReference); + // Get coordinate of $cellReference + [$newColumn, $newRow] = Coordinate::coordinateFromString($cellReference); // Verify which parts should be updated $updateColumn = (($newColumn[0] != '$') && ($beforeColumn[0] != '$') && (Coordinate::columnIndexFromString($newColumn) >= Coordinate::columnIndexFromString($beforeColumn))); @@ -1016,12 +1016,12 @@ class ReferenceHelper // Create new column reference if ($updateColumn) { - $newColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($newColumn) + $pNumCols); + $newColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($newColumn) + $numberOfColumns); } // Create new row reference if ($updateRow) { - $newRow = $newRow + $pNumRows; + $newRow = $newRow + $numberOfRows; } // Return new reference diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index d6223528..4d561252 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -71,16 +71,16 @@ class Settings /** * Identify to PhpSpreadsheet the external library to use for rendering charts. * - * @param string $rendererClass Class name of the chart renderer + * @param string $rendererClassName Class name of the chart renderer * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph */ - public static function setChartRenderer(string $rendererClass): void + public static function setChartRenderer(string $rendererClassName): void { - if (!is_a($rendererClass, IRenderer::class, true)) { + if (!is_a($rendererClassName, IRenderer::class, true)) { throw new Exception('Chart renderer must implement ' . IRenderer::class); } - self::$chartRenderer = $rendererClass; + self::$chartRenderer = $rendererClassName; } /** diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 19c11526..4ff00932 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -439,27 +439,27 @@ class Spreadsheet /** * Check if a sheet with a specified code name already exists. * - * @param string $pSheetCodeName Name of the worksheet to check + * @param string $codeName Name of the worksheet to check * * @return bool */ - public function sheetCodeNameExists($pSheetCodeName) + public function sheetCodeNameExists($codeName) { - return $this->getSheetByCodeName($pSheetCodeName) !== null; + return $this->getSheetByCodeName($codeName) !== null; } /** * Get sheet by code name. Warning : sheet don't have always a code name ! * - * @param string $pName Sheet name + * @param string $codeName Sheet name * * @return Worksheet */ - public function getSheetByCodeName($pName) + public function getSheetByCodeName($codeName) { $worksheetCount = count($this->workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { - if ($this->workSheetCollection[$i]->getCodeName() == $pName) { + if ($this->workSheetCollection[$i]->getCodeName() == $codeName) { return $this->workSheetCollection[$i]; } } @@ -545,9 +545,9 @@ class Spreadsheet /** * Set properties. */ - public function setProperties(Document\Properties $pValue): void + public function setProperties(Document\Properties $documentProperties): void { - $this->properties = $pValue; + $this->properties = $documentProperties; } /** @@ -563,9 +563,9 @@ class Spreadsheet /** * Set security. */ - public function setSecurity(Document\Security $pValue): void + public function setSecurity(Document\Security $documentSecurity): void { - $this->security = $pValue; + $this->security = $documentSecurity; } /** @@ -596,76 +596,78 @@ class Spreadsheet /** * Check if a sheet with a specified name already exists. * - * @param string $pSheetName Name of the worksheet to check + * @param string $worksheetName Name of the worksheet to check * * @return bool */ - public function sheetNameExists($pSheetName) + public function sheetNameExists($worksheetName) { - return $this->getSheetByName($pSheetName) !== null; + return $this->getSheetByName($worksheetName) !== null; } /** * Add sheet. * - * @param null|int $iSheetIndex Index where sheet should go (0,1,..., or null for last) + * @param Worksheet $worksheet The worskeet to add + * @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last) * * @return Worksheet + * @throws Exception */ - public function addSheet(Worksheet $pSheet, $iSheetIndex = null) + public function addSheet(Worksheet $worksheet, $sheetIndex = null) { - if ($this->sheetNameExists($pSheet->getTitle())) { + if ($this->sheetNameExists($worksheet->getTitle())) { throw new Exception( - "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first." + "Workbook already contains a worksheet named '{$worksheet->getTitle()}'. Rename this worksheet first." ); } - if ($iSheetIndex === null) { + if ($sheetIndex === null) { if ($this->activeSheetIndex < 0) { $this->activeSheetIndex = 0; } - $this->workSheetCollection[] = $pSheet; + $this->workSheetCollection[] = $worksheet; } else { // Insert the sheet at the requested index array_splice( $this->workSheetCollection, - $iSheetIndex, + $sheetIndex, 0, - [$pSheet] + [$worksheet] ); // Adjust active sheet index if necessary - if ($this->activeSheetIndex >= $iSheetIndex) { + if ($this->activeSheetIndex >= $sheetIndex) { ++$this->activeSheetIndex; } } - if ($pSheet->getParent() === null) { - $pSheet->rebindParent($this); + if ($worksheet->getParent() === null) { + $worksheet->rebindParent($this); } - return $pSheet; + return $worksheet; } /** * Remove sheet by index. * - * @param int $pIndex Active sheet index + * @param int $sheetIndex Index position of the worksheet to remove */ - public function removeSheetByIndex($pIndex): void + public function removeSheetByIndex($sheetIndex): void { $numSheets = count($this->workSheetCollection); - if ($pIndex > $numSheets - 1) { + if ($sheetIndex > $numSheets - 1) { throw new Exception( - "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + "You tried to remove a sheet by the out of bounds index: {$sheetIndex}. The actual number of sheets is {$numSheets}." ); } - array_splice($this->workSheetCollection, $pIndex, 1); + array_splice($this->workSheetCollection, $sheetIndex, 1); // Adjust active sheet index if necessary if ( - ($this->activeSheetIndex >= $pIndex) && - ($pIndex > count($this->workSheetCollection) - 1) + ($this->activeSheetIndex >= $sheetIndex) && + ($sheetIndex > count($this->workSheetCollection) - 1) ) { --$this->activeSheetIndex; } @@ -674,21 +676,21 @@ class Spreadsheet /** * Get sheet by index. * - * @param int $pIndex Sheet index + * @param int $sheetIndex Sheet index * * @return Worksheet */ - public function getSheet($pIndex) + public function getSheet($sheetIndex) { - if (!isset($this->workSheetCollection[$pIndex])) { + if (!isset($this->workSheetCollection[$sheetIndex])) { $numSheets = $this->getSheetCount(); throw new Exception( - "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}." + "Your requested sheet index: {$sheetIndex} is out of bounds. The actual number of sheets is {$numSheets}." ); } - return $this->workSheetCollection[$pIndex]; + return $this->workSheetCollection[$sheetIndex]; } /** @@ -704,15 +706,15 @@ class Spreadsheet /** * Get sheet by name. * - * @param string $pName Sheet name + * @param string $worksheetName Sheet name * * @return null|Worksheet */ - public function getSheetByName($pName) + public function getSheetByName($worksheetName) { $worksheetCount = count($this->workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { - if ($this->workSheetCollection[$i]->getTitle() === trim($pName, "'")) { + if ($this->workSheetCollection[$i]->getTitle() === trim($worksheetName, "'")) { return $this->workSheetCollection[$i]; } } @@ -725,10 +727,10 @@ class Spreadsheet * * @return int index */ - public function getIndex(Worksheet $pSheet) + public function getIndex(Worksheet $worksheet) { foreach ($this->workSheetCollection as $key => $value) { - if ($value->getHashCode() === $pSheet->getHashCode()) { + if ($value->getHashCode() === $worksheet->getHashCode()) { return $key; } } @@ -739,14 +741,14 @@ class Spreadsheet /** * Set index for sheet by sheet name. * - * @param string $sheetName Sheet name to modify index for - * @param int $newIndex New index for the sheet + * @param string $worksheetName Sheet name to modify index for + * @param int $newIndexPosition New index for the sheet * * @return int New sheet index */ - public function setIndexByName($sheetName, $newIndex) + public function setIndexByName($worksheetName, $newIndexPosition) { - $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); + $oldIndex = $this->getIndex($this->getSheetByName($worksheetName)); $pSheet = array_splice( $this->workSheetCollection, $oldIndex, @@ -754,12 +756,12 @@ class Spreadsheet ); array_splice( $this->workSheetCollection, - $newIndex, + $newIndexPosition, 0, $pSheet ); - return $newIndex; + return $newIndexPosition; } /** @@ -785,20 +787,20 @@ class Spreadsheet /** * Set active sheet index. * - * @param int $pIndex Active sheet index + * @param int $worksheetIndex Active sheet index * * @return Worksheet */ - public function setActiveSheetIndex($pIndex) + public function setActiveSheetIndex($worksheetIndex) { $numSheets = count($this->workSheetCollection); - if ($pIndex > $numSheets - 1) { + if ($worksheetIndex > $numSheets - 1) { throw new Exception( - "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + "You tried to set a sheet active by the out of bounds index: {$worksheetIndex}. The actual number of sheets is {$numSheets}." ); } - $this->activeSheetIndex = $pIndex; + $this->activeSheetIndex = $worksheetIndex; return $this->getActiveSheet(); } @@ -806,19 +808,19 @@ class Spreadsheet /** * Set active sheet index by name. * - * @param string $pValue Sheet title + * @param string $worksheetName Sheet title * * @return Worksheet */ - public function setActiveSheetIndexByName($pValue) + public function setActiveSheetIndexByName($worksheetName) { - if (($worksheet = $this->getSheetByName($pValue)) instanceof Worksheet) { + if (($worksheet = $this->getSheetByName($worksheetName)) instanceof Worksheet) { $this->setActiveSheetIndex($this->getIndex($worksheet)); return $worksheet; } - throw new Exception('Workbook does not contain sheet:' . $pValue); + throw new Exception('Workbook does not contain sheet:' . $worksheetName); } /** @@ -840,35 +842,35 @@ class Spreadsheet /** * Add external sheet. * - * @param Worksheet $pSheet External sheet to add - * @param null|int $iSheetIndex Index where sheet should go (0,1,..., or null for last) + * @param Worksheet $worksheet External sheet to add + * @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last) * * @return Worksheet */ - public function addExternalSheet(Worksheet $pSheet, $iSheetIndex = null) + public function addExternalSheet(Worksheet $worksheet, $sheetIndex = null) { - if ($this->sheetNameExists($pSheet->getTitle())) { - throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); + if ($this->sheetNameExists($worksheet->getTitle())) { + throw new Exception("Workbook already contains a worksheet named '{$worksheet->getTitle()}'. Rename the external sheet first."); } // count how many cellXfs there are in this workbook currently, we will need this below $countCellXfs = count($this->cellXfCollection); // copy all the shared cellXfs from the external workbook and append them to the current - foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) { + foreach ($worksheet->getParent()->getCellXfCollection() as $cellXf) { $this->addCellXf(clone $cellXf); } // move sheet to this workbook - $pSheet->rebindParent($this); + $worksheet->rebindParent($this); // update the cellXfs - foreach ($pSheet->getCoordinates(false) as $coordinate) { - $cell = $pSheet->getCell($coordinate); + foreach ($worksheet->getCoordinates(false) as $coordinate) { + $cell = $worksheet->getCell($coordinate); $cell->setXfIndex($cell->getXfIndex() + $countCellXfs); } - return $this->addSheet($pSheet, $iSheetIndex); + return $this->addSheet($worksheet, $sheetIndex); } /** @@ -948,9 +950,9 @@ class Spreadsheet /** * Get named range. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getNamedRange(string $namedRange, ?Worksheet $pSheet = null): ?NamedRange + public function getNamedRange(string $namedRange, ?Worksheet $worksheet = null): ?NamedRange { $returnValue = null; @@ -959,7 +961,7 @@ class Spreadsheet // first look for global named range $returnValue = $this->getGlobalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE); // then look for local named range (has priority over global named range if both names exist) - $returnValue = $this->getLocalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE, $pSheet) ?: $returnValue; + $returnValue = $this->getLocalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE, $worksheet) ?: $returnValue; } return $returnValue instanceof NamedRange ? $returnValue : null; @@ -968,9 +970,9 @@ class Spreadsheet /** * Get named formula. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getNamedFormula(string $namedFormula, ?Worksheet $pSheet = null): ?NamedFormula + public function getNamedFormula(string $namedFormula, ?Worksheet $worksheet = null): ?NamedFormula { $returnValue = null; @@ -979,7 +981,7 @@ class Spreadsheet // first look for global named formula $returnValue = $this->getGlobalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA); // then look for local named formula (has priority over global named formula if both names exist) - $returnValue = $this->getLocalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA, $pSheet) ?: $returnValue; + $returnValue = $this->getLocalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA, $worksheet) ?: $returnValue; } return $returnValue instanceof NamedFormula ? $returnValue : null; @@ -1009,9 +1011,9 @@ class Spreadsheet /** * Get named range. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getDefinedName(string $definedName, ?Worksheet $pSheet = null): ?DefinedName + public function getDefinedName(string $definedName, ?Worksheet $worksheet = null): ?DefinedName { $returnValue = null; @@ -1023,8 +1025,8 @@ class Spreadsheet } // then look for local defined name (has priority over global defined name if both names exist) - if (($pSheet !== null) && isset($this->definedNames[$pSheet->getTitle() . '!' . $definedName])) { - $returnValue = $this->definedNames[$pSheet->getTitle() . '!' . $definedName]; + if (($worksheet !== null) && isset($this->definedNames[$worksheet->getTitle() . '!' . $definedName])) { + $returnValue = $this->definedNames[$worksheet->getTitle() . '!' . $definedName]; } } @@ -1034,53 +1036,53 @@ class Spreadsheet /** * Remove named range. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeNamedRange(string $namedRange, ?Worksheet $pSheet = null): self + public function removeNamedRange(string $namedRange, ?Worksheet $worksheet = null): self { - if ($this->getNamedRange($namedRange, $pSheet) === null) { + if ($this->getNamedRange($namedRange, $worksheet) === null) { return $this; } - return $this->removeDefinedName($namedRange, $pSheet); + return $this->removeDefinedName($namedRange, $worksheet); } /** * Remove named formula. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeNamedFormula(string $namedFormula, ?Worksheet $pSheet = null): self + public function removeNamedFormula(string $namedFormula, ?Worksheet $worksheet = null): self { - if ($this->getNamedFormula($namedFormula, $pSheet) === null) { + if ($this->getNamedFormula($namedFormula, $worksheet) === null) { return $this; } - return $this->removeDefinedName($namedFormula, $pSheet); + return $this->removeDefinedName($namedFormula, $worksheet); } /** * Remove defined name. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeDefinedName(string $definedName, ?Worksheet $pSheet = null): self + public function removeDefinedName(string $definedName, ?Worksheet $worksheet = null): self { $definedName = StringHelper::strToUpper($definedName); - if ($pSheet === null) { + if ($worksheet === null) { if (isset($this->definedNames[$definedName])) { unset($this->definedNames[$definedName]); } } else { - if (isset($this->definedNames[$pSheet->getTitle() . '!' . $definedName])) { - unset($this->definedNames[$pSheet->getTitle() . '!' . $definedName]); + if (isset($this->definedNames[$worksheet->getTitle() . '!' . $definedName])) { + unset($this->definedNames[$worksheet->getTitle() . '!' . $definedName]); } elseif (isset($this->definedNames[$definedName])) { unset($this->definedNames[$definedName]); } @@ -1142,26 +1144,26 @@ class Spreadsheet /** * Get cellXf by index. * - * @param int $pIndex + * @param int $cellStyleIndex * * @return Style */ - public function getCellXfByIndex($pIndex) + public function getCellXfByIndex($cellStyleIndex) { - return $this->cellXfCollection[$pIndex]; + return $this->cellXfCollection[$cellStyleIndex]; } /** * Get cellXf by hash code. * - * @param string $pValue + * @param string $hashcode * * @return false|Style */ - public function getCellXfByHashCode($pValue) + public function getCellXfByHashCode($hashcode) { foreach ($this->cellXfCollection as $cellXf) { - if ($cellXf->getHashCode() === $pValue) { + if ($cellXf->getHashCode() === $hashcode) { return $cellXf; } } @@ -1172,13 +1174,13 @@ class Spreadsheet /** * Check if style exists in style collection. * - * @param Style $pCellStyle + * @param Style $cellStyleIndex * * @return bool */ - public function cellXfExists($pCellStyle) + public function cellXfExists($cellStyleIndex) { - return in_array($pCellStyle, $this->cellXfCollection, true); + return in_array($cellStyleIndex, $this->cellXfCollection, true); } /** @@ -1207,26 +1209,26 @@ class Spreadsheet /** * Remove cellXf by index. It is ensured that all cells get their xf index updated. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf */ - public function removeCellXfByIndex($pIndex): void + public function removeCellXfByIndex($cellStyleIndex): void { - if ($pIndex > count($this->cellXfCollection) - 1) { + if ($cellStyleIndex > count($this->cellXfCollection) - 1) { throw new Exception('CellXf index is out of bounds.'); } // first remove the cellXf - array_splice($this->cellXfCollection, $pIndex, 1); + array_splice($this->cellXfCollection, $cellStyleIndex, 1); // then update cellXf indexes for cells foreach ($this->workSheetCollection as $worksheet) { foreach ($worksheet->getCoordinates(false) as $coordinate) { $cell = $worksheet->getCell($coordinate); $xfIndex = $cell->getXfIndex(); - if ($xfIndex > $pIndex) { + if ($xfIndex > $cellStyleIndex) { // decrease xf index by 1 $cell->setXfIndex($xfIndex - 1); - } elseif ($xfIndex == $pIndex) { + } elseif ($xfIndex == $cellStyleIndex) { // set to default xf index 0 $cell->setXfIndex(0); } @@ -1257,26 +1259,26 @@ class Spreadsheet /** * Get cellStyleXf by index. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf * * @return Style */ - public function getCellStyleXfByIndex($pIndex) + public function getCellStyleXfByIndex($cellStyleIndex) { - return $this->cellStyleXfCollection[$pIndex]; + return $this->cellStyleXfCollection[$cellStyleIndex]; } /** * Get cellStyleXf by hash code. * - * @param string $pValue + * @param string $hashcode * * @return false|Style */ - public function getCellStyleXfByHashCode($pValue) + public function getCellStyleXfByHashCode($hashcode) { foreach ($this->cellStyleXfCollection as $cellStyleXf) { - if ($cellStyleXf->getHashCode() === $pValue) { + if ($cellStyleXf->getHashCode() === $hashcode) { return $cellStyleXf; } } @@ -1287,23 +1289,23 @@ class Spreadsheet /** * Add a cellStyleXf to the workbook. */ - public function addCellStyleXf(Style $pStyle): void + public function addCellStyleXf(Style $style): void { - $this->cellStyleXfCollection[] = $pStyle; - $pStyle->setIndex(count($this->cellStyleXfCollection) - 1); + $this->cellStyleXfCollection[] = $style; + $style->setIndex(count($this->cellStyleXfCollection) - 1); } /** * Remove cellStyleXf by index. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf */ - public function removeCellStyleXfByIndex($pIndex): void + public function removeCellStyleXfByIndex($cellStyleIndex): void { - if ($pIndex > count($this->cellStyleXfCollection) - 1) { + if ($cellStyleIndex > count($this->cellStyleXfCollection) - 1) { throw new Exception('CellStyleXf index is out of bounds.'); } - array_splice($this->cellStyleXfCollection, $pIndex, 1); + array_splice($this->cellStyleXfCollection, $cellStyleIndex, 1); } /** From 4ab629ff82bc3062fa779d79090f747317ad3126 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 18:04:45 +0100 Subject: [PATCH 19/41] Sane argument names in the Reference Helper, Settings and Spreadsheet classes --- src/PhpSpreadsheet/Spreadsheet.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 4ff00932..bdc54d89 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -612,7 +612,6 @@ class Spreadsheet * @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last) * * @return Worksheet - * @throws Exception */ public function addSheet(Worksheet $worksheet, $sheetIndex = null) { From b5c2709002f573a21a08d482cf4e210f8ca0c7fb Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 19:28:45 +0100 Subject: [PATCH 20/41] Sane argument names in the Cell classes --- src/PhpSpreadsheet/Cell/Cell.php | 102 +++++++-------- src/PhpSpreadsheet/Cell/Coordinate.php | 144 ++++++++++----------- src/PhpSpreadsheet/Cell/DataType.php | 26 ++-- src/PhpSpreadsheet/Cell/DataValidation.php | 78 +++++------ src/PhpSpreadsheet/Cell/Hyperlink.php | 22 ++-- 5 files changed, 186 insertions(+), 186 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index 5dee411b..05ad5cb8 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -89,24 +89,24 @@ class Cell /** * Create a new Cell. * - * @param mixed $pValue - * @param string $pDataType + * @param mixed $value + * @param string $dataType */ - public function __construct($pValue, $pDataType, Worksheet $pSheet) + public function __construct($value, $dataType, Worksheet $worksheet) { // Initialise cell value - $this->value = $pValue; + $this->value = $value; // Set worksheet cache - $this->parent = $pSheet->getCellCollection(); + $this->parent = $worksheet->getCellCollection(); // Set datatype? - if ($pDataType !== null) { - if ($pDataType == DataType::TYPE_STRING2) { - $pDataType = DataType::TYPE_STRING; + if ($dataType !== null) { + if ($dataType == DataType::TYPE_STRING2) { + $dataType = DataType::TYPE_STRING; } - $this->dataType = $pDataType; - } elseif (!self::getValueBinder()->bindValue($this, $pValue)) { + $this->dataType = $dataType; + } elseif (!self::getValueBinder()->bindValue($this, $value)) { throw new Exception('Value could not be bound to cell.'); } } @@ -170,13 +170,13 @@ class Cell * * Sets the value for a cell, automatically determining the datatype using the value binder * - * @param mixed $pValue Value + * @param mixed $value Value * * @return $this */ - public function setValue($pValue) + public function setValue($value) { - if (!self::getValueBinder()->bindValue($this, $pValue)) { + if (!self::getValueBinder()->bindValue($this, $value)) { throw new Exception('Value could not be bound to cell.'); } @@ -186,56 +186,56 @@ class Cell /** * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder). * - * @param mixed $pValue Value - * @param string $pDataType Explicit data type, see DataType::TYPE_* + * @param mixed $value Value + * @param string $dataType Explicit data type, see DataType::TYPE_* * * @return Cell */ - public function setValueExplicit($pValue, $pDataType) + public function setValueExplicit($value, $dataType) { // set the value according to data type - switch ($pDataType) { + switch ($dataType) { case DataType::TYPE_NULL: - $this->value = $pValue; + $this->value = $value; break; case DataType::TYPE_STRING2: - $pDataType = DataType::TYPE_STRING; + $dataType = DataType::TYPE_STRING; // no break case DataType::TYPE_STRING: // Synonym for string case DataType::TYPE_INLINE: // Rich text - $this->value = DataType::checkString($pValue); + $this->value = DataType::checkString($value); break; case DataType::TYPE_NUMERIC: - if (is_string($pValue) && !is_numeric($pValue)) { + if (is_string($value) && !is_numeric($value)) { throw new Exception('Invalid numeric value for datatype Numeric'); } - $this->value = 0 + $pValue; + $this->value = 0 + $value; break; case DataType::TYPE_FORMULA: - $this->value = (string) $pValue; + $this->value = (string) $value; break; case DataType::TYPE_BOOL: - $this->value = (bool) $pValue; + $this->value = (bool) $value; break; case DataType::TYPE_ERROR: - $this->value = DataType::checkErrorCode($pValue); + $this->value = DataType::checkErrorCode($value); break; default: - throw new Exception('Invalid datatype: ' . $pDataType); + throw new Exception('Invalid datatype: ' . $dataType); break; } // set the datatype - $this->dataType = $pDataType; + $this->dataType = $dataType; return $this->updateInCollection(); } @@ -289,14 +289,14 @@ class Cell /** * Set old calculated value (cached). * - * @param mixed $pValue Value + * @param mixed $originalValue Value * * @return Cell */ - public function setCalculatedValue($pValue) + public function setCalculatedValue($originalValue) { - if ($pValue !== null) { - $this->calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue; + if ($originalValue !== null) { + $this->calculatedValue = (is_numeric($originalValue)) ? (float) $originalValue : $originalValue; } return $this->updateInCollection(); @@ -330,16 +330,16 @@ class Cell /** * Set cell data type. * - * @param string $pDataType see DataType::TYPE_* + * @param string $dataType see DataType::TYPE_* * * @return Cell */ - public function setDataType($pDataType) + public function setDataType($dataType) { - if ($pDataType == DataType::TYPE_STRING2) { - $pDataType = DataType::TYPE_STRING; + if ($dataType == DataType::TYPE_STRING2) { + $dataType = DataType::TYPE_STRING; } - $this->dataType = $pDataType; + $this->dataType = $dataType; return $this->updateInCollection(); } @@ -385,17 +385,17 @@ class Cell /** * Set Data validation rules. * - * @param DataValidation $pDataValidation + * @param DataValidation $dataValidation * * @return Cell */ - public function setDataValidation(?DataValidation $pDataValidation = null) + public function setDataValidation(?DataValidation $dataValidation = null) { if (!isset($this->parent)) { throw new Exception('Cannot set data validation for cell that is not bound to a worksheet'); } - $this->getWorksheet()->setDataValidation($this->getCoordinate(), $pDataValidation); + $this->getWorksheet()->setDataValidation($this->getCoordinate(), $dataValidation); return $this->updateInCollection(); } @@ -443,17 +443,17 @@ class Cell /** * Set Hyperlink. * - * @param Hyperlink $pHyperlink + * @param Hyperlink $hyperlink * * @return Cell */ - public function setHyperlink(?Hyperlink $pHyperlink = null) + public function setHyperlink(?Hyperlink $hyperlink = null) { if (!isset($this->parent)) { throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet'); } - $this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink); + $this->getWorksheet()->setHyperlink($this->getCoordinate(), $hyperlink); return $this->updateInCollection(); } @@ -547,13 +547,13 @@ class Cell /** * Is cell in a specific range? * - * @param string $pRange Cell range (e.g. A1:A1) + * @param string $range Cell range (e.g. A1:A1) * * @return bool */ - public function isInRange($pRange) + public function isInRange($range) { - [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($pRange); + [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($range); // Translate properties $myColumn = Coordinate::columnIndexFromString($this->getColumn()); @@ -635,13 +635,13 @@ class Cell /** * Set index to cellXf. * - * @param int $pValue + * @param int $indexValue * * @return Cell */ - public function setXfIndex($pValue) + public function setXfIndex($indexValue) { - $this->xfIndex = $pValue; + $this->xfIndex = $indexValue; return $this->updateInCollection(); } @@ -649,13 +649,13 @@ class Cell /** * Set the formula attributes. * - * @param mixed $pAttributes + * @param mixed $attributes * * @return $this */ - public function setFormulaAttributes($pAttributes) + public function setFormulaAttributes($attributes) { - $this->formulaAttributes = $pAttributes; + $this->formulaAttributes = $attributes; return $this; } diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 2afeebe9..8efd8ad7 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -23,86 +23,86 @@ abstract class Coordinate /** * Coordinate from string. * - * @param string $pCoordinateString eg: 'A1' + * @param string $cellAddress eg: 'A1' * * @return string[] Array containing column and row (indexes 0 and 1) */ - public static function coordinateFromString($pCoordinateString) + public static function coordinateFromString($cellAddress) { - if (preg_match('/^([$]?[A-Z]{1,3})([$]?\\d{1,7})$/', $pCoordinateString, $matches)) { + if (preg_match('/^([$]?[A-Z]{1,3})([$]?\\d{1,7})$/', $cellAddress, $matches)) { return [$matches[1], $matches[2]]; - } elseif (self::coordinateIsRange($pCoordinateString)) { + } elseif (self::coordinateIsRange($cellAddress)) { throw new Exception('Cell coordinate string can not be a range of cells'); - } elseif ($pCoordinateString == '') { + } elseif ($cellAddress == '') { throw new Exception('Cell coordinate can not be zero-length string'); } - throw new Exception('Invalid cell coordinate ' . $pCoordinateString); + throw new Exception('Invalid cell coordinate ' . $cellAddress); } /** - * Checks if a coordinate represents a range of cells. + * Checks if a Cell Address represents a range of cells. * - * @param string $coord eg: 'A1' or 'A1:A2' or 'A1:A2,C1:C2' + * @param string $cellAddress eg: 'A1' or 'A1:A2' or 'A1:A2,C1:C2' * * @return bool Whether the coordinate represents a range of cells */ - public static function coordinateIsRange($coord) + public static function coordinateIsRange($cellAddress) { - return (strpos($coord, ':') !== false) || (strpos($coord, ',') !== false); + return (strpos($cellAddress, ':') !== false) || (strpos($cellAddress, ',') !== false); } /** * Make string row, column or cell coordinate absolute. * - * @param string $pCoordinateString e.g. 'A' or '1' or 'A1' + * @param string $cellAddress e.g. 'A' or '1' or 'A1' * Note that this value can be a row or column reference as well as a cell reference * * @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1' */ - public static function absoluteReference($pCoordinateString) + public static function absoluteReference($cellAddress) { - if (self::coordinateIsRange($pCoordinateString)) { + if (self::coordinateIsRange($cellAddress)) { throw new Exception('Cell coordinate string can not be a range of cells'); } // Split out any worksheet name from the reference - [$worksheet, $pCoordinateString] = Worksheet::extractSheetTitle($pCoordinateString, true); + [$worksheet, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true); if ($worksheet > '') { $worksheet .= '!'; } // Create absolute coordinate - if (ctype_digit($pCoordinateString)) { - return $worksheet . '$' . $pCoordinateString; - } elseif (ctype_alpha($pCoordinateString)) { - return $worksheet . '$' . strtoupper($pCoordinateString); + if (ctype_digit($cellAddress)) { + return $worksheet . '$' . $cellAddress; + } elseif (ctype_alpha($cellAddress)) { + return $worksheet . '$' . strtoupper($cellAddress); } - return $worksheet . self::absoluteCoordinate($pCoordinateString); + return $worksheet . self::absoluteCoordinate($cellAddress); } /** * Make string coordinate absolute. * - * @param string $pCoordinateString e.g. 'A1' + * @param string $cellAddress e.g. 'A1' * * @return string Absolute coordinate e.g. '$A$1' */ - public static function absoluteCoordinate($pCoordinateString) + public static function absoluteCoordinate($cellAddress) { - if (self::coordinateIsRange($pCoordinateString)) { + if (self::coordinateIsRange($cellAddress)) { throw new Exception('Cell coordinate string can not be a range of cells'); } // Split out any worksheet name from the coordinate - [$worksheet, $pCoordinateString] = Worksheet::extractSheetTitle($pCoordinateString, true); + [$worksheet, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true); if ($worksheet > '') { $worksheet .= '!'; } // Create absolute coordinate - [$column, $row] = self::coordinateFromString($pCoordinateString); + [$column, $row] = self::coordinateFromString($cellAddress); $column = ltrim($column, '$'); $row = ltrim($row, '$'); @@ -112,20 +112,20 @@ abstract class Coordinate /** * Split range into coordinate strings. * - * @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' + * @param string $range e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' * * @return array Array containing one or more arrays containing one or two coordinate strings * e.g. ['B4','D9'] or [['B4','D9'], ['H2','O11']] * or ['B4'] */ - public static function splitRange($pRange) + public static function splitRange($range) { // Ensure $pRange is a valid range - if (empty($pRange)) { - $pRange = self::DEFAULT_RANGE; + if (empty($range)) { + $range = self::DEFAULT_RANGE; } - $exploded = explode(',', $pRange); + $exploded = explode(',', $range); $counter = count($exploded); for ($i = 0; $i < $counter; ++$i) { $exploded[$i] = explode(':', $exploded[$i]); @@ -137,49 +137,49 @@ abstract class Coordinate /** * Build range from coordinate strings. * - * @param array $pRange Array containg one or more arrays containing one or two coordinate strings + * @param array $range Array containg one or more arrays containing one or two coordinate strings * * @return string String representation of $pRange */ - public static function buildRange(array $pRange) + public static function buildRange(array $range) { // Verify range - if (empty($pRange) || !is_array($pRange[0])) { + if (empty($range) || !is_array($range[0])) { throw new Exception('Range does not contain any information'); } // Build range - $counter = count($pRange); + $counter = count($range); for ($i = 0; $i < $counter; ++$i) { - $pRange[$i] = implode(':', $pRange[$i]); + $range[$i] = implode(':', $range[$i]); } - return implode(',', $pRange); + return implode(',', $range); } /** * Calculate range boundaries. * - * @param string $pRange Cell range (e.g. A1:A1) + * @param string $range Cell range (e.g. A1:A1) * * @return array Range coordinates [Start Cell, End Cell] * where Start Cell and End Cell are arrays (Column Number, Row Number) */ - public static function rangeBoundaries($pRange) + public static function rangeBoundaries($range) { // Ensure $pRange is a valid range - if (empty($pRange)) { - $pRange = self::DEFAULT_RANGE; + if (empty($range)) { + $range = self::DEFAULT_RANGE; } // Uppercase coordinate - $pRange = strtoupper($pRange); + $range = strtoupper($range); // Extract range - if (strpos($pRange, ':') === false) { - $rangeA = $rangeB = $pRange; + if (strpos($range, ':') === false) { + $rangeA = $rangeB = $range; } else { - [$rangeA, $rangeB] = explode(':', $pRange); + [$rangeA, $rangeB] = explode(':', $range); } // Calculate range outer borders @@ -196,14 +196,14 @@ abstract class Coordinate /** * Calculate range dimension. * - * @param string $pRange Cell range (e.g. A1:A1) + * @param string $range Cell range (e.g. A1:A1) * * @return array Range dimension (width, height) */ - public static function rangeDimension($pRange) + public static function rangeDimension($range) { // Calculate range outer borders - [$rangeStart, $rangeEnd] = self::rangeBoundaries($pRange); + [$rangeStart, $rangeEnd] = self::rangeBoundaries($range); return [($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1)]; } @@ -211,26 +211,26 @@ abstract class Coordinate /** * Calculate range boundaries. * - * @param string $pRange Cell range (e.g. A1:A1) + * @param string $range Cell range (e.g. A1:A1) * * @return array Range coordinates [Start Cell, End Cell] * where Start Cell and End Cell are arrays [Column ID, Row Number] */ - public static function getRangeBoundaries($pRange) + public static function getRangeBoundaries($range) { // Ensure $pRange is a valid range - if (empty($pRange)) { - $pRange = self::DEFAULT_RANGE; + if (empty($range)) { + $range = self::DEFAULT_RANGE; } // Uppercase coordinate - $pRange = strtoupper($pRange); + $range = strtoupper($range); // Extract range - if (strpos($pRange, ':') === false) { - $rangeA = $rangeB = $pRange; + if (strpos($range, ':') === false) { + $rangeA = $rangeB = $range; } else { - [$rangeA, $rangeB] = explode(':', $pRange); + [$rangeA, $rangeB] = explode(':', $range); } return [self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)]; @@ -239,19 +239,19 @@ abstract class Coordinate /** * Column index from string. * - * @param string $pString eg 'A' + * @param string $columnAddress eg 'A' * * @return int Column index (A = 1) */ - public static function columnIndexFromString($pString) + public static function columnIndexFromString($columnAddress) { // Using a lookup cache adds a slight memory overhead, but boosts speed // caching using a static within the method is faster than a class static, // though it's additional memory overhead static $indexCache = []; - if (isset($indexCache[$pString])) { - return $indexCache[$pString]; + if (isset($indexCache[$columnAddress])) { + return $indexCache[$columnAddress]; } // It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord() // and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant @@ -265,23 +265,23 @@ abstract class Coordinate // We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString // for improved performance - if (isset($pString[0])) { - if (!isset($pString[1])) { - $indexCache[$pString] = $columnLookup[$pString]; + if (isset($columnAddress[0])) { + if (!isset($columnAddress[1])) { + $indexCache[$columnAddress] = $columnLookup[$columnAddress]; - return $indexCache[$pString]; - } elseif (!isset($pString[2])) { - $indexCache[$pString] = $columnLookup[$pString[0]] * 26 + $columnLookup[$pString[1]]; + return $indexCache[$columnAddress]; + } elseif (!isset($columnAddress[2])) { + $indexCache[$columnAddress] = $columnLookup[$columnAddress[0]] * 26 + $columnLookup[$columnAddress[1]]; - return $indexCache[$pString]; - } elseif (!isset($pString[3])) { - $indexCache[$pString] = $columnLookup[$pString[0]] * 676 + $columnLookup[$pString[1]] * 26 + $columnLookup[$pString[2]]; + return $indexCache[$columnAddress]; + } elseif (!isset($columnAddress[3])) { + $indexCache[$columnAddress] = $columnLookup[$columnAddress[0]] * 676 + $columnLookup[$columnAddress[1]] * 26 + $columnLookup[$columnAddress[2]]; - return $indexCache[$pString]; + return $indexCache[$columnAddress]; } } - throw new Exception('Column string index can not be ' . ((isset($pString[0])) ? 'longer than 3 characters' : 'empty')); + throw new Exception('Column string index can not be ' . ((isset($columnAddress[0])) ? 'longer than 3 characters' : 'empty')); } /** @@ -435,16 +435,16 @@ abstract class Coordinate * * [ 'A1:A3' => 'x', 'A4' => 'y' ] * - * @param array $pCoordCollection associative array mapping coordinates to values + * @param array $coordinateCollection associative array mapping coordinates to values * * @return array associative array mapping coordinate ranges to valuea */ - public static function mergeRangesInCollection(array $pCoordCollection) + public static function mergeRangesInCollection(array $coordinateCollection) { $hashedValues = []; $mergedCoordCollection = []; - foreach ($pCoordCollection as $coord => $value) { + foreach ($coordinateCollection as $coord => $value) { if (self::coordinateIsRange($coord)) { $mergedCoordCollection[$coord] = $value; diff --git a/src/PhpSpreadsheet/Cell/DataType.php b/src/PhpSpreadsheet/Cell/DataType.php index ba035791..cee3e1e5 100644 --- a/src/PhpSpreadsheet/Cell/DataType.php +++ b/src/PhpSpreadsheet/Cell/DataType.php @@ -45,41 +45,41 @@ class DataType /** * Check a string that it satisfies Excel requirements. * - * @param null|RichText|string $pValue Value to sanitize to an Excel string + * @param null|RichText|string $textValue Value to sanitize to an Excel string * * @return null|RichText|string Sanitized value */ - public static function checkString($pValue) + public static function checkString($textValue) { - if ($pValue instanceof RichText) { + if ($textValue instanceof RichText) { // TODO: Sanitize Rich-Text string (max. character count is 32,767) - return $pValue; + return $textValue; } // string must never be longer than 32,767 characters, truncate if necessary - $pValue = StringHelper::substring($pValue, 0, 32767); + $textValue = StringHelper::substring($textValue, 0, 32767); // we require that newline is represented as "\n" in core, not as "\r\n" or "\r" - $pValue = str_replace(["\r\n", "\r"], "\n", $pValue); + $textValue = str_replace(["\r\n", "\r"], "\n", $textValue); - return $pValue; + return $textValue; } /** * Check a value that it is a valid error code. * - * @param mixed $pValue Value to sanitize to an Excel error code + * @param mixed $value Value to sanitize to an Excel error code * * @return string Sanitized value */ - public static function checkErrorCode($pValue) + public static function checkErrorCode($value) { - $pValue = (string) $pValue; + $value = (string) $value; - if (!isset(self::$errorCodes[$pValue])) { - $pValue = '#NULL!'; + if (!isset(self::$errorCodes[$value])) { + $value = '#NULL!'; } - return $pValue; + return $value; } } diff --git a/src/PhpSpreadsheet/Cell/DataValidation.php b/src/PhpSpreadsheet/Cell/DataValidation.php index dfeb024c..f4a712e0 100644 --- a/src/PhpSpreadsheet/Cell/DataValidation.php +++ b/src/PhpSpreadsheet/Cell/DataValidation.php @@ -140,13 +140,13 @@ class DataValidation /** * Set Formula 1. * - * @param string $value + * @param string $formula * * @return $this */ - public function setFormula1($value) + public function setFormula1($formula) { - $this->formula1 = $value; + $this->formula1 = $formula; return $this; } @@ -164,13 +164,13 @@ class DataValidation /** * Set Formula 2. * - * @param string $value + * @param string $formula * * @return $this */ - public function setFormula2($value) + public function setFormula2($formula) { - $this->formula2 = $value; + $this->formula2 = $formula; return $this; } @@ -188,13 +188,13 @@ class DataValidation /** * Set Type. * - * @param string $value + * @param string $type * * @return $this */ - public function setType($value) + public function setType($type) { - $this->type = $value; + $this->type = $type; return $this; } @@ -212,13 +212,13 @@ class DataValidation /** * Set Error style. * - * @param string $value see self::STYLE_* + * @param string $errorStye see self::STYLE_* * * @return $this */ - public function setErrorStyle($value) + public function setErrorStyle($errorStye) { - $this->errorStyle = $value; + $this->errorStyle = $errorStye; return $this; } @@ -236,13 +236,13 @@ class DataValidation /** * Set Operator. * - * @param string $value + * @param string $operator * * @return $this */ - public function setOperator($value) + public function setOperator($operator) { - $this->operator = $value; + $this->operator = $operator; return $this; } @@ -260,13 +260,13 @@ class DataValidation /** * Set Allow Blank. * - * @param bool $value + * @param bool $allowBlank * * @return $this */ - public function setAllowBlank($value) + public function setAllowBlank($allowBlank) { - $this->allowBlank = $value; + $this->allowBlank = $allowBlank; return $this; } @@ -284,13 +284,13 @@ class DataValidation /** * Set Show DropDown. * - * @param bool $value + * @param bool $showDropDown * * @return $this */ - public function setShowDropDown($value) + public function setShowDropDown($showDropDown) { - $this->showDropDown = $value; + $this->showDropDown = $showDropDown; return $this; } @@ -308,13 +308,13 @@ class DataValidation /** * Set Show InputMessage. * - * @param bool $value + * @param bool $showInputMessage * * @return $this */ - public function setShowInputMessage($value) + public function setShowInputMessage($showInputMessage) { - $this->showInputMessage = $value; + $this->showInputMessage = $showInputMessage; return $this; } @@ -332,13 +332,13 @@ class DataValidation /** * Set Show ErrorMessage. * - * @param bool $value + * @param bool $showErrorMessage * * @return $this */ - public function setShowErrorMessage($value) + public function setShowErrorMessage($showErrorMessage) { - $this->showErrorMessage = $value; + $this->showErrorMessage = $showErrorMessage; return $this; } @@ -356,13 +356,13 @@ class DataValidation /** * Set Error title. * - * @param string $value + * @param string $errorTitle * * @return $this */ - public function setErrorTitle($value) + public function setErrorTitle($errorTitle) { - $this->errorTitle = $value; + $this->errorTitle = $errorTitle; return $this; } @@ -380,13 +380,13 @@ class DataValidation /** * Set Error. * - * @param string $value + * @param string $error * * @return $this */ - public function setError($value) + public function setError($error) { - $this->error = $value; + $this->error = $error; return $this; } @@ -404,13 +404,13 @@ class DataValidation /** * Set Prompt title. * - * @param string $value + * @param string $promptTitle * * @return $this */ - public function setPromptTitle($value) + public function setPromptTitle($promptTitle) { - $this->promptTitle = $value; + $this->promptTitle = $promptTitle; return $this; } @@ -428,13 +428,13 @@ class DataValidation /** * Set Prompt. * - * @param string $value + * @param string $prompt * * @return $this */ - public function setPrompt($value) + public function setPrompt($prompt) { - $this->prompt = $value; + $this->prompt = $prompt; return $this; } diff --git a/src/PhpSpreadsheet/Cell/Hyperlink.php b/src/PhpSpreadsheet/Cell/Hyperlink.php index 003d5101..ffdcbacd 100644 --- a/src/PhpSpreadsheet/Cell/Hyperlink.php +++ b/src/PhpSpreadsheet/Cell/Hyperlink.php @@ -21,14 +21,14 @@ class Hyperlink /** * Create a new Hyperlink. * - * @param string $pUrl Url to link the cell to - * @param string $pTooltip Tooltip to display on the hyperlink + * @param string $url Url to link the cell to + * @param string $tooltip Tooltip to display on the hyperlink */ - public function __construct($pUrl = '', $pTooltip = '') + public function __construct($url = '', $tooltip = '') { // Initialise member variables - $this->url = $pUrl; - $this->tooltip = $pTooltip; + $this->url = $url; + $this->tooltip = $tooltip; } /** @@ -44,13 +44,13 @@ class Hyperlink /** * Set URL. * - * @param string $value + * @param string $url * * @return $this */ - public function setUrl($value) + public function setUrl($url) { - $this->url = $value; + $this->url = $url; return $this; } @@ -68,13 +68,13 @@ class Hyperlink /** * Set tooltip. * - * @param string $value + * @param string $tooltip * * @return $this */ - public function setTooltip($value) + public function setTooltip($tooltip) { - $this->tooltip = $value; + $this->tooltip = $tooltip; return $this; } From b12cebe1f5c37f498b4da66e5848f9964b3d1b4e Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 20:43:42 +0100 Subject: [PATCH 21/41] Sane argument names in the Chart classes --- src/PhpSpreadsheet/Chart/Axis.php | 156 +++++++++--------- src/PhpSpreadsheet/Chart/Chart.php | 6 +- src/PhpSpreadsheet/Chart/GridLines.php | 152 ++++++++--------- src/PhpSpreadsheet/Chart/Layout.php | 84 +++++----- src/PhpSpreadsheet/Chart/Properties.php | 12 +- src/PhpSpreadsheet/Collection/Cells.php | 48 +++--- .../Collection/CellsFactory.php | 6 +- 7 files changed, 232 insertions(+), 232 deletions(-) diff --git a/src/PhpSpreadsheet/Chart/Axis.php b/src/PhpSpreadsheet/Chart/Axis.php index 7995c3b3..1f5ae152 100644 --- a/src/PhpSpreadsheet/Chart/Axis.php +++ b/src/PhpSpreadsheet/Chart/Axis.php @@ -167,30 +167,30 @@ class Axis extends Properties /** * Set Axis Options Properties. * - * @param string $axis_labels - * @param string $horizontal_crosses_value - * @param string $horizontal_crosses - * @param string $axis_orientation - * @param string $major_tmt - * @param string $minor_tmt + * @param string $axisLabels + * @param string $horizontalCrossesValue + * @param string $horizontalCrosses + * @param string $axisOrientation + * @param string $majorTmt + * @param string $minorTmt * @param string $minimum * @param string $maximum - * @param string $major_unit - * @param string $minor_unit + * @param string $majorUnit + * @param string $minorUnit */ - public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value = null, $horizontal_crosses = null, $axis_orientation = null, $major_tmt = null, $minor_tmt = null, $minimum = null, $maximum = null, $major_unit = null, $minor_unit = null): void + public function setAxisOptionsProperties($axisLabels, $horizontalCrossesValue = null, $horizontalCrosses = null, $axisOrientation = null, $majorTmt = null, $minorTmt = null, $minimum = null, $maximum = null, $majorUnit = null, $minorUnit = null): void { - $this->axisOptions['axis_labels'] = (string) $axis_labels; - ($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null; - ($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null; - ($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null; - ($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null; - ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; - ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null; + $this->axisOptions['axis_labels'] = (string) $axisLabels; + ($horizontalCrossesValue !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontalCrossesValue : null; + ($horizontalCrosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontalCrosses : null; + ($axisOrientation !== null) ? $this->axisOptions['orientation'] = (string) $axisOrientation : null; + ($majorTmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $majorTmt : null; + ($minorTmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minorTmt : null; + ($minorTmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minorTmt : null; ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null; ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null; - ($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null; - ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null; + ($majorUnit !== null) ? $this->axisOptions['major_unit'] = (string) $majorUnit : null; + ($minorUnit !== null) ? $this->axisOptions['minor_unit'] = (string) $minorUnit : null; } /** @@ -220,11 +220,11 @@ class Axis extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $AlphaType */ - public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void + public function setFillParameters($color, $alpha = 0, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void { - $this->fillProperties = $this->setColorProperties($color, $alpha, $type); + $this->fillProperties = $this->setColorProperties($color, $alpha, $AlphaType); } /** @@ -232,11 +232,11 @@ class Axis extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $alphaType */ - public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void + public function setLineParameters($color, $alpha = 0, $alphaType = self::EXCEL_COLOR_TYPE_ARGB): void { - $this->lineProperties = $this->setColorProperties($color, $alpha, $type); + $this->lineProperties = $this->setColorProperties($color, $alpha, $alphaType); } /** @@ -266,27 +266,27 @@ class Axis extends Properties /** * Set Line Style Properties. * - * @param float $line_width - * @param string $compound_type - * @param string $dash_type - * @param string $cap_type - * @param string $join_type - * @param string $head_arrow_type - * @param string $head_arrow_size - * @param string $end_arrow_type - * @param string $end_arrow_size + * @param float $lineWidth + * @param string $compoundType + * @param string $dashType + * @param string $capType + * @param string $joinType + * @param string $headArrowType + * @param string $headArrowSize + * @param string $endArrowType + * @param string $endArrowSize */ - public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null): void + public function setLineStyleProperties($lineWidth = null, $compoundType = null, $dashType = null, $capType = null, $joinType = null, $headArrowType = null, $headArrowSize = null, $endArrowType = null, $endArrowSize = null): void { - ($line_width !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null; - ($compound_type !== null) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null; - ($dash_type !== null) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null; - ($cap_type !== null) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null; - ($join_type !== null) ? $this->lineStyleProperties['join'] = (string) $join_type : null; - ($head_arrow_type !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null; - ($head_arrow_size !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null; - ($end_arrow_type !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null; - ($end_arrow_size !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null; + ($lineWidth !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $lineWidth) : null; + ($compoundType !== null) ? $this->lineStyleProperties['compound'] = (string) $compoundType : null; + ($dashType !== null) ? $this->lineStyleProperties['dash'] = (string) $dashType : null; + ($capType !== null) ? $this->lineStyleProperties['cap'] = (string) $capType : null; + ($joinType !== null) ? $this->lineStyleProperties['join'] = (string) $joinType : null; + ($headArrowType !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $headArrowType : null; + ($headArrowSize !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $headArrowSize : null; + ($endArrowType !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $endArrowType : null; + ($endArrowSize !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $endArrowSize : null; } /** @@ -328,38 +328,38 @@ class Axis extends Properties /** * Set Shadow Properties. * - * @param int $sh_presets - * @param string $sh_color_value - * @param string $sh_color_type - * @param string $sh_color_alpha - * @param float $sh_blur - * @param int $sh_angle - * @param float $sh_distance + * @param int $shadowPresets + * @param string $colorValue + * @param string $colorType + * @param string $colorAlpha + * @param float $blur + * @param int $angle + * @param float $distance */ - public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null): void + public function setShadowProperties($shadowPresets, $colorValue = null, $colorType = null, $colorAlpha = null, $blur = null, $angle = null, $distance = null): void { - $this->setShadowPresetsProperties((int) $sh_presets) + $this->setShadowPresetsProperties((int) $shadowPresets) ->setShadowColor( - $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, - $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha, - $sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type + $colorValue === null ? $this->shadowProperties['color']['value'] : $colorValue, + $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $colorAlpha, + $colorType === null ? $this->shadowProperties['color']['type'] : $colorType ) - ->setShadowBlur($sh_blur) - ->setShadowAngle($sh_angle) - ->setShadowDistance($sh_distance); + ->setShadowBlur($blur) + ->setShadowAngle($angle) + ->setShadowDistance($distance); } /** * Set Shadow Color. * - * @param int $shadow_presets + * @param int $presets * * @return $this */ - private function setShadowPresetsProperties($shadow_presets) + private function setShadowPresetsProperties($presets) { - $this->shadowProperties['presets'] = $shadow_presets; - $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); + $this->shadowProperties['presets'] = $presets; + $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets)); return $this; } @@ -371,17 +371,17 @@ class Axis extends Properties * * @return $this */ - private function setShadowProperiesMapValues(array $properties_map, &$reference = null) + private function setShadowPropertiesMapValues(array $propertiesMap, &$reference = null) { $base_reference = $reference; - foreach ($properties_map as $property_key => $property_val) { + foreach ($propertiesMap as $property_key => $property_val) { if (is_array($property_val)) { if ($reference === null) { $reference = &$this->shadowProperties[$property_key]; } else { $reference = &$reference[$property_key]; } - $this->setShadowProperiesMapValues($property_val, $reference); + $this->setShadowPropertiesMapValues($property_val, $reference); } else { if ($base_reference === null) { $this->shadowProperties[$property_key] = $property_val; @@ -399,13 +399,13 @@ class Axis extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $alphaType * * @return $this */ - private function setShadowColor($color, $alpha, $type) + private function setShadowColor($color, $alpha, $alphaType) { - $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $type); + $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $alphaType); return $this; } @@ -474,17 +474,17 @@ class Axis extends Properties * Set Glow Properties. * * @param float $size - * @param string $color_value - * @param int $color_alpha - * @param string $color_type + * @param string $colorValue + * @param int $colorAlpha + * @param string $colorType */ - public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null): void + public function setGlowProperties($size, $colorValue = null, $colorAlpha = null, $colorType = null): void { $this->setGlowSize($size) ->setGlowColor( - $color_value === null ? $this->glowProperties['color']['value'] : $color_value, - $color_alpha === null ? (int) $this->glowProperties['color']['alpha'] : $color_alpha, - $color_type === null ? $this->glowProperties['color']['type'] : $color_type + $colorValue === null ? $this->glowProperties['color']['value'] : $colorValue, + $colorAlpha === null ? (int) $this->glowProperties['color']['alpha'] : $colorAlpha, + $colorType === null ? $this->glowProperties['color']['type'] : $colorType ); } @@ -521,13 +521,13 @@ class Axis extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $colorType * * @return $this */ - private function setGlowColor($color, $alpha, $type) + private function setGlowColor($color, $alpha, $colorType) { - $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $type); + $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $colorType); return $this; } diff --git a/src/PhpSpreadsheet/Chart/Chart.php b/src/PhpSpreadsheet/Chart/Chart.php index 20eb2aee..b6093c45 100644 --- a/src/PhpSpreadsheet/Chart/Chart.php +++ b/src/PhpSpreadsheet/Chart/Chart.php @@ -186,13 +186,13 @@ class Chart /** * Set Worksheet. * - * @param Worksheet $pValue + * @param Worksheet $worksheet * * @return $this */ - public function setWorksheet(?Worksheet $pValue = null) + public function setWorksheet(?Worksheet $worksheet = null) { - $this->worksheet = $pValue; + $this->worksheet = $worksheet; return $this; } diff --git a/src/PhpSpreadsheet/Chart/GridLines.php b/src/PhpSpreadsheet/Chart/GridLines.php index 2e424bc2..ca9ed555 100644 --- a/src/PhpSpreadsheet/Chart/GridLines.php +++ b/src/PhpSpreadsheet/Chart/GridLines.php @@ -105,73 +105,73 @@ class GridLines extends Properties * * @param string $value * @param int $alpha - * @param string $type + * @param string $colorType */ - public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD): void + public function setLineColorProperties($value, $alpha = 0, $colorType = self::EXCEL_COLOR_TYPE_STANDARD): void { $this->activateObject() ->lineProperties['color'] = $this->setColorProperties( $value, $alpha, - $type + $colorType ); } /** * Set Line Color Properties. * - * @param float $line_width - * @param string $compound_type - * @param string $dash_type - * @param string $cap_type - * @param string $join_type - * @param string $head_arrow_type - * @param string $head_arrow_size - * @param string $end_arrow_type - * @param string $end_arrow_size + * @param float $lineWidth + * @param string $compoundType + * @param string $dashType + * @param string $capType + * @param string $joinType + * @param string $headArrowType + * @param string $headArrowSize + * @param string $endArrowType + * @param string $endArrowSize */ - public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null): void + public function setLineStyleProperties($lineWidth = null, $compoundType = null, $dashType = null, $capType = null, $joinType = null, $headArrowType = null, $headArrowSize = null, $endArrowType = null, $endArrowSize = null): void { $this->activateObject(); - ($line_width !== null) - ? $this->lineProperties['style']['width'] = $this->getExcelPointsWidth((float) $line_width) + ($lineWidth !== null) + ? $this->lineProperties['style']['width'] = $this->getExcelPointsWidth((float) $lineWidth) : null; - ($compound_type !== null) - ? $this->lineProperties['style']['compound'] = (string) $compound_type + ($compoundType !== null) + ? $this->lineProperties['style']['compound'] = (string) $compoundType : null; - ($dash_type !== null) - ? $this->lineProperties['style']['dash'] = (string) $dash_type + ($dashType !== null) + ? $this->lineProperties['style']['dash'] = (string) $dashType : null; - ($cap_type !== null) - ? $this->lineProperties['style']['cap'] = (string) $cap_type + ($capType !== null) + ? $this->lineProperties['style']['cap'] = (string) $capType : null; - ($join_type !== null) - ? $this->lineProperties['style']['join'] = (string) $join_type + ($joinType !== null) + ? $this->lineProperties['style']['join'] = (string) $joinType : null; - ($head_arrow_type !== null) - ? $this->lineProperties['style']['arrow']['head']['type'] = (string) $head_arrow_type + ($headArrowType !== null) + ? $this->lineProperties['style']['arrow']['head']['type'] = (string) $headArrowType : null; - ($head_arrow_size !== null) - ? $this->lineProperties['style']['arrow']['head']['size'] = (string) $head_arrow_size + ($headArrowSize !== null) + ? $this->lineProperties['style']['arrow']['head']['size'] = (string) $headArrowSize : null; - ($end_arrow_type !== null) - ? $this->lineProperties['style']['arrow']['end']['type'] = (string) $end_arrow_type + ($endArrowType !== null) + ? $this->lineProperties['style']['arrow']['end']['type'] = (string) $endArrowType : null; - ($end_arrow_size !== null) - ? $this->lineProperties['style']['arrow']['end']['size'] = (string) $end_arrow_size + ($endArrowSize !== null) + ? $this->lineProperties['style']['arrow']['end']['size'] = (string) $endArrowSize : null; } /** * Get Line Color Property. * - * @param string $parameter + * @param string $propertyName * * @return string */ - public function getLineColorProperty($parameter) + public function getLineColorProperty($propertyName) { - return $this->lineProperties['color'][$parameter]; + return $this->lineProperties['color'][$propertyName]; } /** @@ -190,28 +190,28 @@ class GridLines extends Properties * Set Glow Properties. * * @param float $size - * @param string $color_value - * @param int $color_alpha - * @param string $color_type + * @param string $colorValue + * @param int $colorAlpha + * @param string $colorType */ - public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null): void + public function setGlowProperties($size, $colorValue = null, $colorAlpha = null, $colorType = null): void { $this ->activateObject() ->setGlowSize($size) - ->setGlowColor($color_value, $color_alpha, $color_type); + ->setGlowColor($colorValue, $colorAlpha, $colorType); } /** * Get Glow Color Property. * - * @param string $property + * @param string $propertyName * * @return string */ - public function getGlowColor($property) + public function getGlowColor($propertyName) { - return $this->glowProperties['color'][$property]; + return $this->glowProperties['color'][$propertyName]; } /** @@ -243,11 +243,11 @@ class GridLines extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $colorType * * @return $this */ - private function setGlowColor($color, $alpha, $type) + private function setGlowColor($color, $alpha, $colorType) { if ($color !== null) { $this->glowProperties['color']['value'] = (string) $color; @@ -255,8 +255,8 @@ class GridLines extends Properties if ($alpha !== null) { $this->glowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); } - if ($type !== null) { - $this->glowProperties['color']['type'] = (string) $type; + if ($colorType !== null) { + $this->glowProperties['color']['type'] = (string) $colorType; } return $this; @@ -265,52 +265,52 @@ class GridLines extends Properties /** * Get Line Style Arrow Parameters. * - * @param string $arrow_selector - * @param string $property_selector + * @param string $arrowSelector + * @param string $propertySelector * * @return string */ - public function getLineStyleArrowParameters($arrow_selector, $property_selector) + public function getLineStyleArrowParameters($arrowSelector, $propertySelector) { - return $this->getLineStyleArrowSize($this->lineProperties['style']['arrow'][$arrow_selector]['size'], $property_selector); + return $this->getLineStyleArrowSize($this->lineProperties['style']['arrow'][$arrowSelector]['size'], $propertySelector); } /** * Set Shadow Properties. * - * @param int $sh_presets - * @param string $sh_color_value - * @param string $sh_color_type - * @param int $sh_color_alpha - * @param string $sh_blur - * @param int $sh_angle - * @param float $sh_distance + * @param int $presets + * @param string $colorValue + * @param string $colorType + * @param int $colorAlpha + * @param string $blur + * @param int $angle + * @param float $distance */ - public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null): void + public function setShadowProperties($presets, $colorValue = null, $colorType = null, $colorAlpha = null, $blur = null, $angle = null, $distance = null): void { $this->activateObject() - ->setShadowPresetsProperties((int) $sh_presets) + ->setShadowPresetsProperties((int) $presets) ->setShadowColor( - $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, - $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha), - $sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type + $colorValue === null ? $this->shadowProperties['color']['value'] : $colorValue, + $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha), + $colorType === null ? $this->shadowProperties['color']['type'] : $colorType ) - ->setShadowBlur($sh_blur) - ->setShadowAngle($sh_angle) - ->setShadowDistance($sh_distance); + ->setShadowBlur($blur) + ->setShadowAngle($angle) + ->setShadowDistance($distance); } /** * Set Shadow Presets Properties. * - * @param int $shadow_presets + * @param int $presets * * @return $this */ - private function setShadowPresetsProperties($shadow_presets) + private function setShadowPresetsProperties($presets) { - $this->shadowProperties['presets'] = $shadow_presets; - $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); + $this->shadowProperties['presets'] = $presets; + $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets)); return $this; } @@ -322,17 +322,17 @@ class GridLines extends Properties * * @return $this */ - private function setShadowProperiesMapValues(array $properties_map, &$reference = null) + private function setShadowPropertiesMapValues(array $propertiesMap, &$reference = null) { $base_reference = $reference; - foreach ($properties_map as $property_key => $property_val) { + foreach ($propertiesMap as $property_key => $property_val) { if (is_array($property_val)) { if ($reference === null) { $reference = &$this->shadowProperties[$property_key]; } else { $reference = &$reference[$property_key]; } - $this->setShadowProperiesMapValues($property_val, $reference); + $this->setShadowPropertiesMapValues($property_val, $reference); } else { if ($base_reference === null) { $this->shadowProperties[$property_key] = $property_val; @@ -350,11 +350,11 @@ class GridLines extends Properties * * @param string $color * @param int $alpha - * @param string $type + * @param string $colorType * * @return $this */ - private function setShadowColor($color, $alpha, $type) + private function setShadowColor($color, $alpha, $colorType) { if ($color !== null) { $this->shadowProperties['color']['value'] = (string) $color; @@ -362,8 +362,8 @@ class GridLines extends Properties if ($alpha !== null) { $this->shadowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); } - if ($type !== null) { - $this->shadowProperties['color']['type'] = (string) $type; + if ($colorType !== null) { + $this->shadowProperties['color']['type'] = (string) $colorType; } return $this; diff --git a/src/PhpSpreadsheet/Chart/Layout.php b/src/PhpSpreadsheet/Chart/Layout.php index 51c8995b..cea96557 100644 --- a/src/PhpSpreadsheet/Chart/Layout.php +++ b/src/PhpSpreadsheet/Chart/Layout.php @@ -149,13 +149,13 @@ class Layout /** * Set Layout Target. * - * @param string $value + * @param string $target * * @return $this */ - public function setLayoutTarget($value) + public function setLayoutTarget($target) { - $this->layoutTarget = $value; + $this->layoutTarget = $target; return $this; } @@ -173,13 +173,13 @@ class Layout /** * Set X-Mode. * - * @param string $value + * @param string $mode * * @return $this */ - public function setXMode($value) + public function setXMode($mode) { - $this->xMode = (string) $value; + $this->xMode = (string) $mode; return $this; } @@ -197,13 +197,13 @@ class Layout /** * Set Y-Mode. * - * @param string $value + * @param string $mode * * @return $this */ - public function setYMode($value) + public function setYMode($mode) { - $this->yMode = (string) $value; + $this->yMode = (string) $mode; return $this; } @@ -221,13 +221,13 @@ class Layout /** * Set X-Position. * - * @param float $value + * @param float $position * * @return $this */ - public function setXPosition($value) + public function setXPosition($position) { - $this->xPos = (float) $value; + $this->xPos = (float) $position; return $this; } @@ -245,13 +245,13 @@ class Layout /** * Set Y-Position. * - * @param float $value + * @param float $position * * @return $this */ - public function setYPosition($value) + public function setYPosition($position) { - $this->yPos = (float) $value; + $this->yPos = (float) $position; return $this; } @@ -269,13 +269,13 @@ class Layout /** * Set Width. * - * @param float $value + * @param float $width * * @return $this */ - public function setWidth($value) + public function setWidth($width) { - $this->width = $value; + $this->width = $width; return $this; } @@ -293,13 +293,13 @@ class Layout /** * Set Height. * - * @param float $value + * @param float $height * * @return $this */ - public function setHeight($value) + public function setHeight($height) { - $this->height = $value; + $this->height = $height; return $this; } @@ -318,13 +318,13 @@ class Layout * Set show legend key * Specifies that legend keys should be shown in data labels. * - * @param bool $value Show legend key + * @param bool $showLegendKey Show legend key * * @return $this */ - public function setShowLegendKey($value) + public function setShowLegendKey($showLegendKey) { - $this->showLegendKey = $value; + $this->showLegendKey = $showLegendKey; return $this; } @@ -343,13 +343,13 @@ class Layout * Set show val * Specifies that the value should be shown in data labels. * - * @param bool $value Show val + * @param bool $showDataLabelValues Show val * * @return $this */ - public function setShowVal($value) + public function setShowVal($showDataLabelValues) { - $this->showVal = $value; + $this->showVal = $showDataLabelValues; return $this; } @@ -368,13 +368,13 @@ class Layout * Set show cat name * Specifies that the category name should be shown in data labels. * - * @param bool $value Show cat name + * @param bool $showCategoryName Show cat name * * @return $this */ - public function setShowCatName($value) + public function setShowCatName($showCategoryName) { - $this->showCatName = $value; + $this->showCatName = $showCategoryName; return $this; } @@ -393,13 +393,13 @@ class Layout * Set show ser name * Specifies that the series name should be shown in data labels. * - * @param bool $value Show series name + * @param bool $showSeriesName Show series name * * @return $this */ - public function setShowSerName($value) + public function setShowSerName($showSeriesName) { - $this->showSerName = $value; + $this->showSerName = $showSeriesName; return $this; } @@ -418,13 +418,13 @@ class Layout * Set show percentage * Specifies that the percentage should be shown in data labels. * - * @param bool $value Show percentage + * @param bool $showPercentage Show percentage * * @return $this */ - public function setShowPercent($value) + public function setShowPercent($showPercentage) { - $this->showPercent = $value; + $this->showPercent = $showPercentage; return $this; } @@ -443,13 +443,13 @@ class Layout * Set show bubble size * Specifies that the bubble size should be shown in data labels. * - * @param bool $value Show bubble size + * @param bool $showBubbleSize Show bubble size * * @return $this */ - public function setShowBubbleSize($value) + public function setShowBubbleSize($showBubbleSize) { - $this->showBubbleSize = $value; + $this->showBubbleSize = $showBubbleSize; return $this; } @@ -468,13 +468,13 @@ class Layout * Set show leader lines * Specifies that leader lines should be shown in data labels. * - * @param bool $value Show leader lines + * @param bool $showLeaderLines Show leader lines * * @return $this */ - public function setShowLeaderLines($value) + public function setShowLeaderLines($showLeaderLines) { - $this->showLeaderLines = $value; + $this->showLeaderLines = $showLeaderLines; return $this; } diff --git a/src/PhpSpreadsheet/Chart/Properties.php b/src/PhpSpreadsheet/Chart/Properties.php index 98095f0d..ef22fb52 100644 --- a/src/PhpSpreadsheet/Chart/Properties.php +++ b/src/PhpSpreadsheet/Chart/Properties.php @@ -135,16 +135,16 @@ abstract class Properties return (string) 100 - $alpha . '000'; } - protected function setColorProperties($color, $alpha, $type) + protected function setColorProperties($color, $alpha, $colorType) { return [ - 'type' => (string) $type, + 'type' => (string) $colorType, 'value' => (string) $color, 'alpha' => (string) $this->getTrueAlpha($alpha), ]; } - protected function getLineStyleArrowSize($array_selector, $array_kay_selector) + protected function getLineStyleArrowSize($arraySelector, $arrayKaySelector) { $sizes = [ 1 => ['w' => 'sm', 'len' => 'sm'], @@ -158,10 +158,10 @@ abstract class Properties 9 => ['w' => 'lg', 'len' => 'lg'], ]; - return $sizes[$array_selector][$array_kay_selector]; + return $sizes[$arraySelector][$arrayKaySelector]; } - protected function getShadowPresetsMap($shadow_presets_option) + protected function getShadowPresetsMap($presetsOption) { $presets_options = [ //OUTER @@ -350,7 +350,7 @@ abstract class Properties ], ]; - return $presets_options[$shadow_presets_option]; + return $presets_options[$presetsOption]; } protected function getArrayElementsValue($properties, $elements) diff --git a/src/PhpSpreadsheet/Collection/Cells.php b/src/PhpSpreadsheet/Collection/Cells.php index 48f34f41..aedff5d9 100644 --- a/src/PhpSpreadsheet/Collection/Cells.php +++ b/src/PhpSpreadsheet/Collection/Cells.php @@ -86,18 +86,18 @@ class Cells /** * Whether the collection holds a cell for the given coordinate. * - * @param string $pCoord Coordinate of the cell to check + * @param string $cellCoordinate Coordinate of the cell to check * * @return bool */ - public function has($pCoord) + public function has($cellCoordinate) { - if ($pCoord === $this->currentCoordinate) { + if ($cellCoordinate === $this->currentCoordinate) { return true; } // Check if the requested entry exists in the index - return isset($this->index[$pCoord]); + return isset($this->index[$cellCoordinate]); } /** @@ -115,21 +115,21 @@ class Cells /** * Delete a cell in cache identified by coordinate. * - * @param string $pCoord Coordinate of the cell to delete + * @param string $cellCoordinate Coordinate of the cell to delete */ - public function delete($pCoord): void + public function delete($cellCoordinate): void { - if ($pCoord === $this->currentCoordinate && $this->currentCell !== null) { + if ($cellCoordinate === $this->currentCoordinate && $this->currentCell !== null) { $this->currentCell->detach(); $this->currentCoordinate = null; $this->currentCell = null; $this->currentCellIsDirty = false; } - unset($this->index[$pCoord]); + unset($this->index[$cellCoordinate]); // Delete the entry from cache - $this->cache->delete($this->cachePrefix . $pCoord); + $this->cache->delete($this->cachePrefix . $cellCoordinate); } /** @@ -304,16 +304,16 @@ class Cells /** * Clone the cell collection. * - * @param Worksheet $parent The new worksheet that we're copying to + * @param Worksheet $worksheet The new worksheet that we're copying to * * @return self */ - public function cloneCellCollection(Worksheet $parent) + public function cloneCellCollection(Worksheet $worksheet) { $this->storeCurrentCell(); $newCollection = clone $this; - $newCollection->parent = $parent; + $newCollection->parent = $worksheet; if (($newCollection->currentCell !== null) && (is_object($newCollection->currentCell))) { $newCollection->currentCell->attach($this); } @@ -402,19 +402,19 @@ class Cells /** * Add or update a cell identified by its coordinate into the collection. * - * @param string $pCoord Coordinate of the cell to update + * @param string $cellCoordinate Coordinate of the cell to update * @param Cell $cell Cell to update * * @return \PhpOffice\PhpSpreadsheet\Cell\Cell */ - public function add($pCoord, Cell $cell) + public function add($cellCoordinate, Cell $cell) { - if ($pCoord !== $this->currentCoordinate) { + if ($cellCoordinate !== $this->currentCoordinate) { $this->storeCurrentCell(); } - $this->index[$pCoord] = true; + $this->index[$cellCoordinate] = true; - $this->currentCoordinate = $pCoord; + $this->currentCoordinate = $cellCoordinate; $this->currentCell = $cell; $this->currentCellIsDirty = true; @@ -424,30 +424,30 @@ class Cells /** * Get cell at a specific coordinate. * - * @param string $pCoord Coordinate of the cell + * @param string $cellCoordinate Coordinate of the cell * * @return null|\PhpOffice\PhpSpreadsheet\Cell\Cell Cell that was found, or null if not found */ - public function get($pCoord) + public function get($cellCoordinate) { - if ($pCoord === $this->currentCoordinate) { + if ($cellCoordinate === $this->currentCoordinate) { return $this->currentCell; } $this->storeCurrentCell(); // Return null if requested entry doesn't exist in collection - if (!$this->has($pCoord)) { + if (!$this->has($cellCoordinate)) { return null; } // Check if the entry that has been requested actually exists - $cell = $this->cache->get($this->cachePrefix . $pCoord); + $cell = $this->cache->get($this->cachePrefix . $cellCoordinate); if ($cell === null) { - throw new PhpSpreadsheetException("Cell entry {$pCoord} no longer exists in cache. This probably means that the cache was cleared by someone else."); + throw new PhpSpreadsheetException("Cell entry {$cellCoordinate} no longer exists in cache. This probably means that the cache was cleared by someone else."); } // Set current entry to the requested entry - $this->currentCoordinate = $pCoord; + $this->currentCoordinate = $cellCoordinate; $this->currentCell = $cell; // Re-attach this as the cell's parent $this->currentCell->attach($this); diff --git a/src/PhpSpreadsheet/Collection/CellsFactory.php b/src/PhpSpreadsheet/Collection/CellsFactory.php index 7f34c231..26f18dfc 100644 --- a/src/PhpSpreadsheet/Collection/CellsFactory.php +++ b/src/PhpSpreadsheet/Collection/CellsFactory.php @@ -10,12 +10,12 @@ abstract class CellsFactory /** * Initialise the cache storage. * - * @param Worksheet $parent Enable cell caching for this worksheet + * @param Worksheet $worksheet Enable cell caching for this worksheet * * @return Cells * */ - public static function getInstance(Worksheet $parent) + public static function getInstance(Worksheet $worksheet) { - return new Cells($parent, Settings::getCache()); + return new Cells($worksheet, Settings::getCache()); } } From cf6abbc10e5b47f58322c94407a2e9ecc6fcbf8e Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 5 Nov 2020 19:15:01 +0100 Subject: [PATCH 22/41] Sane argument names in the various classes --- src/PhpSpreadsheet/Cell/Coordinate.php | 12 +- src/PhpSpreadsheet/Document/Properties.php | 63 ++++---- src/PhpSpreadsheet/Document/Security.php | 42 ++--- src/PhpSpreadsheet/Helper/Html.php | 8 +- src/PhpSpreadsheet/RichText/RichText.php | 18 +-- src/PhpSpreadsheet/RichText/Run.php | 12 +- src/PhpSpreadsheet/RichText/TextElement.php | 6 +- src/PhpSpreadsheet/Shared/Date.php | 50 +++--- src/PhpSpreadsheet/Shared/Drawing.php | 70 ++++----- src/PhpSpreadsheet/Shared/File.php | 22 +-- src/PhpSpreadsheet/Shared/Font.php | 53 +++---- src/PhpSpreadsheet/Shared/OLE.php | 26 ++-- src/PhpSpreadsheet/Shared/OLERead.php | 17 +- src/PhpSpreadsheet/Shared/PasswordHasher.php | 16 +- src/PhpSpreadsheet/Shared/StringHelper.php | 154 +++++++++---------- src/PhpSpreadsheet/Shared/TimeZone.php | 28 ++-- src/PhpSpreadsheet/Shared/XMLWriter.php | 24 +-- src/PhpSpreadsheet/Shared/Xls.php | 72 ++++----- 18 files changed, 346 insertions(+), 347 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 8efd8ad7..d2bc6e0a 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -137,24 +137,24 @@ abstract class Coordinate /** * Build range from coordinate strings. * - * @param array $range Array containg one or more arrays containing one or two coordinate strings + * @param array $rangea Array containg one or more arrays containing one or two coordinate strings * * @return string String representation of $pRange */ - public static function buildRange(array $range) + public static function buildRange(array $rangea) { // Verify range - if (empty($range) || !is_array($range[0])) { + if (empty($rangea) || !is_array($rangea[0])) { throw new Exception('Range does not contain any information'); } // Build range - $counter = count($range); + $counter = count($rangea); for ($i = 0; $i < $counter; ++$i) { - $range[$i] = implode(':', $range[$i]); + $rangea[$i] = implode(':', $rangea[$i]); } - return implode(',', $range); + return implode(',', $rangea); } /** diff --git a/src/PhpSpreadsheet/Document/Properties.php b/src/PhpSpreadsheet/Document/Properties.php index 0876a9ed..2538fe39 100644 --- a/src/PhpSpreadsheet/Document/Properties.php +++ b/src/PhpSpreadsheet/Document/Properties.php @@ -92,7 +92,7 @@ class Properties /** * Custom Properties. * - * @var string + * @var array */ private $customProperties = []; @@ -144,13 +144,13 @@ class Properties /** * Set Last Modified By. * - * @param string $pValue + * @param string $modifiedBy * * @return $this */ - public function setLastModifiedBy($pValue) + public function setLastModifiedBy($modifiedBy) { - $this->lastModifiedBy = $pValue; + $this->lastModifiedBy = $modifiedBy; return $this; } @@ -165,26 +165,31 @@ class Properties return $this->created; } + private function asTimeStamp($timestamp) + { + if ($timestamp === null) { + return time(); + } elseif (is_string($timestamp)) { + if (is_numeric($timestamp)) { + return (int) $timestamp; + } + + return strtotime($timestamp); + } + + return $timestamp; + } + /** * Set Created. * - * @param int|string $time + * @param int|string $timestamp * * @return $this */ - public function setCreated($time) + public function setCreated($timestamp) { - if ($time === null) { - $time = time(); - } elseif (is_string($time)) { - if (is_numeric($time)) { - $time = (int) $time; - } else { - $time = strtotime($time); - } - } - - $this->created = $time; + $this->created = $this->asTimeStamp($timestamp); return $this; } @@ -202,23 +207,13 @@ class Properties /** * Set Modified. * - * @param int|string $time + * @param int|string $timestamp * * @return $this */ - public function setModified($time) + public function setModified($timestamp) { - if ($time === null) { - $time = time(); - } elseif (is_string($time)) { - if (is_numeric($time)) { - $time = (int) $time; - } else { - $time = strtotime($time); - } - } - - $this->modified = $time; + $this->modified = $this->asTimeStamp($timestamp); return $this; } @@ -394,7 +389,7 @@ class Properties /** * Get a List of Custom Property Names. * - * @return array of string + * @return array */ public function getCustomProperties() { @@ -425,6 +420,8 @@ class Properties if (isset($this->customProperties[$propertyName])) { return $this->customProperties[$propertyName]['value']; } + + return null; } /** @@ -432,13 +429,15 @@ class Properties * * @param string $propertyName * - * @return string + * @return mixed */ public function getCustomPropertyType($propertyName) { if (isset($this->customProperties[$propertyName])) { return $this->customProperties[$propertyName]['type']; } + + return null; } /** diff --git a/src/PhpSpreadsheet/Document/Security.php b/src/PhpSpreadsheet/Document/Security.php index cef3db8c..e13f5e72 100644 --- a/src/PhpSpreadsheet/Document/Security.php +++ b/src/PhpSpreadsheet/Document/Security.php @@ -73,13 +73,13 @@ class Security /** * Set LockRevision. * - * @param bool $pValue + * @param bool $locked * * @return $this */ - public function setLockRevision($pValue) + public function setLockRevision($locked) { - $this->lockRevision = $pValue; + $this->lockRevision = $locked; return $this; } @@ -97,13 +97,13 @@ class Security /** * Set LockStructure. * - * @param bool $pValue + * @param bool $locked * * @return $this */ - public function setLockStructure($pValue) + public function setLockStructure($locked) { - $this->lockStructure = $pValue; + $this->lockStructure = $locked; return $this; } @@ -121,13 +121,13 @@ class Security /** * Set LockWindows. * - * @param bool $pValue + * @param bool $locked * * @return $this */ - public function setLockWindows($pValue) + public function setLockWindows($locked) { - $this->lockWindows = $pValue; + $this->lockWindows = $locked; return $this; } @@ -145,17 +145,17 @@ class Security /** * Set RevisionsPassword. * - * @param string $pValue - * @param bool $pAlreadyHashed If the password has already been hashed, set this to true + * @param string $password + * @param bool $alreadyHashed If the password has already been hashed, set this to true * * @return $this */ - public function setRevisionsPassword($pValue, $pAlreadyHashed = false) + public function setRevisionsPassword($password, $alreadyHashed = false) { - if (!$pAlreadyHashed) { - $pValue = PasswordHasher::hashPassword($pValue); + if (!$alreadyHashed) { + $password = PasswordHasher::hashPassword($password); } - $this->revisionsPassword = $pValue; + $this->revisionsPassword = $password; return $this; } @@ -173,17 +173,17 @@ class Security /** * Set WorkbookPassword. * - * @param string $pValue - * @param bool $pAlreadyHashed If the password has already been hashed, set this to true + * @param string $password + * @param bool $alreadyHashed If the password has already been hashed, set this to true * * @return $this */ - public function setWorkbookPassword($pValue, $pAlreadyHashed = false) + public function setWorkbookPassword($password, $alreadyHashed = false) { - if (!$pAlreadyHashed) { - $pValue = PasswordHasher::hashPassword($pValue); + if (!$alreadyHashed) { + $password = PasswordHasher::hashPassword($password); } - $this->workbookPassword = $pValue; + $this->workbookPassword = $password; return $this; } diff --git a/src/PhpSpreadsheet/Helper/Html.php b/src/PhpSpreadsheet/Helper/Html.php index 6c4cbf9b..908241d6 100644 --- a/src/PhpSpreadsheet/Helper/Html.php +++ b/src/PhpSpreadsheet/Helper/Html.php @@ -684,9 +684,9 @@ class Html $this->stringData = ''; } - protected function rgbToColour($rgb) + protected function rgbToColour($rgbValue) { - preg_match_all('/\d+/', $rgb, $values); + preg_match_all('/\d+/', $rgbValue, $values); foreach ($values[0] as &$value) { $value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } @@ -694,9 +694,9 @@ class Html return implode('', $values[0]); } - public static function colourNameLookup(string $rgb): string + public static function colourNameLookup(string $colorName): string { - return self::$colourMap[$rgb] ?? ''; + return self::$colourMap[$colorName] ?? ''; } protected function startFontTag($tag): void diff --git a/src/PhpSpreadsheet/RichText/RichText.php b/src/PhpSpreadsheet/RichText/RichText.php index 104177bd..ba9be66f 100644 --- a/src/PhpSpreadsheet/RichText/RichText.php +++ b/src/PhpSpreadsheet/RichText/RichText.php @@ -42,13 +42,13 @@ class RichText implements IComparable /** * Add text. * - * @param ITextElement $pText Rich text element + * @param ITextElement $text Rich text element * * @return $this */ - public function addText(ITextElement $pText) + public function addText(ITextElement $text) { - $this->richTextElements[] = $pText; + $this->richTextElements[] = $text; return $this; } @@ -56,13 +56,13 @@ class RichText implements IComparable /** * Create text. * - * @param string $pText Text + * @param string $text Text * * @return TextElement */ - public function createText($pText) + public function createText($text) { - $objText = new TextElement($pText); + $objText = new TextElement($text); $this->addText($objText); return $objText; @@ -71,13 +71,13 @@ class RichText implements IComparable /** * Create text run. * - * @param string $pText Text + * @param string $text Text * * @return Run */ - public function createTextRun($pText) + public function createTextRun($text) { - $objText = new Run($pText); + $objText = new Run($text); $this->addText($objText); return $objText; diff --git a/src/PhpSpreadsheet/RichText/Run.php b/src/PhpSpreadsheet/RichText/Run.php index 592d0e36..9c9f8072 100644 --- a/src/PhpSpreadsheet/RichText/Run.php +++ b/src/PhpSpreadsheet/RichText/Run.php @@ -16,11 +16,11 @@ class Run extends TextElement implements ITextElement /** * Create a new Run instance. * - * @param string $pText Text + * @param string $text Text */ - public function __construct($pText = '') + public function __construct($text = '') { - parent::__construct($pText); + parent::__construct($text); // Initialise variables $this->font = new Font(); } @@ -38,13 +38,13 @@ class Run extends TextElement implements ITextElement /** * Set font. * - * @param Font $pFont Font + * @param Font $font Font * * @return $this */ - public function setFont(?Font $pFont = null) + public function setFont(?Font $font = null) { - $this->font = $pFont; + $this->font = $font; return $this; } diff --git a/src/PhpSpreadsheet/RichText/TextElement.php b/src/PhpSpreadsheet/RichText/TextElement.php index f8be5d55..8e906bf7 100644 --- a/src/PhpSpreadsheet/RichText/TextElement.php +++ b/src/PhpSpreadsheet/RichText/TextElement.php @@ -14,12 +14,12 @@ class TextElement implements ITextElement /** * Create a new TextElement instance. * - * @param string $pText Text + * @param string $text Text */ - public function __construct($pText = '') + public function __construct($text = '') { // Initialise variables - $this->text = $pText; + $this->text = $text; } /** diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index 180a7159..b02e01f1 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -65,17 +65,17 @@ class Date /** * Set the Excel calendar (Windows 1900 or Mac 1904). * - * @param int $baseDate Excel base date (1900 or 1904) + * @param int $baseYear Excel base date (1900 or 1904) * * @return bool Success or failure */ - public static function setExcelCalendar($baseDate) + public static function setExcelCalendar($baseYear) { if ( - ($baseDate == self::CALENDAR_WINDOWS_1900) || - ($baseDate == self::CALENDAR_MAC_1904) + ($baseYear == self::CALENDAR_WINDOWS_1900) || + ($baseYear == self::CALENDAR_MAC_1904) ) { - self::$excelCalendar = $baseDate; + self::$excelCalendar = $baseYear; return true; } @@ -252,17 +252,17 @@ class Date /** * Convert a Unix timestamp to an MS Excel serialized date/time value. * - * @param int $dateValue Unix Timestamp + * @param int $unixTimestamp Unix Timestamp * * @return float MS Excel serialized date/time value */ - public static function timestampToExcel($dateValue) + public static function timestampToExcel($unixTimestamp) { - if (!is_numeric($dateValue)) { + if (!is_numeric($unixTimestamp)) { return false; } - return self::dateTimeToExcel(new \DateTime('@' . $dateValue)); + return self::dateTimeToExcel(new \DateTime('@' . $unixTimestamp)); } /** @@ -332,9 +332,9 @@ class Date * * @return bool */ - public static function isDateTimeFormat(NumberFormat $pFormat) + public static function isDateTimeFormat(NumberFormat $excelFormatCode) { - return self::isDateTimeFormatCode($pFormat->getFormatCode()); + return self::isDateTimeFormatCode($excelFormatCode->getFormatCode()); } private static $possibleDateFormatCharacters = 'eymdHs'; @@ -342,23 +342,23 @@ class Date /** * Is a given number format code a date/time? * - * @param string $pFormatCode + * @param string $excelFormatCode * * @return bool */ - public static function isDateTimeFormatCode($pFormatCode) + public static function isDateTimeFormatCode($excelFormatCode) { - if (strtolower($pFormatCode) === strtolower(NumberFormat::FORMAT_GENERAL)) { + if (strtolower($excelFormatCode) === strtolower(NumberFormat::FORMAT_GENERAL)) { // "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check) return false; } - if (preg_match('/[0#]E[+-]0/i', $pFormatCode)) { + if (preg_match('/[0#]E[+-]0/i', $excelFormatCode)) { // Scientific format return false; } // Switch on formatcode - switch ($pFormatCode) { + switch ($excelFormatCode) { // Explicitly defined date formats case NumberFormat::FORMAT_DATE_YYYYMMDD: case NumberFormat::FORMAT_DATE_YYYYMMDD2: @@ -386,21 +386,21 @@ class Date } // Typically number, currency or accounting (or occasionally fraction) formats - if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) { + if ((substr($excelFormatCode, 0, 1) == '_') || (substr($excelFormatCode, 0, 2) == '0 ')) { return false; } // Some "special formats" provided in German Excel versions were detected as date time value, // so filter them out here - "\C\H\-00000" (Switzerland) and "\D-00000" (Germany). - if (\strpos($pFormatCode, '-00000') !== false) { + if (\strpos($excelFormatCode, '-00000') !== false) { return false; } // Try checking for any of the date formatting characters that don't appear within square braces - if (preg_match('/(^|\])[^\[]*[' . self::$possibleDateFormatCharacters . ']/i', $pFormatCode)) { + if (preg_match('/(^|\])[^\[]*[' . self::$possibleDateFormatCharacters . ']/i', $excelFormatCode)) { // We might also have a format mask containing quoted strings... // we don't want to test for any of our characters within the quoted blocks - if (strpos($pFormatCode, '"') !== false) { + if (strpos($excelFormatCode, '"') !== false) { $segMatcher = false; - foreach (explode('"', $pFormatCode) as $subVal) { + foreach (explode('"', $excelFormatCode) as $subVal) { // Only test in alternate array entries (the non-quoted blocks) if ( ($segMatcher = !$segMatcher) && @@ -456,21 +456,21 @@ class Date /** * Converts a month name (either a long or a short name) to a month number. * - * @param string $month Month name or abbreviation + * @param string $monthName Month name or abbreviation * * @return int|string Month number (1 - 12), or the original string argument if it isn't a valid month name */ - public static function monthStringToNumber($month) + public static function monthStringToNumber($monthName) { $monthIndex = 1; foreach (self::$monthNames as $shortMonthName => $longMonthName) { - if (($month === $longMonthName) || ($month === $shortMonthName)) { + if (($monthName === $longMonthName) || ($monthName === $shortMonthName)) { return $monthIndex; } ++$monthIndex; } - return $month; + return $monthName; } /** diff --git a/src/PhpSpreadsheet/Shared/Drawing.php b/src/PhpSpreadsheet/Shared/Drawing.php index 25d6910d..8484c999 100644 --- a/src/PhpSpreadsheet/Shared/Drawing.php +++ b/src/PhpSpreadsheet/Shared/Drawing.php @@ -7,26 +7,26 @@ class Drawing /** * Convert pixels to EMU. * - * @param int $pValue Value in pixels + * @param int $pxValue Value in pixels * * @return int Value in EMU */ - public static function pixelsToEMU($pValue) + public static function pixelsToEMU($pxValue) { - return round($pValue * 9525); + return round($pxValue * 9525); } /** * Convert EMU to pixels. * - * @param int $pValue Value in EMU + * @param int $emValue Value in EMU * * @return int Value in pixels */ - public static function EMUToPixels($pValue) + public static function EMUToPixels($emValue) { - if ($pValue != 0) { - return round($pValue / 9525); + if ($emValue != 0) { + return round($emValue / 9525); } return 0; @@ -37,24 +37,24 @@ class Drawing * By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875 * This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional. * - * @param int $pValue Value in pixels - * @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook + * @param int $pxValue Value in pixels + * @param \PhpOffice\PhpSpreadsheet\Style\Font $defaultFont Default font of the workbook * * @return int Value in cell dimension */ - public static function pixelsToCellDimension($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont) + public static function pixelsToCellDimension($pxValue, \PhpOffice\PhpSpreadsheet\Style\Font $defaultFont) { // Font name and size - $name = $pDefaultFont->getName(); - $size = $pDefaultFont->getSize(); + $name = $defaultFont->getName(); + $size = $defaultFont->getSize(); if (isset(Font::$defaultColumnWidths[$name][$size])) { // Exact width can be determined - $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px']; + $colWidth = $pxValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px']; } else { // We don't have data for this particular font and size, use approximation by // extrapolating from Calibri 11 - $colWidth = $pValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size; + $colWidth = $pxValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size; } return $colWidth; @@ -63,12 +63,12 @@ class Drawing /** * Convert column width from (intrinsic) Excel units to pixels. * - * @param float $pValue Value in cell dimension + * @param float $excelSize Value in cell dimension * @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook * * @return int Value in pixels */ - public static function cellDimensionToPixels($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont) + public static function cellDimensionToPixels($excelSize, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont) { // Font name and size $name = $pDefaultFont->getName(); @@ -76,11 +76,11 @@ class Drawing if (isset(Font::$defaultColumnWidths[$name][$size])) { // Exact width can be determined - $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['px'] / Font::$defaultColumnWidths[$name][$size]['width']; + $colWidth = $excelSize * Font::$defaultColumnWidths[$name][$size]['px'] / Font::$defaultColumnWidths[$name][$size]['width']; } else { // We don't have data for this particular font and size, use approximation by // extrapolating from Calibri 11 - $colWidth = $pValue * $size * Font::$defaultColumnWidths['Calibri'][11]['px'] / Font::$defaultColumnWidths['Calibri'][11]['width'] / 11; + $colWidth = $excelSize * $size * Font::$defaultColumnWidths['Calibri'][11]['px'] / Font::$defaultColumnWidths['Calibri'][11]['width'] / 11; } // Round pixels to closest integer @@ -92,26 +92,26 @@ class Drawing /** * Convert pixels to points. * - * @param int $pValue Value in pixels + * @param int $pxValue Value in pixels * * @return float Value in points */ - public static function pixelsToPoints($pValue) + public static function pixelsToPoints($pxValue) { - return $pValue * 0.67777777; + return $pxValue * 0.67777777; } /** * Convert points to pixels. * - * @param int $pValue Value in points + * @param int $ptValue Value in points * * @return int Value in pixels */ - public static function pointsToPixels($pValue) + public static function pointsToPixels($ptValue) { - if ($pValue != 0) { - return (int) ceil($pValue * 1.333333333); + if ($ptValue != 0) { + return (int) ceil($ptValue * 1.333333333); } return 0; @@ -120,26 +120,26 @@ class Drawing /** * Convert degrees to angle. * - * @param int $pValue Degrees + * @param int $degrees Degrees * * @return int Angle */ - public static function degreesToAngle($pValue) + public static function degreesToAngle($degrees) { - return (int) round($pValue * 60000); + return (int) round($degrees * 60000); } /** * Convert angle to degrees. * - * @param int $pValue Angle + * @param int $angle Angle * * @return int Degrees */ - public static function angleToDegrees($pValue) + public static function angleToDegrees($angle) { - if ($pValue != 0) { - return round($pValue / 60000); + if ($angle != 0) { + return round($angle / 60000); } return 0; @@ -150,14 +150,14 @@ class Drawing * * @see http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214 * - * @param string $p_sFile Path to Windows DIB (BMP) image + * @param string $bmpFilename Path to Windows DIB (BMP) image * * @return resource */ - public static function imagecreatefrombmp($p_sFile) + public static function imagecreatefrombmp($bmpFilename) { // Load the image into a string - $file = fopen($p_sFile, 'rb'); + $file = fopen($bmpFilename, 'rb'); $read = fread($file, 10); while (!feof($file) && ($read != '')) { $read .= fread($file, 1024); diff --git a/src/PhpSpreadsheet/Shared/File.php b/src/PhpSpreadsheet/Shared/File.php index 7525df8a..1704e957 100644 --- a/src/PhpSpreadsheet/Shared/File.php +++ b/src/PhpSpreadsheet/Shared/File.php @@ -37,19 +37,19 @@ class File /** * Verify if a file exists. * - * @param string $pFilename Filename + * @param string $filename Filename * * @return bool */ - public static function fileExists($pFilename) + public static function fileExists($filename) { // Sick construction, but it seems that // file_exists returns strange values when // doing the original file_exists on ZIP archives... - if (strtolower(substr($pFilename, 0, 3)) == 'zip') { + if (strtolower(substr($filename, 0, 3)) == 'zip') { // Open ZIP file and verify if the file exists - $zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6); - $archiveFile = substr($pFilename, strpos($pFilename, '#') + 1); + $zipFile = substr($filename, 6, strpos($filename, '#') - 6); + $archiveFile = substr($filename, strpos($filename, '#') + 1); $zip = new ZipArchive(); if ($zip->open($zipFile) === true) { @@ -62,29 +62,29 @@ class File return false; } - return file_exists($pFilename); + return file_exists($filename); } /** * Returns canonicalized absolute pathname, also for ZIP archives. * - * @param string $pFilename + * @param string $filename * * @return string */ - public static function realpath($pFilename) + public static function realpath($filename) { // Returnvalue $returnValue = ''; // Try using realpath() - if (file_exists($pFilename)) { - $returnValue = realpath($pFilename); + if (file_exists($filename)) { + $returnValue = realpath($filename); } // Found something? if ($returnValue == '' || ($returnValue === null)) { - $pathArray = explode('/', $pFilename); + $pathArray = explode('/', $filename); while (in_array('..', $pathArray) && $pathArray[0] != '..') { $iMax = count($pathArray); for ($i = 0; $i < $iMax; ++$i) { diff --git a/src/PhpSpreadsheet/Shared/Font.php b/src/PhpSpreadsheet/Shared/Font.php index ee1f8aba..cf17fbf1 100644 --- a/src/PhpSpreadsheet/Shared/Font.php +++ b/src/PhpSpreadsheet/Shared/Font.php @@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\RichText\RichText; +use PhpOffice\PhpSpreadsheet\Style\Font as FontStyle; class Font { @@ -163,16 +164,16 @@ class Font /** * Set autoSize method. * - * @param string $pValue see self::AUTOSIZE_METHOD_* + * @param string $method see self::AUTOSIZE_METHOD_* * * @return bool Success or failure */ - public static function setAutoSizeMethod($pValue) + public static function setAutoSizeMethod($method) { - if (!in_array($pValue, self::$autoSizeMethods)) { + if (!in_array($method, self::$autoSizeMethods)) { return false; } - self::$autoSizeMethod = $pValue; + self::$autoSizeMethod = $method; return true; } @@ -196,11 +197,11 @@ class Font *
  • ~/.fonts/
  • * . * - * @param string $pValue + * @param string $folderPath */ - public static function setTrueTypeFontPath($pValue): void + public static function setTrueTypeFontPath($folderPath): void { - self::$trueTypeFontPath = $pValue; + self::$trueTypeFontPath = $folderPath; } /** @@ -216,14 +217,14 @@ class Font /** * Calculate an (approximate) OpenXML column width, based on font size and text contained. * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $font Font object + * @param FontStyle $font Font object * @param RichText|string $cellText Text to calculate width * @param int $rotation Rotation angle - * @param null|\PhpOffice\PhpSpreadsheet\Style\Font $defaultFont Font object + * @param null|FontStyle $defaultFont Font object * * @return int Column width */ - public static function calculateColumnWidth(\PhpOffice\PhpSpreadsheet\Style\Font $font, $cellText = '', $rotation = 0, ?\PhpOffice\PhpSpreadsheet\Style\Font $defaultFont = null) + public static function calculateColumnWidth(FontStyle $font, $cellText = '', $rotation = 0, ?FontStyle $defaultFont = null) { // If it is rich text, use plain text if ($cellText instanceof RichText) { @@ -273,12 +274,12 @@ class Font * Get GD text width in pixels for a string of text in a certain font at a certain rotation angle. * * @param string $text - * @param \PhpOffice\PhpSpreadsheet\Style\Font + * @param FontStyle * @param int $rotation * * @return int */ - public static function getTextWidthPixelsExact($text, \PhpOffice\PhpSpreadsheet\Style\Font $font, $rotation = 0) + public static function getTextWidthPixelsExact($text, FontStyle $font, $rotation = 0) { if (!function_exists('imagettfbbox')) { throw new PhpSpreadsheetException('GD library needs to be enabled'); @@ -307,7 +308,7 @@ class Font * * @return int Text width in pixels (no padding added) */ - public static function getTextWidthPixelsApprox($columnText, \PhpOffice\PhpSpreadsheet\Style\Font $font, $rotation = 0) + public static function getTextWidthPixelsApprox($columnText, FontStyle $font, $rotation = 0) { $fontName = $font->getName(); $fontSize = $font->getSize(); @@ -395,11 +396,11 @@ class Font /** * Returns the font path given the font. * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $font + * @param FontStyle $font * * @return string Path to TrueType font file */ - public static function getTrueTypeFontFileFromFont($font) + public static function getTrueTypeFontFileFromFont(FontStyle $font) { if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) { throw new PhpSpreadsheetException('Valid directory to TrueType Font files not specified'); @@ -525,13 +526,13 @@ class Font /** * Returns the associated charset for the font name. * - * @param string $name Font name + * @param string $fontName Font name * * @return int Character set code */ - public static function getCharsetFromFontName($name) + public static function getCharsetFromFontName($fontName) { - switch ($name) { + switch ($fontName) { // Add more cases. Check FONT records in real Excel files. case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI; @@ -550,28 +551,28 @@ class Font * Get the effective column width for columns without a column dimension or column with width -1 * For example, for Calibri 11 this is 9.140625 (64 px). * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $font The workbooks default font - * @param bool $pPixels true = return column width in pixels, false = return in OOXML units + * @param FontStyle $font The workbooks default font + * @param bool $returnAsPixels true = return column width in pixels, false = return in OOXML units * * @return mixed Column width */ - public static function getDefaultColumnWidthByFont(\PhpOffice\PhpSpreadsheet\Style\Font $font, $pPixels = false) + public static function getDefaultColumnWidthByFont(FontStyle $font, $returnAsPixels = false) { if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) { // Exact width can be determined - $columnWidth = $pPixels ? + $columnWidth = $returnAsPixels ? self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px'] : self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width']; } else { // We don't have data for this particular font and size, use approximation by // extrapolating from Calibri 11 - $columnWidth = $pPixels ? + $columnWidth = $returnAsPixels ? self::$defaultColumnWidths['Calibri'][11]['px'] : self::$defaultColumnWidths['Calibri'][11]['width']; $columnWidth = $columnWidth * $font->getSize() / 11; // Round pixels to closest integer - if ($pPixels) { + if ($returnAsPixels) { $columnWidth = (int) round($columnWidth); } } @@ -583,11 +584,11 @@ class Font * Get the effective row height for rows without a row dimension or rows with height -1 * For example, for Calibri 11 this is 15 points. * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $font The workbooks default font + * @param FontStyle $font The workbooks default font * * @return float Row height in points */ - public static function getDefaultRowHeightByFont(\PhpOffice\PhpSpreadsheet\Style\Font $font) + public static function getDefaultRowHeightByFont(FontStyle $font) { switch ($font->getName()) { case 'Arial': diff --git a/src/PhpSpreadsheet/Shared/OLE.php b/src/PhpSpreadsheet/Shared/OLE.php index d380995c..a8ed779f 100644 --- a/src/PhpSpreadsheet/Shared/OLE.php +++ b/src/PhpSpreadsheet/Shared/OLE.php @@ -109,15 +109,15 @@ class OLE * * @acces public * - * @param string $file + * @param string $filename * * @return bool true on success, PEAR_Error on failure */ - public function read($file) + public function read($filename) { - $fh = fopen($file, 'rb'); + $fh = fopen($filename, 'rb'); if (!$fh) { - throw new ReaderException("Can't open file $file"); + throw new ReaderException("Can't open file $filename"); } $this->_file_handle = $fh; @@ -243,13 +243,13 @@ class OLE /** * Reads a signed char. * - * @param resource $fh file handle + * @param resource $fileHandle file handle * * @return int */ - private static function readInt1($fh) + private static function readInt1($fileHandle) { - [, $tmp] = unpack('c', fread($fh, 1)); + [, $tmp] = unpack('c', fread($fileHandle, 1)); return $tmp; } @@ -257,13 +257,13 @@ class OLE /** * Reads an unsigned short (2 octets). * - * @param resource $fh file handle + * @param resource $fileHandle file handle * * @return int */ - private static function readInt2($fh) + private static function readInt2($fileHandle) { - [, $tmp] = unpack('v', fread($fh, 2)); + [, $tmp] = unpack('v', fread($fileHandle, 2)); return $tmp; } @@ -271,13 +271,13 @@ class OLE /** * Reads an unsigned long (4 octets). * - * @param resource $fh file handle + * @param resource $fileHandle file handle * * @return int */ - private static function readInt4($fh) + private static function readInt4($fileHandle) { - [, $tmp] = unpack('V', fread($fh, 4)); + [, $tmp] = unpack('V', fread($fileHandle, 4)); return $tmp; } diff --git a/src/PhpSpreadsheet/Shared/OLERead.php b/src/PhpSpreadsheet/Shared/OLERead.php index 7112b090..a431f89f 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -93,24 +93,24 @@ class OLERead /** * Read the file. * - * @param $pFilename string Filename + * @param $filename string Filename */ - public function read($pFilename): void + public function read($filename): void { - File::assertFile($pFilename); + File::assertFile($filename); // Get the file identifier // Don't bother reading the whole file until we know it's a valid OLE file - $this->data = file_get_contents($pFilename, false, null, 0, 8); + $this->data = file_get_contents($filename, false, null, 0, 8); // Check OLE identifier $identifierOle = pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1); if ($this->data != $identifierOle) { - throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file'); + throw new ReaderException('The filename ' . $filename . ' is not recognised as an OLE file'); } // Get the file data - $this->data = file_get_contents($pFilename); + $this->data = file_get_contents($filename); // Total number of sectors used for the SAT $this->numBigBlockDepotBlocks = self::getInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS); @@ -237,13 +237,12 @@ class OLERead /** * Read a standard stream (by joining sectors using information from SAT). * - * @param int $bl Sector ID where the stream starts + * @param int $block Sector ID where the stream starts * * @return string Data for standard stream */ - private function readData($bl) + private function readData($block) { - $block = $bl; $data = ''; while ($block != -2) { diff --git a/src/PhpSpreadsheet/Shared/PasswordHasher.php b/src/PhpSpreadsheet/Shared/PasswordHasher.php index 9fefe88f..aa2c279a 100644 --- a/src/PhpSpreadsheet/Shared/PasswordHasher.php +++ b/src/PhpSpreadsheet/Shared/PasswordHasher.php @@ -44,26 +44,26 @@ class PasswordHasher * Daniel Rentz of OpenOffice and the PEAR package * Spreadsheet_Excel_Writer by Xavier Noguer . * - * @param string $pPassword Password to hash + * @param string $password Password to hash */ - private static function defaultHashPassword(string $pPassword): string + private static function defaultHashPassword(string $password): string { - $password = 0x0000; + $passwordValue = 0x0000; $charPos = 1; // char position // split the plain text password in its component characters - $chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY); + $chars = preg_split('//', $password, -1, PREG_SPLIT_NO_EMPTY); foreach ($chars as $char) { $value = ord($char) << $charPos++; // shifted ASCII value $rotated_bits = $value >> 15; // rotated bits beyond bit 15 $value &= 0x7fff; // first 15 bits - $password ^= ($value | $rotated_bits); + $passwordValue ^= ($value | $rotated_bits); } - $password ^= strlen($pPassword); - $password ^= 0xCE4B; + $passwordValue ^= strlen($password); + $passwordValue ^= 0xCE4B; - return strtoupper(dechex($password)); + return strtoupper(dechex($passwordValue)); } /** diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index 9ae32413..12bc82b0 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -294,15 +294,15 @@ class StringHelper * So you could end up with something like _x0008_ in a string (either in a cell value () * element or in the shared string element. * - * @param string $value Value to unescape + * @param string $textValue Value to unescape * * @return string */ - public static function controlCharacterOOXML2PHP($value) + public static function controlCharacterOOXML2PHP($textValue) { self::buildCharacterSets(); - return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value); + return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $textValue); } /** @@ -316,64 +316,64 @@ class StringHelper * So you could end up with something like _x0008_ in a string (either in a cell value () * element or in the shared string element. * - * @param string $value Value to escape + * @param string $textValue Value to escape * * @return string */ - public static function controlCharacterPHP2OOXML($value) + public static function controlCharacterPHP2OOXML($textValue) { self::buildCharacterSets(); - return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value); + return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $textValue); } /** * Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters. * - * @param string $value + * @param string $textValue * * @return string */ - public static function sanitizeUTF8($value) + public static function sanitizeUTF8($textValue) { if (self::getIsIconvEnabled()) { - $value = @iconv('UTF-8', 'UTF-8', $value); + $textValue = @iconv('UTF-8', 'UTF-8', $textValue); - return $value; + return $textValue; } - $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8'); + $textValue = mb_convert_encoding($textValue, 'UTF-8', 'UTF-8'); - return $value; + return $textValue; } /** * Check if a string contains UTF8 data. * - * @param string $value + * @param string $textValue * * @return bool */ - public static function isUTF8($value) + public static function isUTF8($textValue) { - return $value === '' || preg_match('/^./su', $value) === 1; + return $textValue === '' || preg_match('/^./su', $textValue) === 1; } /** * Formats a numeric value as a string for output in various output writers forcing * point as decimal separator in case locale is other than English. * - * @param mixed $value + * @param mixed $numericValue * * @return string */ - public static function formatNumber($value) + public static function formatNumber($numericValue) { - if (is_float($value)) { - return str_replace(',', '.', $value); + if (is_float($numericValue)) { + return str_replace(',', '.', $numericValue); } - return (string) $value; + return (string) $numericValue; } /** @@ -383,25 +383,25 @@ class StringHelper * although this will give wrong results for non-ASCII strings * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3. * - * @param string $value UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * @param mixed[] $arrcRuns Details of rich text runs in $value * * @return string */ - public static function UTF8toBIFF8UnicodeShort($value, $arrcRuns = []) + public static function UTF8toBIFF8UnicodeShort($textValue, $arrcRuns = []) { // character count - $ln = self::countCharacters($value, 'UTF-8'); + $ln = self::countCharacters($textValue, 'UTF-8'); // option flags if (empty($arrcRuns)) { $data = pack('CC', $ln, 0x0001); // characters - $data .= self::convertEncoding($value, 'UTF-16LE', 'UTF-8'); + $data .= self::convertEncoding($textValue, 'UTF-16LE', 'UTF-8'); } else { $data = pack('vC', $ln, 0x09); $data .= pack('v', count($arrcRuns)); // characters - $data .= self::convertEncoding($value, 'UTF-16LE', 'UTF-8'); + $data .= self::convertEncoding($textValue, 'UTF-16LE', 'UTF-8'); foreach ($arrcRuns as $cRun) { $data .= pack('v', $cRun['strlen']); $data .= pack('v', $cRun['fontidx']); @@ -418,17 +418,17 @@ class StringHelper * although this will give wrong results for non-ASCII strings * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3. * - * @param string $value UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * * @return string */ - public static function UTF8toBIFF8UnicodeLong($value) + public static function UTF8toBIFF8UnicodeLong($textValue) { // character count - $ln = self::countCharacters($value, 'UTF-8'); + $ln = self::countCharacters($textValue, 'UTF-8'); // characters - $chars = self::convertEncoding($value, 'UTF-16LE', 'UTF-8'); + $chars = self::convertEncoding($textValue, 'UTF-16LE', 'UTF-8'); return pack('vC', $ln, 0x0001) . $chars; } @@ -436,91 +436,91 @@ class StringHelper /** * Convert string from one encoding to another. * - * @param string $value + * @param string $textValue * @param string $to Encoding to convert to, e.g. 'UTF-8' * @param string $from Encoding to convert from, e.g. 'UTF-16LE' * * @return string */ - public static function convertEncoding($value, $to, $from) + public static function convertEncoding($textValue, $to, $from) { if (self::getIsIconvEnabled()) { - $result = iconv($from, $to . self::$iconvOptions, $value); + $result = iconv($from, $to . self::$iconvOptions, $textValue); if (false !== $result) { return $result; } } - return mb_convert_encoding($value, $to, $from); + return mb_convert_encoding($textValue, $to, $from); } /** * Get character count. * - * @param string $value - * @param string $enc Encoding + * @param string $textValue + * @param string $encoding Encoding * * @return int Character count */ - public static function countCharacters($value, $enc = 'UTF-8') + public static function countCharacters($textValue, $encoding = 'UTF-8') { - return mb_strlen($value, $enc); + return mb_strlen($textValue, $encoding); } /** * Get a substring of a UTF-8 encoded string. * - * @param string $pValue UTF-8 encoded string - * @param int $pStart Start offset - * @param int $pLength Maximum number of characters in substring + * @param string $textValue UTF-8 encoded string + * @param int $offset Start offset + * @param int $length Maximum number of characters in substring * * @return string */ - public static function substring($pValue, $pStart, $pLength = 0) + public static function substring($textValue, $offset, $length = 0) { - return mb_substr($pValue, $pStart, $pLength, 'UTF-8'); + return mb_substr($textValue, $offset, $length, 'UTF-8'); } /** * Convert a UTF-8 encoded string to upper case. * - * @param string $pValue UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * * @return string */ - public static function strToUpper($pValue) + public static function strToUpper($textValue) { - return mb_convert_case($pValue, MB_CASE_UPPER, 'UTF-8'); + return mb_convert_case($textValue, MB_CASE_UPPER, 'UTF-8'); } /** * Convert a UTF-8 encoded string to lower case. * - * @param string $pValue UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * * @return string */ - public static function strToLower($pValue) + public static function strToLower($textValue) { - return mb_convert_case($pValue, MB_CASE_LOWER, 'UTF-8'); + return mb_convert_case($textValue, MB_CASE_LOWER, 'UTF-8'); } /** * Convert a UTF-8 encoded string to title/proper case * (uppercase every first character in each word, lower case all other characters). * - * @param string $pValue UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * * @return string */ - public static function strToTitle($pValue) + public static function strToTitle($textValue) { - return mb_convert_case($pValue, MB_CASE_TITLE, 'UTF-8'); + return mb_convert_case($textValue, MB_CASE_TITLE, 'UTF-8'); } - public static function mbIsUpper($char) + public static function mbIsUpper($character) { - return mb_strtolower($char, 'UTF-8') != $char; + return mb_strtolower($character, 'UTF-8') != $character; } public static function mbStrSplit($string) @@ -534,13 +534,13 @@ class StringHelper * Reverse the case of a string, so that all uppercase characters become lowercase * and all lowercase characters become uppercase. * - * @param string $pValue UTF-8 encoded string + * @param string $textValue UTF-8 encoded string * * @return string */ - public static function strCaseReverse($pValue) + public static function strCaseReverse($textValue) { - $characters = self::mbStrSplit($pValue); + $characters = self::mbStrSplit($textValue); foreach ($characters as &$character) { if (self::mbIsUpper($character)) { $character = mb_strtolower($character, 'UTF-8'); @@ -601,11 +601,11 @@ class StringHelper * Set the decimal separator. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * - * @param string $pValue Character for decimal separator + * @param string $separator Character for decimal separator */ - public static function setDecimalSeparator($pValue): void + public static function setDecimalSeparator($separator): void { - self::$decimalSeparator = $pValue; + self::$decimalSeparator = $separator; } /** @@ -634,11 +634,11 @@ class StringHelper * Set the thousands separator. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * - * @param string $pValue Character for thousands separator + * @param string $separator Character for thousands separator */ - public static function setThousandsSeparator($pValue): void + public static function setThousandsSeparator($separator): void { - self::$thousandsSeparator = $pValue; + self::$thousandsSeparator = $separator; } /** @@ -672,51 +672,51 @@ class StringHelper * Set the currency code. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * - * @param string $pValue Character for currency code + * @param string $currencyCode Character for currency code */ - public static function setCurrencyCode($pValue): void + public static function setCurrencyCode($currencyCode): void { - self::$currencyCode = $pValue; + self::$currencyCode = $currencyCode; } /** * Convert SYLK encoded string to UTF-8. * - * @param string $pValue + * @param string $textValue * * @return string UTF-8 encoded string */ - public static function SYLKtoUTF8($pValue) + public static function SYLKtoUTF8($textValue) { self::buildCharacterSets(); // If there is no escape character in the string there is nothing to do - if (strpos($pValue, '') === false) { - return $pValue; + if (strpos($textValue, '') === false) { + return $textValue; } foreach (self::$SYLKCharacters as $k => $v) { - $pValue = str_replace($k, $v, $pValue); + $textValue = str_replace($k, $v, $textValue); } - return $pValue; + return $textValue; } /** * Retrieve any leading numeric part of a string, or return the full string if no leading numeric * (handles basic integer or float, but not exponent or non decimal). * - * @param string $value + * @param string $textValue * * @return mixed string or only the leading numeric part of the string */ - public static function testStringAsNumeric($value) + public static function testStringAsNumeric($textValue) { - if (is_numeric($value)) { - return $value; + if (is_numeric($textValue)) { + return $textValue; } - $v = (float) $value; + $v = (float) $textValue; - return (is_numeric(substr($value, 0, strlen($v)))) ? $v : $value; + return (is_numeric(substr($textValue, 0, strlen($v)))) ? $v : $textValue; } } diff --git a/src/PhpSpreadsheet/Shared/TimeZone.php b/src/PhpSpreadsheet/Shared/TimeZone.php index 43fd3653..58b3e4eb 100644 --- a/src/PhpSpreadsheet/Shared/TimeZone.php +++ b/src/PhpSpreadsheet/Shared/TimeZone.php @@ -17,26 +17,26 @@ class TimeZone /** * Validate a Timezone name. * - * @param string $timezone Time zone (e.g. 'Europe/London') + * @param string $timezoneName Time zone (e.g. 'Europe/London') * * @return bool Success or failure */ - private static function validateTimeZone($timezone) + private static function validateTimeZone($timezoneName) { - return in_array($timezone, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC)); + return in_array($timezoneName, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC)); } /** * Set the Default Timezone used for date/time conversions. * - * @param string $timezone Time zone (e.g. 'Europe/London') + * @param string $timezoneName Time zone (e.g. 'Europe/London') * * @return bool Success or failure */ - public static function setTimeZone($timezone) + public static function setTimeZone($timezoneName) { - if (self::validateTimezone($timezone)) { - self::$timezone = $timezone; + if (self::validateTimezone($timezoneName)) { + self::$timezone = $timezoneName; return true; } @@ -58,22 +58,22 @@ class TimeZone * Return the Timezone offset used for date/time conversions to/from UST * This requires both the timezone and the calculated date/time to allow for local DST. * - * @param string $timezone The timezone for finding the adjustment to UST + * @param string $timezoneName The timezone for finding the adjustment to UST * @param int $timestamp PHP date/time value * * @return int Number of seconds for timezone adjustment */ - public static function getTimeZoneAdjustment($timezone, $timestamp) + public static function getTimeZoneAdjustment($timezoneName, $timestamp) { - if ($timezone !== null) { - if (!self::validateTimezone($timezone)) { - throw new PhpSpreadsheetException('Invalid timezone ' . $timezone); + if ($timezoneName !== null) { + if (!self::validateTimezone($timezoneName)) { + throw new PhpSpreadsheetException('Invalid timezone ' . $timezoneName); } } else { - $timezone = self::$timezone; + $timezoneName = self::$timezone; } - $objTimezone = new DateTimeZone($timezone); + $objTimezone = new DateTimeZone($timezoneName); $transitions = $objTimezone->getTransitions($timestamp, $timestamp); return (count($transitions) > 0) ? $transitions[0]['offset'] : 0; diff --git a/src/PhpSpreadsheet/Shared/XMLWriter.php b/src/PhpSpreadsheet/Shared/XMLWriter.php index 4f7a6a06..6fb38438 100644 --- a/src/PhpSpreadsheet/Shared/XMLWriter.php +++ b/src/PhpSpreadsheet/Shared/XMLWriter.php @@ -20,20 +20,20 @@ class XMLWriter extends \XMLWriter /** * Create a new XMLWriter instance. * - * @param int $pTemporaryStorage Temporary storage location - * @param string $pTemporaryStorageFolder Temporary storage folder + * @param int $temporaryStorage Temporary storage location + * @param string $temporaryStorageFolder Temporary storage folder */ - public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = null) + public function __construct($temporaryStorage = self::STORAGE_MEMORY, $temporaryStorageFolder = null) { // Open temporary storage - if ($pTemporaryStorage == self::STORAGE_MEMORY) { + if ($temporaryStorage == self::STORAGE_MEMORY) { $this->openMemory(); } else { // Create temporary filename - if ($pTemporaryStorageFolder === null) { - $pTemporaryStorageFolder = File::sysGetTempDir(); + if ($temporaryStorageFolder === null) { + $temporaryStorageFolder = File::sysGetTempDir(); } - $this->tempFileName = @tempnam($pTemporaryStorageFolder, 'xml'); + $this->tempFileName = @tempnam($temporaryStorageFolder, 'xml'); // Open storage if ($this->openUri($this->tempFileName) === false) { @@ -77,16 +77,16 @@ class XMLWriter extends \XMLWriter /** * Wrapper method for writeRaw. * - * @param string|string[] $text + * @param string|string[] $rawTextData * * @return bool */ - public function writeRawData($text) + public function writeRawData($rawTextData) { - if (is_array($text)) { - $text = implode("\n", $text); + if (is_array($rawTextData)) { + $rawTextData = implode("\n", $rawTextData); } - return $this->writeRaw(htmlspecialchars($text)); + return $this->writeRaw(htmlspecialchars($rawTextData)); } } diff --git a/src/PhpSpreadsheet/Shared/Xls.php b/src/PhpSpreadsheet/Shared/Xls.php index c9eaf378..6a57f8e9 100644 --- a/src/PhpSpreadsheet/Shared/Xls.php +++ b/src/PhpSpreadsheet/Shared/Xls.php @@ -12,17 +12,17 @@ class Xls * x is the width in intrinsic Excel units (measuring width in number of normal characters) * This holds for Arial 10. * - * @param Worksheet $sheet The sheet + * @param Worksheet $worksheet The sheet * @param string $col The column * * @return int The width in pixels */ - public static function sizeCol($sheet, $col = 'A') + public static function sizeCol(Worksheet $worksheet, $col = 'A') { // default font of the workbook - $font = $sheet->getParent()->getDefaultStyle()->getFont(); + $font = $worksheet->getParent()->getDefaultStyle()->getFont(); - $columnDimensions = $sheet->getColumnDimensions(); + $columnDimensions = $worksheet->getColumnDimensions(); // first find the true column width in pixels (uncollapsed and unhidden) if (isset($columnDimensions[$col]) && $columnDimensions[$col]->getWidth() != -1) { @@ -30,9 +30,9 @@ class Xls $columnDimension = $columnDimensions[$col]; $width = $columnDimension->getWidth(); $pixelWidth = Drawing::cellDimensionToPixels($width, $font); - } elseif ($sheet->getDefaultColumnDimension()->getWidth() != -1) { + } elseif ($worksheet->getDefaultColumnDimension()->getWidth() != -1) { // then we have default column dimension with explicit width - $defaultColumnDimension = $sheet->getDefaultColumnDimension(); + $defaultColumnDimension = $worksheet->getDefaultColumnDimension(); $width = $defaultColumnDimension->getWidth(); $pixelWidth = Drawing::cellDimensionToPixels($width, $font); } else { @@ -55,17 +55,17 @@ class Xls * the relationship is: y = 4/3x. If the height hasn't been set by the user we * use the default value. If the row is hidden we use a value of zero. * - * @param Worksheet $sheet The sheet + * @param Worksheet $worksheet The sheet * @param int $row The row index (1-based) * * @return int The width in pixels */ - public static function sizeRow($sheet, $row = 1) + public static function sizeRow(Worksheet $worksheet, $row = 1) { // default font of the workbook - $font = $sheet->getParent()->getDefaultStyle()->getFont(); + $font = $worksheet->getParent()->getDefaultStyle()->getFont(); - $rowDimensions = $sheet->getRowDimensions(); + $rowDimensions = $worksheet->getRowDimensions(); // first find the true row height in pixels (uncollapsed and unhidden) if (isset($rowDimensions[$row]) && $rowDimensions[$row]->getRowHeight() != -1) { @@ -73,9 +73,9 @@ class Xls $rowDimension = $rowDimensions[$row]; $rowHeight = $rowDimension->getRowHeight(); $pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10 - } elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) { + } elseif ($worksheet->getDefaultRowDimension()->getRowHeight() != -1) { // then we have a default row dimension with explicit height - $defaultRowDimension = $sheet->getDefaultRowDimension(); + $defaultRowDimension = $worksheet->getDefaultRowDimension(); $rowHeight = $defaultRowDimension->getRowHeight(); $pixelRowHeight = Drawing::pointsToPixels($rowHeight); } else { @@ -105,7 +105,7 @@ class Xls * * @return int Horizontal measured in pixels */ - public static function getDistanceX(Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0) + public static function getDistanceX(Worksheet $worksheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0) { $distanceX = 0; @@ -113,14 +113,14 @@ class Xls $startColumnIndex = Coordinate::columnIndexFromString($startColumn); $endColumnIndex = Coordinate::columnIndexFromString($endColumn); for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) { - $distanceX += self::sizeCol($sheet, Coordinate::stringFromColumnIndex($i)); + $distanceX += self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($i)); } // correct for offsetX in startcell - $distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024); + $distanceX -= (int) floor(self::sizeCol($worksheet, $startColumn) * $startOffsetX / 1024); // correct for offsetX in endcell - $distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024)); + $distanceX -= (int) floor(self::sizeCol($worksheet, $endColumn) * (1 - $endOffsetX / 1024)); return $distanceX; } @@ -136,20 +136,20 @@ class Xls * * @return int Vertical distance measured in pixels */ - public static function getDistanceY(Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0) + public static function getDistanceY(Worksheet $worksheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0) { $distanceY = 0; // add the widths of the spanning rows for ($row = $startRow; $row <= $endRow; ++$row) { - $distanceY += self::sizeRow($sheet, $row); + $distanceY += self::sizeRow($worksheet, $row); } // correct for offsetX in startcell - $distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256); + $distanceY -= (int) floor(self::sizeRow($worksheet, $startRow) * $startOffsetY / 256); // correct for offsetX in endcell - $distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256)); + $distanceY -= (int) floor(self::sizeRow($worksheet, $endRow) * (1 - $endOffsetY / 256)); return $distanceY; } @@ -198,7 +198,7 @@ class Xls * W is the width of the cell * H is the height of the cell * - * @param Worksheet $sheet + * @param Worksheet $worksheet * @param string $coordinates E.g. 'A1' * @param int $offsetX Horizontal offset in pixels * @param int $offsetY Vertical offset in pixels @@ -207,7 +207,7 @@ class Xls * * @return array */ - public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height) + public static function oneAnchor2twoAnchor(Worksheet $worksheet, $coordinates, $offsetX, $offsetY, $width, $height) { [$column, $row] = Coordinate::coordinateFromString($coordinates); $col_start = Coordinate::columnIndexFromString($column); @@ -221,10 +221,10 @@ class Xls $row_end = $row_start; // Row containing bottom right corner of object // Zero the specified offset if greater than the cell dimensions - if ($x1 >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start))) { + if ($x1 >= self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_start))) { $x1 = 0; } - if ($y1 >= self::sizeRow($sheet, $row_start + 1)) { + if ($y1 >= self::sizeRow($worksheet, $row_start + 1)) { $y1 = 0; } @@ -232,37 +232,37 @@ class Xls $height = $height + $y1 - 1; // Subtract the underlying cell widths to find the end cell of the image - while ($width >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end))) { - $width -= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)); + while ($width >= self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_end))) { + $width -= self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_end)); ++$col_end; } // Subtract the underlying cell heights to find the end cell of the image - while ($height >= self::sizeRow($sheet, $row_end + 1)) { - $height -= self::sizeRow($sheet, $row_end + 1); + while ($height >= self::sizeRow($worksheet, $row_end + 1)) { + $height -= self::sizeRow($worksheet, $row_end + 1); ++$row_end; } // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // with zero height or width. - if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) == 0) { + if (self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_start)) == 0) { return; } - if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) == 0) { + if (self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_end)) == 0) { return; } - if (self::sizeRow($sheet, $row_start + 1) == 0) { + if (self::sizeRow($worksheet, $row_start + 1) == 0) { return; } - if (self::sizeRow($sheet, $row_end + 1) == 0) { + if (self::sizeRow($worksheet, $row_end + 1) == 0) { return; } // Convert the pixel values to the percentage value expected by Excel - $x1 = $x1 / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) * 1024; - $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256; - $x2 = ($width + 1) / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object - $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object + $x1 = $x1 / self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_start)) * 1024; + $y1 = $y1 / self::sizeRow($worksheet, $row_start + 1) * 256; + $x2 = ($width + 1) / self::sizeCol($worksheet, Coordinate::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object + $y2 = ($height + 1) / self::sizeRow($worksheet, $row_end + 1) * 256; // Distance to bottom of object $startCoordinates = Coordinate::stringFromColumnIndex($col_start) . ($row_start + 1); $endCoordinates = Coordinate::stringFromColumnIndex($col_end) . ($row_end + 1); From 317965078dad8c0407e0fb111bd5d25a6b877984 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 5 Nov 2020 19:29:55 +0100 Subject: [PATCH 23/41] Fix a couple of phpcs issues --- src/PhpSpreadsheet/Shared/Font.php | 2 -- src/PhpSpreadsheet/Shared/Xls.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/PhpSpreadsheet/Shared/Font.php b/src/PhpSpreadsheet/Shared/Font.php index cf17fbf1..188a987b 100644 --- a/src/PhpSpreadsheet/Shared/Font.php +++ b/src/PhpSpreadsheet/Shared/Font.php @@ -396,8 +396,6 @@ class Font /** * Returns the font path given the font. * - * @param FontStyle $font - * * @return string Path to TrueType font file */ public static function getTrueTypeFontFileFromFont(FontStyle $font) diff --git a/src/PhpSpreadsheet/Shared/Xls.php b/src/PhpSpreadsheet/Shared/Xls.php index 6a57f8e9..41cd0c50 100644 --- a/src/PhpSpreadsheet/Shared/Xls.php +++ b/src/PhpSpreadsheet/Shared/Xls.php @@ -198,7 +198,6 @@ class Xls * W is the width of the cell * H is the height of the cell * - * @param Worksheet $worksheet * @param string $coordinates E.g. 'A1' * @param int $offsetX Horizontal offset in pixels * @param int $offsetY Vertical offset in pixels From 86728cb214ffa18d397a58af97e70263ea3401fa Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 5 Nov 2020 20:04:35 +0100 Subject: [PATCH 24/41] Sane argument names for Styles --- src/PhpSpreadsheet/Style/Alignment.php | 48 ++++---- src/PhpSpreadsheet/Style/Border.php | 14 +-- src/PhpSpreadsheet/Style/Borders.php | 52 ++++----- src/PhpSpreadsheet/Style/Color.php | 38 +++--- src/PhpSpreadsheet/Style/Conditional.php | 46 ++++---- src/PhpSpreadsheet/Style/Fill.php | 52 ++++----- src/PhpSpreadsheet/Style/Font.php | 134 +++++++++++----------- src/PhpSpreadsheet/Style/NumberFormat.php | 52 ++++----- src/PhpSpreadsheet/Style/Protection.php | 30 ++--- src/PhpSpreadsheet/Style/Style.php | 96 ++++++++-------- 10 files changed, 281 insertions(+), 281 deletions(-) diff --git a/src/PhpSpreadsheet/Style/Alignment.php b/src/PhpSpreadsheet/Style/Alignment.php index 414307e3..43b0ead2 100644 --- a/src/PhpSpreadsheet/Style/Alignment.php +++ b/src/PhpSpreadsheet/Style/Alignment.php @@ -140,36 +140,36 @@ class Alignment extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { $this->getActiveSheet()->getStyle($this->getSelectedCells()) - ->applyFromArray($this->getStyleArray($pStyles)); + ->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['horizontal'])) { - $this->setHorizontal($pStyles['horizontal']); + if (isset($styleArray['horizontal'])) { + $this->setHorizontal($styleArray['horizontal']); } - if (isset($pStyles['vertical'])) { - $this->setVertical($pStyles['vertical']); + if (isset($styleArray['vertical'])) { + $this->setVertical($styleArray['vertical']); } - if (isset($pStyles['textRotation'])) { - $this->setTextRotation($pStyles['textRotation']); + if (isset($styleArray['textRotation'])) { + $this->setTextRotation($styleArray['textRotation']); } - if (isset($pStyles['wrapText'])) { - $this->setWrapText($pStyles['wrapText']); + if (isset($styleArray['wrapText'])) { + $this->setWrapText($styleArray['wrapText']); } - if (isset($pStyles['shrinkToFit'])) { - $this->setShrinkToFit($pStyles['shrinkToFit']); + if (isset($styleArray['shrinkToFit'])) { + $this->setShrinkToFit($styleArray['shrinkToFit']); } - if (isset($pStyles['indent'])) { - $this->setIndent($pStyles['indent']); + if (isset($styleArray['indent'])) { + $this->setIndent($styleArray['indent']); } - if (isset($pStyles['readOrder'])) { - $this->setReadOrder($pStyles['readOrder']); + if (isset($styleArray['readOrder'])) { + $this->setReadOrder($styleArray['readOrder']); } } @@ -267,24 +267,24 @@ class Alignment extends Supervisor /** * Set TextRotation. * - * @param int $rotation + * @param int $angleInDegrees * * @return $this */ - public function setTextRotation($rotation) + public function setTextRotation($angleInDegrees) { // Excel2007 value 255 => PhpSpreadsheet value -165 - if ($rotation == self::TEXTROTATION_STACK_EXCEL) { - $rotation = self::TEXTROTATION_STACK_PHPSPREADSHEET; + if ($angleInDegrees == self::TEXTROTATION_STACK_EXCEL) { + $angleInDegrees = self::TEXTROTATION_STACK_PHPSPREADSHEET; } // Set rotation - if (($rotation >= -90 && $rotation <= 90) || $rotation == self::TEXTROTATION_STACK_PHPSPREADSHEET) { + if (($angleInDegrees >= -90 && $angleInDegrees <= 90) || $angleInDegrees == self::TEXTROTATION_STACK_PHPSPREADSHEET) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['textRotation' => $rotation]); + $styleArray = $this->getStyleArray(['textRotation' => $angleInDegrees]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->textRotation = $rotation; + $this->textRotation = $angleInDegrees; } } else { throw new PhpSpreadsheetException('Text rotation should be a value between -90 and 90.'); diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index a09078a4..b8f277e4 100644 --- a/src/PhpSpreadsheet/Style/Border.php +++ b/src/PhpSpreadsheet/Style/Border.php @@ -115,20 +115,20 @@ class Border extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['borderStyle'])) { - $this->setBorderStyle($pStyles['borderStyle']); + if (isset($styleArray['borderStyle'])) { + $this->setBorderStyle($styleArray['borderStyle']); } - if (isset($pStyles['color'])) { - $this->getColor()->applyFromArray($pStyles['color']); + if (isset($styleArray['color'])) { + $this->getColor()->applyFromArray($styleArray['color']); } } diff --git a/src/PhpSpreadsheet/Style/Borders.php b/src/PhpSpreadsheet/Style/Borders.php index a1acfdd4..1b1b6ab6 100644 --- a/src/PhpSpreadsheet/Style/Borders.php +++ b/src/PhpSpreadsheet/Style/Borders.php @@ -193,38 +193,38 @@ class Borders extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['left'])) { - $this->getLeft()->applyFromArray($pStyles['left']); + if (isset($styleArray['left'])) { + $this->getLeft()->applyFromArray($styleArray['left']); } - if (isset($pStyles['right'])) { - $this->getRight()->applyFromArray($pStyles['right']); + if (isset($styleArray['right'])) { + $this->getRight()->applyFromArray($styleArray['right']); } - if (isset($pStyles['top'])) { - $this->getTop()->applyFromArray($pStyles['top']); + if (isset($styleArray['top'])) { + $this->getTop()->applyFromArray($styleArray['top']); } - if (isset($pStyles['bottom'])) { - $this->getBottom()->applyFromArray($pStyles['bottom']); + if (isset($styleArray['bottom'])) { + $this->getBottom()->applyFromArray($styleArray['bottom']); } - if (isset($pStyles['diagonal'])) { - $this->getDiagonal()->applyFromArray($pStyles['diagonal']); + if (isset($styleArray['diagonal'])) { + $this->getDiagonal()->applyFromArray($styleArray['diagonal']); } - if (isset($pStyles['diagonalDirection'])) { - $this->setDiagonalDirection($pStyles['diagonalDirection']); + if (isset($styleArray['diagonalDirection'])) { + $this->setDiagonalDirection($styleArray['diagonalDirection']); } - if (isset($pStyles['allBorders'])) { - $this->getLeft()->applyFromArray($pStyles['allBorders']); - $this->getRight()->applyFromArray($pStyles['allBorders']); - $this->getTop()->applyFromArray($pStyles['allBorders']); - $this->getBottom()->applyFromArray($pStyles['allBorders']); + if (isset($styleArray['allBorders'])) { + $this->getLeft()->applyFromArray($styleArray['allBorders']); + $this->getRight()->applyFromArray($styleArray['allBorders']); + $this->getTop()->applyFromArray($styleArray['allBorders']); + $this->getBottom()->applyFromArray($styleArray['allBorders']); } } @@ -368,20 +368,20 @@ class Borders extends Supervisor /** * Set DiagonalDirection. * - * @param int $pValue see self::DIAGONAL_* + * @param int $direction see self::DIAGONAL_* * * @return $this */ - public function setDiagonalDirection($pValue) + public function setDiagonalDirection($direction) { - if ($pValue == '') { - $pValue = self::DIAGONAL_NONE; + if ($direction == '') { + $direction = self::DIAGONAL_NONE; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]); + $styleArray = $this->getStyleArray(['diagonalDirection' => $direction]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->diagonalDirection = $pValue; + $this->diagonalDirection = $direction; } return $this; diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 534bcc9f..e3defb6a 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -104,20 +104,20 @@ class Color extends Supervisor * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']); * * - * @param array $styles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $styles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($styles['rgb'])) { - $this->setRGB($styles['rgb']); + if (isset($styleArray['rgb'])) { + $this->setRGB($styleArray['rgb']); } - if (isset($styles['argb'])) { - $this->setARGB($styles['argb']); + if (isset($styleArray['argb'])) { + $this->setARGB($styleArray['argb']); } } @@ -211,16 +211,16 @@ class Color extends Supervisor /** * Get a specified colour component of an RGB value. * - * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE + * @param string $rgbValue The colour as an RGB value (e.g. FF00CCCC or CCDDEE * @param int $offset Position within the RGB value to extract * @param bool $hex Flag indicating whether the component should be returned as a hex or a * decimal value * * @return string The extracted colour component */ - private static function getColourComponent($RGB, $offset, $hex = true) + private static function getColourComponent($rgbValue, $offset, $hex = true) { - $colour = substr($RGB, $offset, 2); + $colour = substr($rgbValue, $offset, 2); return ($hex) ? $colour : hexdec($colour); } @@ -228,43 +228,43 @@ class Color extends Supervisor /** * Get the red colour component of an RGB value. * - * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE + * @param string $rgbValue The colour as an RGB value (e.g. FF00CCCC or CCDDEE * @param bool $hex Flag indicating whether the component should be returned as a hex or a * decimal value * * @return string The red colour component */ - public static function getRed($RGB, $hex = true) + public static function getRed($rgbValue, $hex = true) { - return self::getColourComponent($RGB, strlen($RGB) - 6, $hex); + return self::getColourComponent($rgbValue, strlen($rgbValue) - 6, $hex); } /** * Get the green colour component of an RGB value. * - * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE + * @param string $rgbValue The colour as an RGB value (e.g. FF00CCCC or CCDDEE * @param bool $hex Flag indicating whether the component should be returned as a hex or a * decimal value * * @return string The green colour component */ - public static function getGreen($RGB, $hex = true) + public static function getGreen($rgbValue, $hex = true) { - return self::getColourComponent($RGB, strlen($RGB) - 4, $hex); + return self::getColourComponent($rgbValue, strlen($rgbValue) - 4, $hex); } /** * Get the blue colour component of an RGB value. * - * @param string $RGB The colour as an RGB value (e.g. FF00CCCC or CCDDEE + * @param string $rgbValue The colour as an RGB value (e.g. FF00CCCC or CCDDEE * @param bool $hex Flag indicating whether the component should be returned as a hex or a * decimal value * * @return string The blue colour component */ - public static function getBlue($RGB, $hex = true) + public static function getBlue($rgbValue, $hex = true) { - return self::getColourComponent($RGB, strlen($RGB) - 2, $hex); + return self::getColourComponent($rgbValue, strlen($rgbValue) - 2, $hex); } /** diff --git a/src/PhpSpreadsheet/Style/Conditional.php b/src/PhpSpreadsheet/Style/Conditional.php index 35ec479b..190eee86 100644 --- a/src/PhpSpreadsheet/Style/Conditional.php +++ b/src/PhpSpreadsheet/Style/Conditional.php @@ -93,13 +93,13 @@ class Conditional implements IComparable /** * Set Condition type. * - * @param string $pValue Condition type, see self::CONDITION_* + * @param string $type Condition type, see self::CONDITION_* * * @return $this */ - public function setConditionType($pValue) + public function setConditionType($type) { - $this->conditionType = $pValue; + $this->conditionType = $type; return $this; } @@ -117,13 +117,13 @@ class Conditional implements IComparable /** * Set Operator type. * - * @param string $pValue Conditional operator type, see self::OPERATOR_* + * @param string $type Conditional operator type, see self::OPERATOR_* * * @return $this */ - public function setOperatorType($pValue) + public function setOperatorType($type) { - $this->operatorType = $pValue; + $this->operatorType = $type; return $this; } @@ -141,13 +141,13 @@ class Conditional implements IComparable /** * Set text. * - * @param string $value + * @param string $text * * @return $this */ - public function setText($value) + public function setText($text) { - $this->text = $value; + $this->text = $text; return $this; } @@ -165,13 +165,13 @@ class Conditional implements IComparable /** * Set StopIfTrue. * - * @param bool $value + * @param bool $stopIfTrue * * @return $this */ - public function setStopIfTrue($value) + public function setStopIfTrue($stopIfTrue) { - $this->stopIfTrue = $value; + $this->stopIfTrue = $stopIfTrue; return $this; } @@ -189,16 +189,16 @@ class Conditional implements IComparable /** * Set Conditions. * - * @param string[] $pValue Condition + * @param string[] $conditions Condition * * @return $this */ - public function setConditions($pValue) + public function setConditions($conditions) { - if (!is_array($pValue)) { - $pValue = [$pValue]; + if (!is_array($conditions)) { + $conditions = [$conditions]; } - $this->condition = $pValue; + $this->condition = $conditions; return $this; } @@ -206,13 +206,13 @@ class Conditional implements IComparable /** * Add Condition. * - * @param string $pValue Condition + * @param string $comdition Condition * * @return $this */ - public function addCondition($pValue) + public function addCondition($comdition) { - $this->condition[] = $pValue; + $this->condition[] = $comdition; return $this; } @@ -230,13 +230,13 @@ class Conditional implements IComparable /** * Set Style. * - * @param Style $pValue + * @param Style $style * * @return $this */ - public function setStyle(?Style $pValue = null) + public function setStyle(?Style $style = null) { - $this->style = $pValue; + $this->style = $style; return $this; } diff --git a/src/PhpSpreadsheet/Style/Fill.php b/src/PhpSpreadsheet/Style/Fill.php index 3891bc47..29ff05a7 100644 --- a/src/PhpSpreadsheet/Style/Fill.php +++ b/src/PhpSpreadsheet/Style/Fill.php @@ -135,30 +135,30 @@ class Fill extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['fillType'])) { - $this->setFillType($pStyles['fillType']); + if (isset($styleArray['fillType'])) { + $this->setFillType($styleArray['fillType']); } - if (isset($pStyles['rotation'])) { - $this->setRotation($pStyles['rotation']); + if (isset($styleArray['rotation'])) { + $this->setRotation($styleArray['rotation']); } - if (isset($pStyles['startColor'])) { - $this->getStartColor()->applyFromArray($pStyles['startColor']); + if (isset($styleArray['startColor'])) { + $this->getStartColor()->applyFromArray($styleArray['startColor']); } - if (isset($pStyles['endColor'])) { - $this->getEndColor()->applyFromArray($pStyles['endColor']); + if (isset($styleArray['endColor'])) { + $this->getEndColor()->applyFromArray($styleArray['endColor']); } - if (isset($pStyles['color'])) { - $this->getStartColor()->applyFromArray($pStyles['color']); - $this->getEndColor()->applyFromArray($pStyles['color']); + if (isset($styleArray['color'])) { + $this->getStartColor()->applyFromArray($styleArray['color']); + $this->getEndColor()->applyFromArray($styleArray['color']); } } @@ -182,17 +182,17 @@ class Fill extends Supervisor /** * Set Fill Type. * - * @param string $pValue Fill type, see self::FILL_* + * @param string $fillType Fill type, see self::FILL_* * * @return $this */ - public function setFillType($pValue) + public function setFillType($fillType) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['fillType' => $pValue]); + $styleArray = $this->getStyleArray(['fillType' => $fillType]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->fillType = $pValue; + $this->fillType = $fillType; } return $this; @@ -215,17 +215,17 @@ class Fill extends Supervisor /** * Set Rotation. * - * @param float $pValue + * @param float $angleInDegrees * * @return $this */ - public function setRotation($pValue) + public function setRotation($angleInDegrees) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['rotation' => $pValue]); + $styleArray = $this->getStyleArray(['rotation' => $angleInDegrees]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->rotation = $pValue; + $this->rotation = $angleInDegrees; } return $this; @@ -246,10 +246,10 @@ class Fill extends Supervisor * * @return $this */ - public function setStartColor(Color $pValue) + public function setStartColor(Color $color) { // make sure parameter is a real color and not a supervisor - $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color; if ($this->isSupervisor) { $styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]); @@ -276,10 +276,10 @@ class Fill extends Supervisor * * @return $this */ - public function setEndColor(Color $pValue) + public function setEndColor(Color $color) { // make sure parameter is a real color and not a supervisor - $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color; if ($this->isSupervisor) { $styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]); diff --git a/src/PhpSpreadsheet/Style/Font.php b/src/PhpSpreadsheet/Style/Font.php index ad405708..969cc96a 100644 --- a/src/PhpSpreadsheet/Style/Font.php +++ b/src/PhpSpreadsheet/Style/Font.php @@ -155,41 +155,41 @@ class Font extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['name'])) { - $this->setName($pStyles['name']); + if (isset($styleArray['name'])) { + $this->setName($styleArray['name']); } - if (isset($pStyles['bold'])) { - $this->setBold($pStyles['bold']); + if (isset($styleArray['bold'])) { + $this->setBold($styleArray['bold']); } - if (isset($pStyles['italic'])) { - $this->setItalic($pStyles['italic']); + if (isset($styleArray['italic'])) { + $this->setItalic($styleArray['italic']); } - if (isset($pStyles['superscript'])) { - $this->setSuperscript($pStyles['superscript']); + if (isset($styleArray['superscript'])) { + $this->setSuperscript($styleArray['superscript']); } - if (isset($pStyles['subscript'])) { - $this->setSubscript($pStyles['subscript']); + if (isset($styleArray['subscript'])) { + $this->setSubscript($styleArray['subscript']); } - if (isset($pStyles['underline'])) { - $this->setUnderline($pStyles['underline']); + if (isset($styleArray['underline'])) { + $this->setUnderline($styleArray['underline']); } - if (isset($pStyles['strikethrough'])) { - $this->setStrikethrough($pStyles['strikethrough']); + if (isset($styleArray['strikethrough'])) { + $this->setStrikethrough($styleArray['strikethrough']); } - if (isset($pStyles['color'])) { - $this->getColor()->applyFromArray($pStyles['color']); + if (isset($styleArray['color'])) { + $this->getColor()->applyFromArray($styleArray['color']); } - if (isset($pStyles['size'])) { - $this->setSize($pStyles['size']); + if (isset($styleArray['size'])) { + $this->setSize($styleArray['size']); } } @@ -213,20 +213,20 @@ class Font extends Supervisor /** * Set Name. * - * @param string $pValue + * @param string $fontName * * @return $this */ - public function setName($pValue) + public function setName($fontName) { - if ($pValue == '') { - $pValue = 'Calibri'; + if ($fontName == '') { + $fontName = 'Calibri'; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['name' => $pValue]); + $styleArray = $this->getStyleArray(['name' => $fontName]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->name = $pValue; + $this->name = $fontName; } return $this; @@ -249,20 +249,20 @@ class Font extends Supervisor /** * Set Size. * - * @param float $pValue + * @param float $fontSize * * @return $this */ - public function setSize($pValue) + public function setSize($fontSize) { - if ($pValue == '') { - $pValue = 10; + if ($fontSize == '') { + $fontSize = 10; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['size' => $pValue]); + $styleArray = $this->getStyleArray(['size' => $fontSize]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->size = $pValue; + $this->size = $fontSize; } return $this; @@ -285,20 +285,20 @@ class Font extends Supervisor /** * Set Bold. * - * @param bool $pValue + * @param bool $bold * * @return $this */ - public function setBold($pValue) + public function setBold($bold) { - if ($pValue == '') { - $pValue = false; + if ($bold == '') { + $bold = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['bold' => $pValue]); + $styleArray = $this->getStyleArray(['bold' => $bold]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->bold = $pValue; + $this->bold = $bold; } return $this; @@ -321,20 +321,20 @@ class Font extends Supervisor /** * Set Italic. * - * @param bool $pValue + * @param bool $italic * * @return $this */ - public function setItalic($pValue) + public function setItalic($italic) { - if ($pValue == '') { - $pValue = false; + if ($italic == '') { + $italic = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['italic' => $pValue]); + $styleArray = $this->getStyleArray(['italic' => $italic]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->italic = $pValue; + $this->italic = $italic; } return $this; @@ -359,13 +359,13 @@ class Font extends Supervisor * * @return $this */ - public function setSuperscript(bool $pValue) + public function setSuperscript(bool $superscript) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['superscript' => $pValue]); + $styleArray = $this->getStyleArray(['superscript' => $superscript]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->superscript = $pValue; + $this->superscript = $superscript; if ($this->superscript) { $this->subscript = false; } @@ -393,13 +393,13 @@ class Font extends Supervisor * * @return $this */ - public function setSubscript(bool $pValue) + public function setSubscript(bool $subscript) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['subscript' => $pValue]); + $styleArray = $this->getStyleArray(['subscript' => $subscript]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->subscript = $pValue; + $this->subscript = $subscript; if ($this->subscript) { $this->superscript = false; } @@ -425,24 +425,24 @@ class Font extends Supervisor /** * Set Underline. * - * @param bool|string $pValue \PhpOffice\PhpSpreadsheet\Style\Font underline type + * @param bool|string $underlineStyle \PhpOffice\PhpSpreadsheet\Style\Font underline type * If a boolean is passed, then TRUE equates to UNDERLINE_SINGLE, * false equates to UNDERLINE_NONE * * @return $this */ - public function setUnderline($pValue) + public function setUnderline($underlineStyle) { - if (is_bool($pValue)) { - $pValue = ($pValue) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE; - } elseif ($pValue == '') { - $pValue = self::UNDERLINE_NONE; + if (is_bool($underlineStyle)) { + $underlineStyle = ($underlineStyle) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE; + } elseif ($underlineStyle == '') { + $underlineStyle = self::UNDERLINE_NONE; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['underline' => $pValue]); + $styleArray = $this->getStyleArray(['underline' => $underlineStyle]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->underline = $pValue; + $this->underline = $underlineStyle; } return $this; @@ -465,21 +465,21 @@ class Font extends Supervisor /** * Set Strikethrough. * - * @param bool $pValue + * @param bool $strikethru * * @return $this */ - public function setStrikethrough($pValue) + public function setStrikethrough($strikethru) { - if ($pValue == '') { - $pValue = false; + if ($strikethru == '') { + $strikethru = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['strikethrough' => $pValue]); + $styleArray = $this->getStyleArray(['strikethrough' => $strikethru]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->strikethrough = $pValue; + $this->strikethrough = $strikethru; } return $this; @@ -500,10 +500,10 @@ class Font extends Supervisor * * @return $this */ - public function setColor(Color $pValue) + public function setColor(Color $color) { // make sure parameter is a real color and not a supervisor - $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; + $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color; if ($this->isSupervisor) { $styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]); diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 0b761bd3..d00a352a 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -134,17 +134,17 @@ class NumberFormat extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['formatCode'])) { - $this->setFormatCode($pStyles['formatCode']); + if (isset($styleArray['formatCode'])) { + $this->setFormatCode($styleArray['formatCode']); } } @@ -171,21 +171,21 @@ class NumberFormat extends Supervisor /** * Set Format Code. * - * @param string $pValue see self::FORMAT_* + * @param string $formatCode see self::FORMAT_* * * @return $this */ - public function setFormatCode($pValue) + public function setFormatCode($formatCode) { - if ($pValue == '') { - $pValue = self::FORMAT_GENERAL; + if ($formatCode == '') { + $formatCode = self::FORMAT_GENERAL; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['formatCode' => $pValue]); + $styleArray = $this->getStyleArray(['formatCode' => $formatCode]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->formatCode = $pValue; - $this->builtInFormatCode = self::builtInFormatCodeIndex($pValue); + $this->formatCode = $formatCode; + $this->builtInFormatCode = self::builtInFormatCodeIndex($formatCode); } return $this; @@ -208,18 +208,18 @@ class NumberFormat extends Supervisor /** * Set Built-In Format Code. * - * @param int $pValue + * @param int $formatCodeIndex * * @return $this */ - public function setBuiltInFormatCode($pValue) + public function setBuiltInFormatCode($formatCodeIndex) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($pValue)]); + $styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($formatCodeIndex)]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->builtInFormatCode = $pValue; - $this->formatCode = self::builtInFormatCode($pValue); + $this->builtInFormatCode = $formatCodeIndex; + $this->formatCode = self::builtInFormatCode($formatCodeIndex); } return $this; @@ -331,21 +331,21 @@ class NumberFormat extends Supervisor /** * Get built-in format code. * - * @param int $pIndex + * @param int $index * * @return string */ - public static function builtInFormatCode($pIndex) + public static function builtInFormatCode($index) { // Clean parameter - $pIndex = (int) $pIndex; + $index = (int) $index; // Ensure built-in format codes are available self::fillBuiltInFormatCodes(); // Lookup format code - if (isset(self::$builtInFormats[$pIndex])) { - return self::$builtInFormats[$pIndex]; + if (isset(self::$builtInFormats[$index])) { + return self::$builtInFormats[$index]; } return ''; @@ -354,18 +354,18 @@ class NumberFormat extends Supervisor /** * Get built-in format code index. * - * @param string $formatCode + * @param string $formatCodeIndex * * @return bool|int */ - public static function builtInFormatCodeIndex($formatCode) + public static function builtInFormatCodeIndex($formatCodeIndex) { // Ensure built-in format codes are available self::fillBuiltInFormatCodes(); // Lookup format code - if (array_key_exists($formatCode, self::$flippedBuiltInFormats)) { - return self::$flippedBuiltInFormats[$formatCode]; + if (array_key_exists($formatCodeIndex, self::$flippedBuiltInFormats)) { + return self::$flippedBuiltInFormats[$formatCodeIndex]; } return false; diff --git a/src/PhpSpreadsheet/Style/Protection.php b/src/PhpSpreadsheet/Style/Protection.php index 9ae7d4bb..fc15e3b8 100644 --- a/src/PhpSpreadsheet/Style/Protection.php +++ b/src/PhpSpreadsheet/Style/Protection.php @@ -80,20 +80,20 @@ class Protection extends Supervisor * ); * * - * @param array $pStyles Array containing style information + * @param array $styleArray Array containing style information * * @return $this */ - public function applyFromArray(array $pStyles) + public function applyFromArray(array $styleArray) { if ($this->isSupervisor) { - $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray)); } else { - if (isset($pStyles['locked'])) { - $this->setLocked($pStyles['locked']); + if (isset($styleArray['locked'])) { + $this->setLocked($styleArray['locked']); } - if (isset($pStyles['hidden'])) { - $this->setHidden($pStyles['hidden']); + if (isset($styleArray['hidden'])) { + $this->setHidden($styleArray['hidden']); } } @@ -117,17 +117,17 @@ class Protection extends Supervisor /** * Set locked. * - * @param string $pValue see self::PROTECTION_* + * @param string $lockType see self::PROTECTION_* * * @return $this */ - public function setLocked($pValue) + public function setLocked($lockType) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['locked' => $pValue]); + $styleArray = $this->getStyleArray(['locked' => $lockType]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->locked = $pValue; + $this->locked = $lockType; } return $this; @@ -150,17 +150,17 @@ class Protection extends Supervisor /** * Set hidden. * - * @param string $pValue see self::PROTECTION_* + * @param string $hiddenType see self::PROTECTION_* * * @return $this */ - public function setHidden($pValue) + public function setHidden($hiddenType) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['hidden' => $pValue]); + $styleArray = $this->getStyleArray(['hidden' => $hiddenType]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->hidden = $pValue; + $this->hidden = $hiddenType; } return $this; diff --git a/src/PhpSpreadsheet/Style/Style.php b/src/PhpSpreadsheet/Style/Style.php index 1270b3d7..bb99aaac 100644 --- a/src/PhpSpreadsheet/Style/Style.php +++ b/src/PhpSpreadsheet/Style/Style.php @@ -184,12 +184,12 @@ class Style extends Supervisor * ); * * - * @param array $pStyles Array containing style information - * @param bool $pAdvanced advanced mode for setting borders + * @param array $styleArray Array containing style information + * @param bool $advancedBorders advanced mode for setting borders * * @return $this */ - public function applyFromArray(array $pStyles, $pAdvanced = true) + public function applyFromArray(array $styleArray, $advancedBorders = true) { if ($this->isSupervisor) { $pRange = $this->getSelectedCells(); @@ -221,36 +221,36 @@ class Style extends Supervisor } // ADVANCED MODE: - if ($pAdvanced && isset($pStyles['borders'])) { + if ($advancedBorders && isset($styleArray['borders'])) { // 'allBorders' is a shorthand property for 'outline' and 'inside' and // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['allBorders'])) { + if (isset($styleArray['borders']['allBorders'])) { foreach (['outline', 'inside'] as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['allBorders']; + if (!isset($styleArray['borders'][$component])) { + $styleArray['borders'][$component] = $styleArray['borders']['allBorders']; } } - unset($pStyles['borders']['allBorders']); // not needed any more + unset($styleArray['borders']['allBorders']); // not needed any more } // 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left' // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['outline'])) { + if (isset($styleArray['borders']['outline'])) { foreach (['top', 'right', 'bottom', 'left'] as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['outline']; + if (!isset($styleArray['borders'][$component])) { + $styleArray['borders'][$component] = $styleArray['borders']['outline']; } } - unset($pStyles['borders']['outline']); // not needed any more + unset($styleArray['borders']['outline']); // not needed any more } // 'inside' is a shorthand property for 'vertical' and 'horizontal' // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['inside'])) { + if (isset($styleArray['borders']['inside'])) { foreach (['vertical', 'horizontal'] as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['inside']; + if (!isset($styleArray['borders'][$component])) { + $styleArray['borders'][$component] = $styleArray['borders']['inside']; } } - unset($pStyles['borders']['inside']); // not needed any more + unset($styleArray['borders']['inside']); // not needed any more } // width and height characteristics of selection, 1, 2, or 3 (for 3 or more) $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3); @@ -299,7 +299,7 @@ class Style extends Supervisor $range = $colStart . $rowStart . ':' . $colEnd . $rowEnd; // retrieve relevant style array for region - $regionStyles = $pStyles; + $regionStyles = $styleArray; unset($regionStyles['borders']['inside']); // what are the inner edges of the region when looking at the selection @@ -311,8 +311,8 @@ class Style extends Supervisor case 'top': case 'bottom': // should pick up 'horizontal' border property if set - if (isset($pStyles['borders']['horizontal'])) { - $regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal']; + if (isset($styleArray['borders']['horizontal'])) { + $regionStyles['borders'][$innerEdge] = $styleArray['borders']['horizontal']; } else { unset($regionStyles['borders'][$innerEdge]); } @@ -321,8 +321,8 @@ class Style extends Supervisor case 'left': case 'right': // should pick up 'vertical' border property if set - if (isset($pStyles['borders']['vertical'])) { - $regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical']; + if (isset($styleArray['borders']['vertical'])) { + $regionStyles['borders'][$innerEdge] = $styleArray['borders']['vertical']; } else { unset($regionStyles['borders'][$innerEdge]); } @@ -388,7 +388,7 @@ class Style extends Supervisor foreach ($oldXfIndexes as $oldXfIndex => $dummy) { $style = $workbook->getCellXfByIndex($oldXfIndex); $newStyle = clone $style; - $newStyle->applyFromArray($pStyles); + $newStyle->applyFromArray($styleArray); if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) { // there is already such cell Xf in our collection @@ -432,26 +432,26 @@ class Style extends Supervisor } } else { // not a supervisor, just apply the style array directly on style object - if (isset($pStyles['fill'])) { - $this->getFill()->applyFromArray($pStyles['fill']); + if (isset($styleArray['fill'])) { + $this->getFill()->applyFromArray($styleArray['fill']); } - if (isset($pStyles['font'])) { - $this->getFont()->applyFromArray($pStyles['font']); + if (isset($styleArray['font'])) { + $this->getFont()->applyFromArray($styleArray['font']); } - if (isset($pStyles['borders'])) { - $this->getBorders()->applyFromArray($pStyles['borders']); + if (isset($styleArray['borders'])) { + $this->getBorders()->applyFromArray($styleArray['borders']); } - if (isset($pStyles['alignment'])) { - $this->getAlignment()->applyFromArray($pStyles['alignment']); + if (isset($styleArray['alignment'])) { + $this->getAlignment()->applyFromArray($styleArray['alignment']); } - if (isset($pStyles['numberFormat'])) { - $this->getNumberFormat()->applyFromArray($pStyles['numberFormat']); + if (isset($styleArray['numberFormat'])) { + $this->getNumberFormat()->applyFromArray($styleArray['numberFormat']); } - if (isset($pStyles['protection'])) { - $this->getProtection()->applyFromArray($pStyles['protection']); + if (isset($styleArray['protection'])) { + $this->getProtection()->applyFromArray($styleArray['protection']); } - if (isset($pStyles['quotePrefix'])) { - $this->quotePrefix = $pStyles['quotePrefix']; + if (isset($styleArray['quotePrefix'])) { + $this->quotePrefix = $styleArray['quotePrefix']; } } @@ -533,13 +533,13 @@ class Style extends Supervisor /** * Set Conditional Styles. Only used on supervisor. * - * @param Conditional[] $pValue Array of conditional styles + * @param Conditional[] $conditionalStyleArray Array of conditional styles * * @return $this */ - public function setConditionalStyles(array $pValue) + public function setConditionalStyles(array $conditionalStyleArray) { - $this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $pValue); + $this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $conditionalStyleArray); return $this; } @@ -571,20 +571,20 @@ class Style extends Supervisor /** * Set quote prefix. * - * @param bool $pValue + * @param bool $quotePrefix * * @return $this */ - public function setQuotePrefix($pValue) + public function setQuotePrefix($quotePrefix) { - if ($pValue == '') { - $pValue = false; + if ($quotePrefix == '') { + $quotePrefix = false; } if ($this->isSupervisor) { - $styleArray = ['quotePrefix' => $pValue]; + $styleArray = ['quotePrefix' => $quotePrefix]; $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->quotePrefix = (bool) $pValue; + $this->quotePrefix = (bool) $quotePrefix; } return $this; @@ -628,11 +628,11 @@ class Style extends Supervisor /** * Set own index in style collection. * - * @param int $pValue + * @param int $index */ - public function setIndex($pValue): void + public function setIndex($index): void { - $this->index = $pValue; + $this->index = $index; } protected function exportArray1(): array From d558e2ba99dec20c6ddf5074556052cef2471c4a Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 5 Nov 2020 21:20:33 +0100 Subject: [PATCH 25/41] Datatype fix --- src/PhpSpreadsheet/HashTable.php | 2 +- src/PhpSpreadsheet/Helper/Size.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index e615b060..445addd6 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -111,7 +111,7 @@ class HashTable * * @param string $hashCode * - * @return int Index + * @return false|int Index */ public function getIndexForHashCode($hashCode) { diff --git a/src/PhpSpreadsheet/Helper/Size.php b/src/PhpSpreadsheet/Helper/Size.php index 12bccaad..80b6fbd7 100644 --- a/src/PhpSpreadsheet/Helper/Size.php +++ b/src/PhpSpreadsheet/Helper/Size.php @@ -14,7 +14,7 @@ class Size public function __construct(string $size) { - $this->valid = preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches); + $this->valid = (bool) preg_match(self::REGEXP_SIZE_VALIDATION, $size, $matches); if ($this->valid) { $this->size = $matches['size']; $this->unit = $matches['unit'] ?? 'pt'; From 3f3a3174b5cf27ddf0741435f86ff9914186872a Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 6 Nov 2020 19:48:32 +0100 Subject: [PATCH 26/41] Scrutinizer tweaks --- src/PhpSpreadsheet/Chart/Axis.php | 2 +- src/PhpSpreadsheet/Chart/GridLines.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Chart/Axis.php b/src/PhpSpreadsheet/Chart/Axis.php index 1f5ae152..5f235c3d 100644 --- a/src/PhpSpreadsheet/Chart/Axis.php +++ b/src/PhpSpreadsheet/Chart/Axis.php @@ -341,7 +341,7 @@ class Axis extends Properties $this->setShadowPresetsProperties((int) $shadowPresets) ->setShadowColor( $colorValue === null ? $this->shadowProperties['color']['value'] : $colorValue, - $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $colorAlpha, + $colorAlpha === null ? $this->shadowProperties['color']['alpha'] : $colorAlpha, $colorType === null ? $this->shadowProperties['color']['type'] : $colorType ) ->setShadowBlur($blur) diff --git a/src/PhpSpreadsheet/Chart/GridLines.php b/src/PhpSpreadsheet/Chart/GridLines.php index ca9ed555..6093a60e 100644 --- a/src/PhpSpreadsheet/Chart/GridLines.php +++ b/src/PhpSpreadsheet/Chart/GridLines.php @@ -281,7 +281,7 @@ class GridLines extends Properties * @param int $presets * @param string $colorValue * @param string $colorType - * @param int $colorAlpha + * @param string $colorAlpha * @param string $blur * @param int $angle * @param float $distance @@ -292,7 +292,7 @@ class GridLines extends Properties ->setShadowPresetsProperties((int) $presets) ->setShadowColor( $colorValue === null ? $this->shadowProperties['color']['value'] : $colorValue, - $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha), + $colorAlpha === null ? $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha), $colorType === null ? $this->shadowProperties['color']['type'] : $colorType ) ->setShadowBlur($blur) From 34d15b80de2ade851d0a705bb18f3340c5e3f222 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sat, 7 Nov 2020 17:41:58 +0100 Subject: [PATCH 27/41] Lets try some moew modern annotations for index key/value typing --- src/PhpSpreadsheet/HashTable.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index 445addd6..50446ffc 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -7,14 +7,14 @@ class HashTable /** * HashTable elements. * - * @var IComparable[] + * @var array */ protected $items = []; /** * HashTable key map. * - * @var string[] + * @var array */ protected $keyMap = []; @@ -115,7 +115,7 @@ class HashTable */ public function getIndexForHashCode($hashCode) { - return array_search($hashCode, $this->keyMap); + return array_search($hashCode, $this->keyMap, true); } /** @@ -125,7 +125,7 @@ class HashTable * * @return IComparable */ - public function getByIndex($index) + public function getByIndex(int $index) { if (isset($this->keyMap[$index])) { return $this->getByHashCode($this->keyMap[$index]); @@ -141,7 +141,7 @@ class HashTable * * @return IComparable */ - public function getByHashCode($hashCode) + public function getByHashCode(string $hashCode) { if (isset($this->items[$hashCode])) { return $this->items[$hashCode]; From 6e497a5fd638ee406fb40381a96a25aca8c3f8dc Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sat, 7 Nov 2020 20:14:32 +0100 Subject: [PATCH 28/41] Lets try some more modern annotations for index key/value typing --- src/PhpSpreadsheet/HashTable.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index 50446ffc..3bd01557 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -19,7 +19,7 @@ class HashTable protected $keyMap = []; /** - * Create a new \PhpOffice\PhpSpreadsheet\HashTable. + * Create a new HashTable. * * @param IComparable[] $source Optional source array to create HashTable from */ @@ -39,7 +39,7 @@ class HashTable public function addFromSource(?array $source = null): void { // Check if an array was passed - if ($source == null) { + if ($source === null) { return; } @@ -109,11 +109,9 @@ class HashTable /** * Get index for hash code. * - * @param string $hashCode - * * @return false|int Index */ - public function getIndexForHashCode($hashCode) + public function getIndexForHashCode(string $hashCode) { return array_search($hashCode, $this->keyMap, true); } @@ -121,8 +119,6 @@ class HashTable /** * Get by index. * - * @param int $index - * * @return IComparable */ public function getByIndex(int $index) @@ -137,8 +133,6 @@ class HashTable /** * Get by hashcode. * - * @param string $hashCode - * * @return IComparable */ public function getByHashCode(string $hashCode) From 3ad919575dd87a236fc429c17bda0781efa42d19 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 14:45:37 +0100 Subject: [PATCH 29/41] See if we can sort out scrutinizer's issue with the hash map --- .../Calculation/Calculation.php | 38 +++++++++---------- src/PhpSpreadsheet/HashTable.php | 8 +++- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 99260e3b..99287721 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -5117,47 +5117,47 @@ class Calculation /** * Extract range values. * - * @param string &$pRange String based range representation - * @param Worksheet $pSheet Worksheet + * @param string &$range String based range representation + * @param null|Worksheet $worksheet Worksheet * @param bool $resetLog Flag indicating whether calculation log should be reset or not * * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned. */ - public function extractNamedRange(&$pRange = 'A1', ?Worksheet $pSheet = null, $resetLog = true) + public function extractNamedRange(&$range = 'A1', ?Worksheet $worksheet = null, $resetLog = true) { // Return value $returnValue = []; - if ($pSheet !== null) { - $pSheetName = $pSheet->getTitle(); - if (strpos($pRange, '!') !== false) { - [$pSheetName, $pRange] = Worksheet::extractSheetTitle($pRange, true); - $pSheet = $this->spreadsheet->getSheetByName($pSheetName); + if ($worksheet !== null) { + $pSheetName = $worksheet->getTitle(); + if (strpos($range, '!') !== false) { + [$pSheetName, $range] = Worksheet::extractSheetTitle($range, true); + $worksheet = $this->spreadsheet->getSheetByName($pSheetName); } // Named range? - $namedRange = DefinedName::resolveName($pRange, $pSheet); + $namedRange = DefinedName::resolveName($range, $worksheet); if ($namedRange === null) { return Functions::REF(); } - $pSheet = $namedRange->getWorksheet(); - $pRange = $namedRange->getValue(); - $splitRange = Coordinate::splitRange($pRange); + $worksheet = $namedRange->getWorksheet(); + $range = $namedRange->getValue(); + $splitRange = Coordinate::splitRange($range); // Convert row and column references if (ctype_alpha($splitRange[0][0])) { - $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow(); + $range = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow(); } elseif (ctype_digit($splitRange[0][0])) { - $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1]; + $range = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1]; } // Extract range - $aReferences = Coordinate::extractAllCellReferencesInRange($pRange); + $aReferences = Coordinate::extractAllCellReferencesInRange($range); if (!isset($aReferences[1])) { // Single cell (or single column or row) in range [$currentCol, $currentRow] = Coordinate::coordinateFromString($aReferences[0]); - if ($pSheet->cellExists($aReferences[0])) { - $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog); + if ($worksheet->cellExists($aReferences[0])) { + $returnValue[$currentRow][$currentCol] = $worksheet->getCell($aReferences[0])->getCalculatedValue($resetLog); } else { $returnValue[$currentRow][$currentCol] = null; } @@ -5166,8 +5166,8 @@ class Calculation foreach ($aReferences as $reference) { // Extract range [$currentCol, $currentRow] = Coordinate::coordinateFromString($reference); - if ($pSheet->cellExists($reference)) { - $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog); + if ($worksheet->cellExists($reference)) { + $returnValue[$currentRow][$currentCol] = $worksheet->getCell($reference)->getCalculatedValue($resetLog); } else { $returnValue[$currentRow][$currentCol] = null; } diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index 3bd01557..0fb56c9f 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -113,7 +113,13 @@ class HashTable */ public function getIndexForHashCode(string $hashCode) { - return array_search($hashCode, $this->keyMap, true); + $matched = array_search($hashCode, $this->keyMap, true); + + if ($matched === false) { + return $matched; + } + + return (int) $matched; } /** From 6bf24d8aacae61fc695e808b8ece41aec830e667 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 17:34:44 +0100 Subject: [PATCH 30/41] See if we can sort out scrutinizer's issue with the hash map --- src/PhpSpreadsheet/HashTable.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/PhpSpreadsheet/HashTable.php b/src/PhpSpreadsheet/HashTable.php index 0fb56c9f..f433e237 100644 --- a/src/PhpSpreadsheet/HashTable.php +++ b/src/PhpSpreadsheet/HashTable.php @@ -109,17 +109,11 @@ class HashTable /** * Get index for hash code. * - * @return false|int Index + * @return false|int|string Index (return should never be a string, but scrutinizer refuses to recognise that) */ public function getIndexForHashCode(string $hashCode) { - $matched = array_search($hashCode, $this->keyMap, true); - - if ($matched === false) { - return $matched; - } - - return (int) $matched; + return array_search($hashCode, $this->keyMap, true); } /** From d6f2180fa0c27d30b66c14aed8564faa9307cb09 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 18:14:38 +0100 Subject: [PATCH 31/41] Keep scrutinizer happy --- src/PhpSpreadsheet/Reader/Xlsx.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 3a75edf6..3674667a 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1138,12 +1138,12 @@ class Xlsx extends BaseReader $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx'))); $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cy'))); if ($xfrm) { - $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem($xfrm->attributes(), 'rot'))); + $objDrawing->setRotation(Drawing::angleToDegrees((int) self::getArrayItem($xfrm->attributes(), 'rot'))); } if ($outerShdw) { $shadow = $objDrawing->getShadow(); $shadow->setVisible(true); - $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'blurRad'))); + $shadow->setBlurRadius(Drawing::EMUToPixels((int) self::getArrayItem($outerShdw->attributes(), 'blurRad'))); $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); @@ -1563,7 +1563,7 @@ class Xlsx extends BaseReader // font if (isset($style->font)) { $docStyle->getFont()->setName((string) $style->font->name['val']); - $docStyle->getFont()->setSize((string) $style->font->sz['val']); + $docStyle->getFont()->setSize((float) $style->font->sz['val']); if (isset($style->font->b)) { $docStyle->getFont()->setBold(!isset($style->font->b['val']) || self::boolean((string) $style->font->b['val'])); } @@ -1676,7 +1676,7 @@ class Xlsx extends BaseReader // top-level style settings if (isset($style->quotePrefix)) { - $docStyle->setQuotePrefix($style->quotePrefix); + $docStyle->setQuotePrefix((bool) $style->quotePrefix); } } From d311603c6b8a2f9ca08edb251a262ec2335f578b Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 19:48:32 +0100 Subject: [PATCH 32/41] Typecasting fixes --- src/PhpSpreadsheet/Reader/Xlsx.php | 4 ++-- src/PhpSpreadsheet/Shared/Xls.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 3674667a..22584c51 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1144,8 +1144,8 @@ class Xlsx extends BaseReader $shadow = $objDrawing->getShadow(); $shadow->setVisible(true); $shadow->setBlurRadius(Drawing::EMUToPixels((int) self::getArrayItem($outerShdw->attributes(), 'blurRad'))); - $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); - $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); + $shadow->setDistance(Drawing::EMUToPixels((int) self::getArrayItem($outerShdw->attributes(), 'dist'))); + $shadow->setDirection(Drawing::angleToDegrees((int) self::getArrayItem($outerShdw->attributes(), 'dir'))); $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); $clr = isset($outerShdw->srgbClr) ? $outerShdw->srgbClr : $outerShdw->prstClr; $shadow->getColor()->setRGB(self::getArrayItem($clr->attributes(), 'val')); diff --git a/src/PhpSpreadsheet/Shared/Xls.php b/src/PhpSpreadsheet/Shared/Xls.php index 41cd0c50..f6c95e72 100644 --- a/src/PhpSpreadsheet/Shared/Xls.php +++ b/src/PhpSpreadsheet/Shared/Xls.php @@ -77,7 +77,7 @@ class Xls // then we have a default row dimension with explicit height $defaultRowDimension = $worksheet->getDefaultRowDimension(); $rowHeight = $defaultRowDimension->getRowHeight(); - $pixelRowHeight = Drawing::pointsToPixels($rowHeight); + $pixelRowHeight = Drawing::pointsToPixels((int) $rowHeight); } else { // we don't even have any default row dimension. Height depends on default font $pointRowHeight = Font::getDefaultRowHeightByFont($font); From 1626f5931b266d6e984c79407b08770bc2faf8f3 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 20:19:19 +0100 Subject: [PATCH 33/41] Scrutinizer fixes --- src/PhpSpreadsheet/Chart/GridLines.php | 2 +- src/PhpSpreadsheet/ReferenceHelper.php | 35 +++++++++----------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/PhpSpreadsheet/Chart/GridLines.php b/src/PhpSpreadsheet/Chart/GridLines.php index 6093a60e..fb789d76 100644 --- a/src/PhpSpreadsheet/Chart/GridLines.php +++ b/src/PhpSpreadsheet/Chart/GridLines.php @@ -295,7 +295,7 @@ class GridLines extends Properties $colorAlpha === null ? $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha), $colorType === null ? $this->shadowProperties['color']['type'] : $colorType ) - ->setShadowBlur($blur) + ->setShadowBlur((float) $blur) ->setShadowAngle($angle) ->setShadowDistance($distance); } diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 09b88b25..453447f9 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -212,12 +212,10 @@ class ReferenceHelper * * @param Worksheet $worksheet The worksheet that we're editing * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) - * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void + protected function adjustHyperlinks($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows): void { $aHyperlinkCollection = $worksheet->getHyperlinkCollection(); ($numberOfColumns > 0 || $numberOfRows > 0) ? @@ -237,12 +235,10 @@ class ReferenceHelper * * @param Worksheet $pSheet The worksheet that we're editing * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) - * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustDataValidations(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustDataValidations(Worksheet $pSheet, $pBefore, $pNumCols, $pNumRows): void { $aDataValidationCollection = $pSheet->getDataValidationCollection(); ($pNumCols > 0 || $pNumRows > 0) ? @@ -262,12 +258,10 @@ class ReferenceHelper * * @param Worksheet $worksheet The worksheet that we're editing * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) - * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustMergeCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void + protected function adjustMergeCells(Worksheet $worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows): void { $aMergeCells = $worksheet->getMergeCells(); $aNewMergeCells = []; // the new array of all merge cells @@ -283,12 +277,10 @@ class ReferenceHelper * * @param Worksheet $worksheet The worksheet that we're editing * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) - * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustProtectedCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void + protected function adjustProtectedCells(Worksheet $worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows): void { $aProtectedCells = $worksheet->getProtectedCells(); ($numberOfColumns > 0 || $numberOfRows > 0) ? @@ -307,12 +299,10 @@ class ReferenceHelper * * @param Worksheet $worksheet The worksheet that we're editing * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) - * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustColumnDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void + protected function adjustColumnDimensions(Worksheet $worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows): void { $aColumnDimensions = array_reverse($worksheet->getColumnDimensions(), true); if (!empty($aColumnDimensions)) { @@ -332,12 +322,11 @@ class ReferenceHelper * * @param Worksheet $worksheet The worksheet that we're editing * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') - * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustRowDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void + protected function adjustRowDimensions(Worksheet $worksheet, $beforeCellAddress, $numberOfColumns, $beforeRow, $numberOfRows): void { $aRowDimensions = array_reverse($worksheet->getRowDimensions(), true); if (!empty($aRowDimensions)) { @@ -502,10 +491,10 @@ class ReferenceHelper } // Update worksheet: column dimensions - $this->adjustColumnDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustColumnDimensions($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: row dimensions - $this->adjustRowDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustRowDimensions($worksheet, $beforeCellAddress, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: page breaks $this->adjustPageBreaks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); @@ -514,16 +503,16 @@ class ReferenceHelper $this->adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: hyperlinks - $this->adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustHyperlinks($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: data validations - $this->adjustDataValidations($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustDataValidations($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: merge cells - $this->adjustMergeCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustMergeCells($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: protected cells - $this->adjustProtectedCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustProtectedCells($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: autofilter $autoFilter = $worksheet->getAutoFilter(); From 575ff5509cd128292abf89b560f8e109aaee012b Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 21:03:39 +0100 Subject: [PATCH 34/41] Cell row should be an int --- src/PhpSpreadsheet/Cell/Coordinate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index d2bc6e0a..7ceec156 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -30,7 +30,7 @@ abstract class Coordinate public static function coordinateFromString($cellAddress) { if (preg_match('/^([$]?[A-Z]{1,3})([$]?\\d{1,7})$/', $cellAddress, $matches)) { - return [$matches[1], $matches[2]]; + return [$matches[1], (int) $matches[2]]; } elseif (self::coordinateIsRange($cellAddress)) { throw new Exception('Cell coordinate string can not be a range of cells'); } elseif ($cellAddress == '') { From 29e0a8a6e81d12a821ad4e670b5eca38f1aba782 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 21:09:21 +0100 Subject: [PATCH 35/41] Revert --- src/PhpSpreadsheet/Cell/Coordinate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 7ceec156..d2bc6e0a 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -30,7 +30,7 @@ abstract class Coordinate public static function coordinateFromString($cellAddress) { if (preg_match('/^([$]?[A-Z]{1,3})([$]?\\d{1,7})$/', $cellAddress, $matches)) { - return [$matches[1], (int) $matches[2]]; + return [$matches[1], $matches[2]]; } elseif (self::coordinateIsRange($cellAddress)) { throw new Exception('Cell coordinate string can not be a range of cells'); } elseif ($cellAddress == '') { From 97f82c83de49004214dc386bd656b8e6340caaed Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 16 Nov 2020 21:45:05 +0100 Subject: [PATCH 36/41] Type-hinting fixes --- src/PhpSpreadsheet/ReferenceHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 453447f9..ef95b893 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -494,13 +494,13 @@ class ReferenceHelper $this->adjustColumnDimensions($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); // Update worksheet: row dimensions - $this->adjustRowDimensions($worksheet, $beforeCellAddress, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustRowDimensions($worksheet, $beforeCellAddress, $numberOfColumns, (int) $beforeRow, $numberOfRows); // Update worksheet: page breaks - $this->adjustPageBreaks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustPageBreaks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, (int) $beforeRow, $numberOfRows); // Update worksheet: comments - $this->adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); + $this->adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, (int) $beforeRow, $numberOfRows); // Update worksheet: hyperlinks $this->adjustHyperlinks($worksheet, $beforeCellAddress, $numberOfColumns, $numberOfRows); From bd0462bcfcff091b16b85ff8f0a163ba3b15cb8d Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 19 Nov 2020 16:41:52 +0100 Subject: [PATCH 37/41] Work on renaming method arguments for the Readers and Writers --- samples/Basic/24_Readfilter.php | 2 +- ...Simple_file_reader_using_a_read_filter.php | 4 +- ...eader_using_a_configurable_read_filter.php | 4 +- ...a_configurable_read_filter_(version_1).php | 2 +- ...a_configurable_read_filter_(version_2).php | 2 +- ...ks_to_split_across_multiple_worksheets.php | 2 +- src/PhpSpreadsheet/Reader/BaseReader.php | 34 ++++++------- src/PhpSpreadsheet/Reader/Csv.php | 50 +++++++++---------- .../Reader/DefaultReadFilter.php | 4 +- src/PhpSpreadsheet/Reader/Gnumeric.php | 14 +++--- src/PhpSpreadsheet/Reader/Html.php | 12 ++--- src/PhpSpreadsheet/Reader/IReadFilter.php | 4 +- src/PhpSpreadsheet/Reader/IReader.php | 26 +++++----- src/PhpSpreadsheet/Reader/Ods.php | 14 +++--- src/PhpSpreadsheet/Reader/Slk.php | 12 ++--- src/PhpSpreadsheet/Reader/Xls.php | 14 +++--- src/PhpSpreadsheet/Reader/Xlsx.php | 22 ++++---- src/PhpSpreadsheet/Reader/Xml.php | 12 ++--- src/PhpSpreadsheet/Writer/BaseWriter.php | 20 ++++---- src/PhpSpreadsheet/Writer/Csv.php | 6 +-- src/PhpSpreadsheet/Writer/Html.php | 6 +-- src/PhpSpreadsheet/Writer/IWriter.php | 20 ++++---- src/PhpSpreadsheet/Writer/Ods.php | 6 +-- src/PhpSpreadsheet/Writer/Pdf.php | 28 +++++------ src/PhpSpreadsheet/Writer/Pdf/Dompdf.php | 6 +-- src/PhpSpreadsheet/Writer/Pdf/Mpdf.php | 6 +-- src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php | 8 +-- src/PhpSpreadsheet/Writer/Xls.php | 6 +-- src/PhpSpreadsheet/Writer/Xlsx.php | 6 +-- .../Reader/CsvContiguousFilter.php | 2 +- .../Reader/Gnumeric/GnumericFilter.php | 2 +- .../Reader/OddColumnReadFilter.php | 4 +- .../Reader/Xml/XmlFilter.php | 2 +- 33 files changed, 182 insertions(+), 180 deletions(-) diff --git a/samples/Basic/24_Readfilter.php b/samples/Basic/24_Readfilter.php index ab1c2e41..e5b613a6 100644 --- a/samples/Basic/24_Readfilter.php +++ b/samples/Basic/24_Readfilter.php @@ -18,7 +18,7 @@ $helper->logWrite($writer, $filename, $callStartTime); class MyReadFilter implements IReadFilter { - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { diff --git a/samples/Reader/09_Simple_file_reader_using_a_read_filter.php b/samples/Reader/09_Simple_file_reader_using_a_read_filter.php index 6e0eda14..04c47c64 100644 --- a/samples/Reader/09_Simple_file_reader_using_a_read_filter.php +++ b/samples/Reader/09_Simple_file_reader_using_a_read_filter.php @@ -13,11 +13,11 @@ $sheetname = 'Data Sheet #3'; class MyReadFilter implements IReadFilter { - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { // Read rows 1 to 7 and columns A to E only if ($row >= 1 && $row <= 7) { - if (in_array($column, range('A', 'E'))) { + if (in_array($columnAddress, range('A', 'E'))) { return true; } } diff --git a/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php b/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php index 7b3fc440..6a600d43 100644 --- a/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php +++ b/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php @@ -26,10 +26,10 @@ class MyReadFilter implements IReadFilter $this->columns = $columns; } - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { if ($row >= $this->startRow && $row <= $this->endRow) { - if (in_array($column, $this->columns)) { + if (in_array($columnAddress, $this->columns)) { return true; } } diff --git a/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php b/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php index 18562217..6c908703 100644 --- a/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php +++ b/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php @@ -29,7 +29,7 @@ class ChunkReadFilter implements IReadFilter $this->endRow = $startRow + $chunkSize; } - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { // Only read the heading row, and the rows that were configured in the constructor if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) { diff --git a/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php b/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php index 61f624b2..c594c798 100644 --- a/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php +++ b/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php @@ -29,7 +29,7 @@ class ChunkReadFilter implements IReadFilter $this->endRow = $startRow + $chunkSize; } - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) { diff --git a/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php b/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php index 02d3d939..87fbb225 100644 --- a/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php +++ b/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php @@ -30,7 +30,7 @@ class ChunkReadFilter implements IReadFilter $this->endRow = $startRow + $chunkSize; } - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) { diff --git a/src/PhpSpreadsheet/Reader/BaseReader.php b/src/PhpSpreadsheet/Reader/BaseReader.php index eb0e3ba2..9804b57b 100644 --- a/src/PhpSpreadsheet/Reader/BaseReader.php +++ b/src/PhpSpreadsheet/Reader/BaseReader.php @@ -66,9 +66,9 @@ abstract class BaseReader implements IReader return $this->readDataOnly; } - public function setReadDataOnly($pValue) + public function setReadDataOnly($readCellValuesOnly) { - $this->readDataOnly = (bool) $pValue; + $this->readDataOnly = (bool) $readCellValuesOnly; return $this; } @@ -78,9 +78,9 @@ abstract class BaseReader implements IReader return $this->readEmptyCells; } - public function setReadEmptyCells($pValue) + public function setReadEmptyCells($readEmptyCells) { - $this->readEmptyCells = (bool) $pValue; + $this->readEmptyCells = (bool) $readEmptyCells; return $this; } @@ -90,9 +90,9 @@ abstract class BaseReader implements IReader return $this->includeCharts; } - public function setIncludeCharts($pValue) + public function setIncludeCharts($includeCharts) { - $this->includeCharts = (bool) $pValue; + $this->includeCharts = (bool) $includeCharts; return $this; } @@ -102,13 +102,13 @@ abstract class BaseReader implements IReader return $this->loadSheetsOnly; } - public function setLoadSheetsOnly($value) + public function setLoadSheetsOnly($sheetList) { - if ($value === null) { + if ($sheetList === null) { return $this->setLoadAllSheets(); } - $this->loadSheetsOnly = is_array($value) ? $value : [$value]; + $this->loadSheetsOnly = is_array($sheetList) ? $sheetList : [$sheetList]; return $this; } @@ -125,9 +125,9 @@ abstract class BaseReader implements IReader return $this->readFilter; } - public function setReadFilter(IReadFilter $pValue) + public function setReadFilter(IReadFilter $readFilter) { - $this->readFilter = $pValue; + $this->readFilter = $readFilter; return $this; } @@ -140,22 +140,22 @@ abstract class BaseReader implements IReader /** * Open file for reading. * - * @param string $pFilename + * @param string $filename */ - protected function openFile($pFilename): void + protected function openFile($filename): void { - if ($pFilename) { - File::assertFile($pFilename); + if ($filename) { + File::assertFile($filename); // Open file - $fileHandle = fopen($pFilename, 'rb'); + $fileHandle = fopen($filename, 'rb'); } else { $fileHandle = false; } if ($fileHandle !== false) { $this->fileHandle = $fileHandle; } else { - throw new ReaderException('Could not open file ' . $pFilename . ' for reading.'); + throw new ReaderException('Could not open file ' . $filename . ' for reading.'); } } } diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index d6eb16b0..3fd95e14 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -62,13 +62,13 @@ class Csv extends BaseReader /** * Set input encoding. * - * @param string $pValue Input encoding, eg: 'UTF-8' + * @param string $encoding Input encoding, eg: 'UTF-8' * * @return $this */ - public function setInputEncoding($pValue) + public function setInputEncoding($encoding) { - $this->inputEncoding = $pValue; + $this->inputEncoding = $encoding; return $this; } @@ -240,14 +240,14 @@ class Csv extends BaseReader /** * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns). * - * @param string $pFilename + * @param string $filename * * @return array */ - public function listWorksheetInfo($pFilename) + public function listWorksheetInfo($filename) { // Open file - $this->openFileOrMemory($pFilename); + $this->openFileOrMemory($filename); $fileHandle = $this->fileHandle; // Skip BOM, if any @@ -280,30 +280,30 @@ class Csv extends BaseReader /** * Loads Spreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } - private function openFileOrMemory($pFilename): void + private function openFileOrMemory($filename): void { // Open file - $fhandle = $this->canRead($pFilename); + $fhandle = $this->canRead($filename); if (!$fhandle) { - throw new Exception($pFilename . ' is an Invalid Spreadsheet file.'); + throw new Exception($filename . ' is an Invalid Spreadsheet file.'); } - $this->openFile($pFilename); + $this->openFile($filename); if ($this->inputEncoding !== 'UTF-8') { fclose($this->fileHandle); - $entireFile = file_get_contents($pFilename); + $entireFile = file_get_contents($filename); $this->fileHandle = fopen('php://memory', 'r+b'); $data = StringHelper::convertEncoding($entireFile, 'UTF-8', $this->inputEncoding); fwrite($this->fileHandle, $data); @@ -314,17 +314,17 @@ class Csv extends BaseReader /** * Loads PhpSpreadsheet from file into PhpSpreadsheet instance. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) + public function loadIntoExisting($filename, Spreadsheet $spreadsheet) { $lineEnding = ini_get('auto_detect_line_endings'); ini_set('auto_detect_line_endings', true); // Open file - $this->openFileOrMemory($pFilename); + $this->openFileOrMemory($filename); $fileHandle = $this->fileHandle; // Skip BOM, if any @@ -437,13 +437,13 @@ class Csv extends BaseReader /** * Set sheet index. * - * @param int $pValue Sheet index + * @param int $indexValue Sheet index * * @return $this */ - public function setSheetIndex($pValue) + public function setSheetIndex($indexValue) { - $this->sheetIndex = $pValue; + $this->sheetIndex = $indexValue; return $this; } @@ -499,15 +499,15 @@ class Csv extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { // Check if file exists try { - $this->openFile($pFilename); + $this->openFile($filename); } catch (InvalidArgumentException $e) { return false; } @@ -515,13 +515,13 @@ class Csv extends BaseReader fclose($this->fileHandle); // Trust file extension if any - $extension = strtolower(pathinfo($pFilename, PATHINFO_EXTENSION)); + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (in_array($extension, ['csv', 'tsv'])) { return true; } // Attempt to guess mimetype - $type = mime_content_type($pFilename); + $type = mime_content_type($filename); $supportedTypes = [ 'application/csv', 'text/csv', diff --git a/src/PhpSpreadsheet/Reader/DefaultReadFilter.php b/src/PhpSpreadsheet/Reader/DefaultReadFilter.php index e104186a..8fdb162b 100644 --- a/src/PhpSpreadsheet/Reader/DefaultReadFilter.php +++ b/src/PhpSpreadsheet/Reader/DefaultReadFilter.php @@ -7,13 +7,13 @@ class DefaultReadFilter implements IReadFilter /** * Should this cell be read? * - * @param string $column Column address (as a string value like "A", or "IV") + * @param string $columnAddress Column address (as a string value like "A", or "IV") * @param int $row Row number * @param string $worksheetName Optional worksheet name * * @return bool */ - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { return true; } diff --git a/src/PhpSpreadsheet/Reader/Gnumeric.php b/src/PhpSpreadsheet/Reader/Gnumeric.php index dc921c1e..7f583663 100644 --- a/src/PhpSpreadsheet/Reader/Gnumeric.php +++ b/src/PhpSpreadsheet/Reader/Gnumeric.php @@ -63,19 +63,19 @@ class Gnumeric extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { - File::assertFile($pFilename); + File::assertFile($filename); // Check if gzlib functions are available $data = ''; if (function_exists('gzread')) { // Read signature data (first 3 bytes) - $fh = fopen($pFilename, 'rb'); + $fh = fopen($filename, 'rb'); $data = fread($fh, 2); fclose($fh); } @@ -420,18 +420,18 @@ class Gnumeric extends BaseReader /** * Loads Spreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); $spreadsheet->removeSheetByIndex(0); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } /** diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 73f4591e..ed58fb51 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -136,15 +136,15 @@ class Html extends BaseReader /** * Validate that the current file is an HTML file. * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { // Check if file exists try { - $this->openFile($pFilename); + $this->openFile($filename); } catch (Exception $e) { return false; } @@ -204,17 +204,17 @@ class Html extends BaseReader /** * Loads Spreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } /** diff --git a/src/PhpSpreadsheet/Reader/IReadFilter.php b/src/PhpSpreadsheet/Reader/IReadFilter.php index ccfe05ad..9f68a7f3 100644 --- a/src/PhpSpreadsheet/Reader/IReadFilter.php +++ b/src/PhpSpreadsheet/Reader/IReadFilter.php @@ -7,11 +7,11 @@ interface IReadFilter /** * Should this cell be read? * - * @param string $column Column address (as a string value like "A", or "IV") + * @param string $columnAddress Column address (as a string value like "A", or "IV") * @param int $row Row number * @param string $worksheetName Optional worksheet name * * @return bool */ - public function readCell($column, $row, $worksheetName = ''); + public function readCell($columnAddress, $row, $worksheetName = ''); } diff --git a/src/PhpSpreadsheet/Reader/IReader.php b/src/PhpSpreadsheet/Reader/IReader.php index a8bd3606..bbbc1ec3 100644 --- a/src/PhpSpreadsheet/Reader/IReader.php +++ b/src/PhpSpreadsheet/Reader/IReader.php @@ -12,11 +12,11 @@ interface IReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename); + public function canRead($filename); /** * Read data only? @@ -32,11 +32,11 @@ interface IReader * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. * Set to false (the default) to advise the Reader to read both data and formatting for cells. * - * @param bool $pValue + * @param bool $readCellValuesOnly * * @return IReader */ - public function setReadDataOnly($pValue); + public function setReadDataOnly($readCellValuesOnly); /** * Read empty cells? @@ -52,11 +52,11 @@ interface IReader * Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. * Set to false to advise the Reader to ignore cells containing a null value or an empty string. * - * @param bool $pValue + * @param bool $readEmptyCells * * @return IReader */ - public function setReadEmptyCells($pValue); + public function setReadEmptyCells($readEmptyCells); /** * Read charts in workbook? @@ -74,11 +74,11 @@ interface IReader * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. * Set to false (the default) to discard charts. * - * @param bool $pValue + * @param bool $includeCharts * * @return IReader */ - public function setIncludeCharts($pValue); + public function setIncludeCharts($includeCharts); /** * Get which sheets to load @@ -92,13 +92,13 @@ interface IReader /** * Set which sheets to load. * - * @param mixed $value + * @param mixed $sheetList * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. * If NULL, then it tells the Reader to read all worksheets in the workbook * * @return IReader */ - public function setLoadSheetsOnly($value); + public function setLoadSheetsOnly($sheetList); /** * Set all sheets to load @@ -120,14 +120,14 @@ interface IReader * * @return IReader */ - public function setReadFilter(IReadFilter $pValue); + public function setReadFilter(IReadFilter $readFilter); /** * Loads PhpSpreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return \PhpOffice\PhpSpreadsheet\Spreadsheet */ - public function load($pFilename); + public function load($filename); } diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 4ceac653..668176d1 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -40,20 +40,20 @@ class Ods extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { - File::assertFile($pFilename); + File::assertFile($filename); $mimeType = 'UNKNOWN'; // Load file $zip = new ZipArchive(); - if ($zip->open($pFilename) === true) { + if ($zip->open($filename) === true) { // check if it is an OOXML archive $stat = $zip->statName('mimetype'); if ($stat && ($stat['size'] <= 255)) { @@ -231,17 +231,17 @@ class Ods extends BaseReader /** * Loads PhpSpreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } /** diff --git a/src/PhpSpreadsheet/Reader/Slk.php b/src/PhpSpreadsheet/Reader/Slk.php index 0e147376..5f1ff250 100644 --- a/src/PhpSpreadsheet/Reader/Slk.php +++ b/src/PhpSpreadsheet/Reader/Slk.php @@ -65,14 +65,14 @@ class Slk extends BaseReader /** * Validate that the current file is a SYLK file. * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { try { - $this->openFile($pFilename); + $this->openFile($filename); } catch (InvalidArgumentException $e) { return false; } @@ -196,17 +196,17 @@ class Slk extends BaseReader /** * Loads PhpSpreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } private $colorArray = [ diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index b5c92d8d..d9ac6410 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -418,20 +418,20 @@ class Xls extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { - File::assertFile($pFilename); + File::assertFile($filename); try { // Use ParseXL for the hard work. $ole = new OLERead(); // get excel data - $ole->read($pFilename); + $ole->read($filename); return true; } catch (PhpSpreadsheetException $e) { @@ -621,14 +621,14 @@ class Xls extends BaseReader /** * Loads PhpSpreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Read the OLE file - $this->loadOLE($pFilename); + $this->loadOLE($filename); // Initialisations $this->spreadsheet = new Spreadsheet(); diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 22584c51..aaf6c56b 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -69,18 +69,18 @@ class Xlsx extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { - File::assertFile($pFilename); + File::assertFile($filename); $result = false; $zip = new ZipArchive(); - if ($zip->open($pFilename) === true) { + if ($zip->open($filename) === true) { $workbookBasename = $this->getWorkbookBaseName($zip); $result = !empty($workbookBasename); @@ -311,13 +311,13 @@ class Xlsx extends BaseReader /** * Loads Spreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { - File::assertFile($pFilename); + File::assertFile($filename); // Initialisations $excel = new Spreadsheet(); @@ -329,7 +329,7 @@ class Xlsx extends BaseReader $unparsedLoadedData = []; $zip = new ZipArchive(); - $zip->open($pFilename); + $zip->open($filename); // Read the theme first, because we need the colour scheme when reading the styles //~ http://schemas.openxmlformats.org/package/2006/relationships" @@ -1036,7 +1036,7 @@ class Xlsx extends BaseReader $hfImages[(string) $shape['id']]->setName((string) $imageData['title']); } - $hfImages[(string) $shape['id']]->setPath('zip://' . File::realpath($pFilename) . '#' . $drawings[(string) $imageData['relid']], false); + $hfImages[(string) $shape['id']]->setPath('zip://' . File::realpath($filename) . '#' . $drawings[(string) $imageData['relid']], false); $hfImages[(string) $shape['id']]->setResizeProportional(false); $hfImages[(string) $shape['id']]->setWidth($style['width']); $hfImages[(string) $shape['id']]->setHeight($style['height']); @@ -1124,7 +1124,7 @@ class Xlsx extends BaseReader $objDrawing->setName((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); $objDrawing->setDescription((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); $objDrawing->setPath( - 'zip://' . File::realpath($pFilename) . '#' . + 'zip://' . File::realpath($filename) . '#' . $images[(string) self::getArrayItem( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'embed' @@ -1176,7 +1176,7 @@ class Xlsx extends BaseReader $objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); $objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); $objDrawing->setPath( - 'zip://' . File::realpath($pFilename) . '#' . + 'zip://' . File::realpath($filename) . '#' . $images[(string) self::getArrayItem( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'embed' diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index e4d251e2..97e85790 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -96,11 +96,11 @@ class Xml extends BaseReader /** * Can the current IReader read the file? * - * @param string $pFilename + * @param string $filename * * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { // Office xmlns:o="urn:schemas-microsoft-com:office:office" // Excel xmlns:x="urn:schemas-microsoft-com:office:excel" @@ -118,7 +118,7 @@ class Xml extends BaseReader ]; // Open file - $data = file_get_contents($pFilename); + $data = file_get_contents($filename); // Why? //$data = str_replace("'", '"', $data); // fix headers with single quote @@ -272,18 +272,18 @@ class Xml extends BaseReader /** * Loads Spreadsheet from file. * - * @param string $pFilename + * @param string $filename * * @return Spreadsheet */ - public function load($pFilename) + public function load($filename) { // Create new Spreadsheet $spreadsheet = new Spreadsheet(); $spreadsheet->removeSheetByIndex(0); // Load into this instance - return $this->loadIntoExisting($pFilename, $spreadsheet); + return $this->loadIntoExisting($filename, $spreadsheet); } private static function identifyFixedStyleValue($styleList, &$styleAttributeValue) diff --git a/src/PhpSpreadsheet/Writer/BaseWriter.php b/src/PhpSpreadsheet/Writer/BaseWriter.php index afda5c43..6e8f7495 100644 --- a/src/PhpSpreadsheet/Writer/BaseWriter.php +++ b/src/PhpSpreadsheet/Writer/BaseWriter.php @@ -50,9 +50,9 @@ abstract class BaseWriter implements IWriter return $this->includeCharts; } - public function setIncludeCharts($pValue) + public function setIncludeCharts($includeCharts) { - $this->includeCharts = (bool) $pValue; + $this->includeCharts = (bool) $includeCharts; return $this; } @@ -62,9 +62,9 @@ abstract class BaseWriter implements IWriter return $this->preCalculateFormulas; } - public function setPreCalculateFormulas($pValue) + public function setPreCalculateFormulas($precalculateFormulas) { - $this->preCalculateFormulas = (bool) $pValue; + $this->preCalculateFormulas = (bool) $precalculateFormulas; return $this; } @@ -74,15 +74,15 @@ abstract class BaseWriter implements IWriter return $this->useDiskCaching; } - public function setUseDiskCaching($pValue, $pDirectory = null) + public function setUseDiskCaching($useDiskCache, $cacheDirectory = null) { - $this->useDiskCaching = $pValue; + $this->useDiskCaching = $useDiskCache; - if ($pDirectory !== null) { - if (is_dir($pDirectory)) { - $this->diskCachingDirectory = $pDirectory; + if ($cacheDirectory !== null) { + if (is_dir($cacheDirectory)) { + $this->diskCachingDirectory = $cacheDirectory; } else { - throw new Exception("Directory does not exist: $pDirectory"); + throw new Exception("Directory does not exist: $cacheDirectory"); } } diff --git a/src/PhpSpreadsheet/Writer/Csv.php b/src/PhpSpreadsheet/Writer/Csv.php index 74f28636..d6d688c0 100644 --- a/src/PhpSpreadsheet/Writer/Csv.php +++ b/src/PhpSpreadsheet/Writer/Csv.php @@ -77,9 +77,9 @@ class Csv extends BaseWriter /** * Save PhpSpreadsheet to file. * - * @param resource|string $pFilename + * @param resource|string $filename */ - public function save($pFilename): void + public function save($filename): void { // Fetch sheet $sheet = $this->spreadsheet->getSheet($this->sheetIndex); @@ -90,7 +90,7 @@ class Csv extends BaseWriter Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); if ($this->excelCompatibility) { $this->setUseBOM(true); // Enforce UTF-8 BOM Header diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index 31cc05af..d40d10d7 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -151,12 +151,12 @@ class Html extends BaseWriter /** * Save Spreadsheet to file. * - * @param resource|string $pFilename + * @param resource|string $filename */ - public function save($pFilename): void + public function save($filename): void { // Open file - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); // Write html fwrite($this->fileHandle, $this->generateHTMLAll()); diff --git a/src/PhpSpreadsheet/Writer/IWriter.php b/src/PhpSpreadsheet/Writer/IWriter.php index 5129d655..ac2972bc 100644 --- a/src/PhpSpreadsheet/Writer/IWriter.php +++ b/src/PhpSpreadsheet/Writer/IWriter.php @@ -8,6 +8,8 @@ interface IWriter { /** * IWriter constructor. + * + * @param Spreadsheet $spreadsheet The spreadsheet that we want to save using this Writer */ public function __construct(Spreadsheet $spreadsheet); @@ -25,11 +27,11 @@ interface IWriter * Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object. * Set to false (the default) to ignore charts. * - * @param bool $pValue + * @param bool $includeCharts * * @return IWriter */ - public function setIncludeCharts($pValue); + public function setIncludeCharts($includeCharts); /** * Get Pre-Calculate Formulas flag @@ -48,18 +50,18 @@ interface IWriter * Set to true (the default) to advise the Writer to calculate all formulae on save * Set to false to prevent precalculation of formulae on save. * - * @param bool $pValue Pre-Calculate Formulas? + * @param bool $precalculateFormulas Pre-Calculate Formulas? * * @return IWriter */ - public function setPreCalculateFormulas($pValue); + public function setPreCalculateFormulas($precalculateFormulas); /** * Save PhpSpreadsheet to file. * - * @param resource|string $pFilename Name of the file to save + * @param resource|string $filename Name of the file to save */ - public function save($pFilename); + public function save($filename); /** * Get use disk caching where possible? @@ -71,12 +73,12 @@ interface IWriter /** * Set use disk caching where possible? * - * @param bool $pValue - * @param string $pDirectory Disk caching directory + * @param bool $useDiskCache + * @param string $cacheDirectory Disk caching directory * * @return IWriter */ - public function setUseDiskCaching($pValue, $pDirectory = null); + public function setUseDiskCaching($useDiskCache, $cacheDirectory = null); /** * Get disk caching directory. diff --git a/src/PhpSpreadsheet/Writer/Ods.php b/src/PhpSpreadsheet/Writer/Ods.php index 36f3e9ca..61a91c1e 100644 --- a/src/PhpSpreadsheet/Writer/Ods.php +++ b/src/PhpSpreadsheet/Writer/Ods.php @@ -73,9 +73,9 @@ class Ods extends BaseWriter /** * Save PhpSpreadsheet to file. * - * @param resource|string $pFilename + * @param resource|string $filename */ - public function save($pFilename): void + public function save($filename): void { if (!$this->spreadSheet) { throw new WriterException('PhpSpreadsheet object unassigned.'); @@ -84,7 +84,7 @@ class Ods extends BaseWriter // garbage collect $this->spreadSheet->garbageCollect(); - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); $zip = $this->createZip(); diff --git a/src/PhpSpreadsheet/Writer/Pdf.php b/src/PhpSpreadsheet/Writer/Pdf.php index 87220458..d1ac69fa 100644 --- a/src/PhpSpreadsheet/Writer/Pdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf.php @@ -165,13 +165,13 @@ abstract class Pdf extends Html /** * Set Paper Size. * - * @param string $pValue Paper size see PageSetup::PAPERSIZE_* + * @param string $paperSize Paper size see PageSetup::PAPERSIZE_* * * @return self */ - public function setPaperSize($pValue) + public function setPaperSize($paperSize) { - $this->paperSize = $pValue; + $this->paperSize = $paperSize; return $this; } @@ -189,13 +189,13 @@ abstract class Pdf extends Html /** * Set Orientation. * - * @param string $pValue Page orientation see PageSetup::ORIENTATION_* + * @param string $orientation Page orientation see PageSetup::ORIENTATION_* * * @return self */ - public function setOrientation($pValue) + public function setOrientation($orientation) { - $this->orientation = $pValue; + $this->orientation = $orientation; return $this; } @@ -213,16 +213,16 @@ abstract class Pdf extends Html /** * Set temporary storage directory. * - * @param string $pValue Temporary storage directory + * @param string $temporaryDirectory Temporary storage directory * * @return self */ - public function setTempDir($pValue) + public function setTempDir($temporaryDirectory) { - if (is_dir($pValue)) { - $this->tempDir = $pValue; + if (is_dir($temporaryDirectory)) { + $this->tempDir = $temporaryDirectory; } else { - throw new WriterException("Directory does not exist: $pValue"); + throw new WriterException("Directory does not exist: $temporaryDirectory"); } return $this; @@ -231,14 +231,14 @@ abstract class Pdf extends Html /** * Save Spreadsheet to PDF file, pre-save. * - * @param string $pFilename Name of the file to save as + * @param string $filename Name of the file to save as * * @return resource */ - protected function prepareForSave($pFilename) + protected function prepareForSave($filename) { // Open file - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); return $this->fileHandle; } diff --git a/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php b/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php index 9ae2ccee..51b0e1f1 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Dompdf.php @@ -20,11 +20,11 @@ class Dompdf extends Pdf /** * Save Spreadsheet to file. * - * @param string $pFilename Name of the file to save as + * @param string $filename Name of the file to save as */ - public function save($pFilename): void + public function save($filename): void { - $fileHandle = parent::prepareForSave($pFilename); + $fileHandle = parent::prepareForSave($filename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) diff --git a/src/PhpSpreadsheet/Writer/Pdf/Mpdf.php b/src/PhpSpreadsheet/Writer/Pdf/Mpdf.php index 75e0010d..bbc35e15 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Mpdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Mpdf.php @@ -22,11 +22,11 @@ class Mpdf extends Pdf /** * Save Spreadsheet to file. * - * @param string $pFilename Name of the file to save as + * @param string $filename Name of the file to save as */ - public function save($pFilename): void + public function save($filename): void { - $fileHandle = parent::prepareForSave($pFilename); + $fileHandle = parent::prepareForSave($filename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) diff --git a/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php b/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php index 7530b1ef..770c2248 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php @@ -36,11 +36,11 @@ class Tcpdf extends Pdf /** * Save Spreadsheet to file. * - * @param string $pFilename Name of the file to save as + * @param string $filename Name of the file to save as */ - public function save($pFilename): void + public function save($filename): void { - $fileHandle = parent::prepareForSave($pFilename); + $fileHandle = parent::prepareForSave($filename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) @@ -97,7 +97,7 @@ class Tcpdf extends Pdf $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); // Write to file - fwrite($fileHandle, $pdf->output($pFilename, 'S')); + fwrite($fileHandle, $pdf->output($filename, 'S')); parent::restoreStateAfterSave(); } diff --git a/src/PhpSpreadsheet/Writer/Xls.php b/src/PhpSpreadsheet/Writer/Xls.php index c7c2e7d6..741aee74 100644 --- a/src/PhpSpreadsheet/Writer/Xls.php +++ b/src/PhpSpreadsheet/Writer/Xls.php @@ -114,9 +114,9 @@ class Xls extends BaseWriter /** * Save Spreadsheet to file. * - * @param resource|string $pFilename + * @param resource|string $filename */ - public function save($pFilename): void + public function save($filename): void { // garbage collect $this->spreadsheet->garbageCollect(); @@ -218,7 +218,7 @@ class Xls extends BaseWriter $root = new Root(time(), time(), $arrRootData); // save the OLE file - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); $root->save($this->fileHandle); $this->maybeCloseFileHandle(); diff --git a/src/PhpSpreadsheet/Writer/Xlsx.php b/src/PhpSpreadsheet/Writer/Xlsx.php index d71541c8..104e6041 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx.php +++ b/src/PhpSpreadsheet/Writer/Xlsx.php @@ -174,15 +174,15 @@ class Xlsx extends BaseWriter /** * Save PhpSpreadsheet to file. * - * @param resource|string $pFilename + * @param resource|string $filename */ - public function save($pFilename): void + public function save($filename): void { // garbage collect $this->pathNames = []; $this->spreadSheet->garbageCollect(); - $this->openFileHandle($pFilename); + $this->openFileHandle($filename); $saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false); diff --git a/tests/PhpSpreadsheetTests/Reader/CsvContiguousFilter.php b/tests/PhpSpreadsheetTests/Reader/CsvContiguousFilter.php index 9bc16ae0..b6b24751 100644 --- a/tests/PhpSpreadsheetTests/Reader/CsvContiguousFilter.php +++ b/tests/PhpSpreadsheetTests/Reader/CsvContiguousFilter.php @@ -46,7 +46,7 @@ class CsvContiguousFilter implements IReadFilter return false; } - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { if ($this->filterType == 1) { return $this->filter1($row); diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php index 0904e2d4..8d8fd62b 100644 --- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php +++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericFilter.php @@ -7,7 +7,7 @@ use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; /** Define a Read Filter class implementing IReadFilter */ class GnumericFilter implements IReadFilter { - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { return $row !== 4; } diff --git a/tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php b/tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php index b9373314..2ee6015b 100644 --- a/tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php +++ b/tests/PhpSpreadsheetTests/Reader/OddColumnReadFilter.php @@ -9,8 +9,8 @@ use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; */ class OddColumnReadFilter implements IReadFilter { - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { - return (\ord(\substr($column, -1, 1)) % 2) === 1; + return (\ord(\substr($columnAddress, -1, 1)) % 2) === 1; } } diff --git a/tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php b/tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php index 1a20bb21..b53fffd5 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php +++ b/tests/PhpSpreadsheetTests/Reader/Xml/XmlFilter.php @@ -7,7 +7,7 @@ use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; /** Define a Read Filter class implementing IReadFilter */ class XmlFilter implements IReadFilter { - public function readCell($column, $row, $worksheetName = '') + public function readCell($columnAddress, $row, $worksheetName = '') { return $row !== 4; } From 02e88971e8f4915c0715da758e9732af3bbd5407 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 19 Nov 2020 16:45:01 +0100 Subject: [PATCH 38/41] Update todocumentation --- docs/topics/reading-and-writing-to-file.md | 10 +++++----- docs/topics/reading-files.md | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/topics/reading-and-writing-to-file.md b/docs/topics/reading-and-writing-to-file.md index e55471a7..4f30cc43 100644 --- a/docs/topics/reading-and-writing-to-file.md +++ b/docs/topics/reading-and-writing-to-file.md @@ -125,7 +125,7 @@ the Excel file: ```php class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { return true; @@ -242,7 +242,7 @@ in the Excel file: ```php class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { return true; @@ -301,7 +301,7 @@ in the Excel file: ```php class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { return true; @@ -352,7 +352,7 @@ in the SYLK file: ```php class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { return true; @@ -397,7 +397,7 @@ in the Calc file: ```php class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 || ($row >= 20 && $row <= 30)) { return true; diff --git a/docs/topics/reading-files.md b/docs/topics/reading-files.md index 1451f2ab..b46908a6 100644 --- a/docs/topics/reading-files.md +++ b/docs/topics/reading-files.md @@ -256,7 +256,7 @@ $sheetname = 'Data Sheet #3'; /** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Read rows 1 to 7 and columns A to E only if ($row >= 1 && $row <= 7) { if (in_array($column,range('A','E'))) { @@ -301,7 +301,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter $this->columns = $columns; } - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Only read the rows and columns that were configured if ($row >= $this->startRow && $row <= $this->endRow) { if (in_array($column,$this->columns)) { @@ -340,7 +340,7 @@ class ChunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter $this->endRow = $startRow + $chunkSize; } - public function readCell($column, $row, $worksheetName = '') { + public function readCell($columnAddress, $row, $worksheetName = '') { // Only read the heading row, and the configured rows if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) { return true; From c3c93c56d63eeb71dfde4998ad230368aa7d1bd1 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 31 Oct 2021 22:17:07 +0900 Subject: [PATCH 39/41] Fix CI --- phpstan-baseline.neon | 9 +++++++-- src/PhpSpreadsheet/Reader/Ods.php | 8 ++++---- src/PhpSpreadsheet/Reader/Xls.php | 18 +++++++++--------- src/PhpSpreadsheet/Style/Color.php | 4 ++-- src/PhpSpreadsheet/Writer/Html.php | 8 ++++---- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0fca9ef3..96eeee15 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5757,7 +5757,7 @@ parameters: - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, string\\|null given\\.$#" - count: 4 + count: 5 path: src/PhpSpreadsheet/Writer/Xlsx/StringTable.php - @@ -5852,9 +5852,14 @@ parameters: - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, string\\|null given\\.$#" - count: 4 + count: 9 path: src/PhpSpreadsheet/Writer/Xlsx/Style.php + - + message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php + - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, float given\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index abf658e5..80ad43c6 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -56,10 +56,10 @@ class Ods extends BaseReader $mimeType = $zip->getFromName($stat['name']); } elseif ($zip->statName('META-INF/manifest.xml')) { $xml = simplexml_load_string( - $this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')), - 'SimpleXMLElement', - Settings::getLibXmlLoaderOptions() - ); + $this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')), + 'SimpleXMLElement', + Settings::getLibXmlLoaderOptions() + ); $namespacesContent = $xml->getNamespaces(true); if (isset($namespacesContent['manifest'])) { $manifest = $xml->children($namespacesContent['manifest']); diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index a046626c..aa8a5bc5 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -1154,19 +1154,19 @@ class Xls extends BaseReader $drawing->setOffsetY($offsetY); switch ($blipType) { - case BSE::BLIPTYPE_JPEG: - $drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG); - $drawing->setMimeType(MemoryDrawing::MIMETYPE_JPEG); + case BSE::BLIPTYPE_JPEG: + $drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG); + $drawing->setMimeType(MemoryDrawing::MIMETYPE_JPEG); - break; - case BSE::BLIPTYPE_PNG: + break; + case BSE::BLIPTYPE_PNG: imagealphablending($ih, false); imagesavealpha($ih, true); - $drawing->setRenderingFunction(MemoryDrawing::RENDERING_PNG); - $drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG); + $drawing->setRenderingFunction(MemoryDrawing::RENDERING_PNG); + $drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG); - break; - } + break; + } $drawing->setWorksheet($this->phpSheet); $drawing->setCoordinates($spContainer->getStartCoordinates()); diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 182eb15c..d9b9830c 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -41,7 +41,7 @@ class Color extends Supervisor /** * ARGB - Alpha RGB. * - * @var string + * @var null|string */ protected $argb; @@ -135,7 +135,7 @@ class Color extends Supervisor /** * Get ARGB. */ - public function getARGB(): string + public function getARGB(): ?string { if ($this->isSupervisor) { return $this->getSharedComponent()->getARGB(); diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index 9f7d347b..b440358b 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -698,10 +698,10 @@ class Html extends BaseWriter if ($imageResource) { ob_start(); // Let's start output buffering. imagepng($imageResource); // This will normally output the image, but because of ob_start(), it won't. - $contents = ob_get_contents(); // Instead, output above is saved to $contents - ob_end_clean(); // End the output buffer. + $contents = ob_get_contents(); // Instead, output above is saved to $contents + ob_end_clean(); // End the output buffer. - $dataUri = 'data:image/jpeg;base64,' . base64_encode($contents); + $dataUri = 'data:image/jpeg;base64,' . base64_encode($contents); // Because of the nature of tables, width is more important than height. // max-width: 100% ensures that image doesnt overflow containing cell @@ -1296,7 +1296,7 @@ class Html extends BaseWriter } else { $origData = $this->preCalculateFormulas ? $cell->getCalculatedValue() : $cell->getValue(); $formatCode = $worksheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(); - if ($formatCode) { + if ($formatCode !== null) { $cellData = NumberFormat::toFormattedString( $origData, $formatCode, From 8cef8c0cfbb369abd290be8ced17138b54725358 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 31 Oct 2021 22:35:14 +0900 Subject: [PATCH 40/41] Help Scrutinizer --- CHANGELOG.PHPExcel.md | 2 +- src/PhpSpreadsheet/Calculation/Calculation.php | 3 +-- src/PhpSpreadsheet/Cell/Coordinate.php | 12 ++++++------ src/PhpSpreadsheet/Reader/Csv.php | 13 ------------- src/PhpSpreadsheet/Shared/Drawing.php | 2 +- src/PhpSpreadsheet/Writer/Xlsx/Chart.php | 4 ++-- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.PHPExcel.md b/CHANGELOG.PHPExcel.md index c92feda9..3c299020 100644 --- a/CHANGELOG.PHPExcel.md +++ b/CHANGELOG.PHPExcel.md @@ -1518,7 +1518,7 @@ documentation for more information on entering dates into a cell. ### Bugfixes - PHPExcel->removeSheetByIndex now re-orders sheets after deletion, so no array indexes are lost - @JV -- PHPExcel_Writer_Excel2007_Worksheet::_writeCols() used direct assignment to $pSheet->getColumnDimension('A')->Width instead of ~~~~$pSheet->getColumnDimension('A')->setWidth() - @JV +- PHPExcel_Writer_Excel2007_Worksheet::_writeCols() used direct assignment to $pSheet->getColumnDimension('A')->Width instead of $pSheet->getColumnDimension('A')->setWidth() - @JV - DocumentProperties used $this->LastModifiedBy instead of $this->_lastModifiedBy. - @JV ### General diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index f9c4fc0c..15bb8100 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -4724,7 +4724,7 @@ class Calculation } } else { if ($pCell === null) { - // We can't access the cell, so return a REF error + // We can't access the cell, so return a REF error $cellValue = Functions::REF(); } else { $cellRef = $matches[6] . $matches[7]; @@ -5307,7 +5307,6 @@ class Calculation $returnValue = []; if ($worksheet !== null) { - $worksheetName = $worksheet->getTitle(); if (strpos($range, '!') !== false) { [$worksheetName, $range] = Worksheet::extractSheetTitle($range, true); $worksheet = $this->spreadsheet->getSheetByName($worksheetName); diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 33b0c214..df64c557 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -156,24 +156,24 @@ abstract class Coordinate /** * Build range from coordinate strings. * - * @param array $rangea Array containg one or more arrays containing one or two coordinate strings + * @param array $range Array containing one or more arrays containing one or two coordinate strings * * @return string String representation of $pRange */ - public static function buildRange(array $rangea) + public static function buildRange(array $range) { // Verify range - if (empty($rangea) || !is_array($rangea[0])) { + if (empty($range) || !is_array($range[0])) { throw new Exception('Range does not contain any information'); } // Build range - $counter = count($rangea); + $counter = count($range); for ($i = 0; $i < $counter; ++$i) { - $rangea[$i] = implode(':', $rangea[$i]); + $range[$i] = implode(':', $range[$i]); } - return implode(',', $rangea); + return implode(',', $range); } /** diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index e0f2c451..50426c4f 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -427,19 +427,6 @@ class Csv extends BaseReader return $this->escapeCharacter; } - /** - * Scrutinizer believes, incorrectly, that the specific pathinfo - * call in canRead can return something other than an array. - * Phpstan knows better. - * This function satisfies both. - * - * @param mixed $extension - */ - private static function extractStringLower($extension): string - { - return is_string($extension) ? strtolower($extension) : ''; - } - /** * Can the current IReader read the file? */ diff --git a/src/PhpSpreadsheet/Shared/Drawing.php b/src/PhpSpreadsheet/Shared/Drawing.php index 04ce1430..1d2a1537 100644 --- a/src/PhpSpreadsheet/Shared/Drawing.php +++ b/src/PhpSpreadsheet/Shared/Drawing.php @@ -143,7 +143,7 @@ class Drawing */ public static function angleToDegrees($angle) { - $pValue = (int) $angle; + $angle = (int) $angle; if ($angle != 0) { return (int) round($angle / 60000); } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index e65f6e34..8cefe4cc 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -75,7 +75,7 @@ class Chart extends WriterPart $objWriter->writeAttribute('val', 0); $objWriter->endElement(); - $this->writePlotArea($objWriter, $pChart->getWorksheet(), $pChart->getPlotArea(), $pChart->getXAxisLabel(), $pChart->getYAxisLabel(), $pChart->getChartAxisX(), $pChart->getChartAxisY(), $pChart->getMajorGridlines(), $pChart->getMinorGridlines()); + $this->writePlotArea($objWriter, $pChart->getPlotArea(), $pChart->getXAxisLabel(), $pChart->getYAxisLabel(), $pChart->getChartAxisX(), $pChart->getChartAxisY(), $pChart->getMajorGridlines(), $pChart->getMinorGridlines()); $this->writeLegend($objWriter, $pChart->getLegend()); @@ -202,7 +202,7 @@ class Chart extends WriterPart * @param Axis $xAxis * @param Axis $yAxis */ - private function writePlotArea(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $worksheet, PlotArea $plotArea, ?Title $xAxisLabel = null, ?Title $yAxisLabel = null, ?Axis $xAxis = null, ?Axis $yAxis = null, ?GridLines $majorGridlines = null, ?GridLines $minorGridlines = null): void + private function writePlotArea(XMLWriter $objWriter, PlotArea $plotArea, ?Title $xAxisLabel = null, ?Title $yAxisLabel = null, ?Axis $xAxis = null, ?Axis $yAxis = null, ?GridLines $majorGridlines = null, ?GridLines $minorGridlines = null): void { if ($plotArea === null) { return; From 59c706ebe727f40db6a3daba4ee9883f71f33807 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 31 Oct 2021 22:39:08 +0900 Subject: [PATCH 41/41] Fix warnings in PHP 8.1 --- phpstan-baseline.neon | 2 +- src/PhpSpreadsheet/Shared/XMLWriter.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 96eeee15..4423b594 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5636,7 +5636,7 @@ parameters: path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php - - message: "#^Parameter \\#1 \\$rawTextData of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\XMLWriter\\:\\:writeRawData\\(\\) expects array\\\\|string, int given\\.$#" + message: "#^Parameter \\#1 \\$rawTextData of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\XMLWriter\\:\\:writeRawData\\(\\) expects array\\\\|string\\|null, int given\\.$#" count: 1 path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php diff --git a/src/PhpSpreadsheet/Shared/XMLWriter.php b/src/PhpSpreadsheet/Shared/XMLWriter.php index 6fb38438..84ad8a83 100644 --- a/src/PhpSpreadsheet/Shared/XMLWriter.php +++ b/src/PhpSpreadsheet/Shared/XMLWriter.php @@ -77,7 +77,7 @@ class XMLWriter extends \XMLWriter /** * Wrapper method for writeRaw. * - * @param string|string[] $rawTextData + * @param null|string|string[] $rawTextData * * @return bool */ @@ -87,6 +87,6 @@ class XMLWriter extends \XMLWriter $rawTextData = implode("\n", $rawTextData); } - return $this->writeRaw(htmlspecialchars($rawTextData)); + return $this->writeRaw(htmlspecialchars($rawTextData ?? '')); } }