Sane argument names for Styles

This commit is contained in:
MarkBaker 2020-11-05 20:04:35 +01:00
parent 317965078d
commit 86728cb214
10 changed files with 281 additions and 281 deletions

View File

@ -140,36 +140,36 @@ class Alignment extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells()) $this->getActiveSheet()->getStyle($this->getSelectedCells())
->applyFromArray($this->getStyleArray($pStyles)); ->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['horizontal'])) { if (isset($styleArray['horizontal'])) {
$this->setHorizontal($pStyles['horizontal']); $this->setHorizontal($styleArray['horizontal']);
} }
if (isset($pStyles['vertical'])) { if (isset($styleArray['vertical'])) {
$this->setVertical($pStyles['vertical']); $this->setVertical($styleArray['vertical']);
} }
if (isset($pStyles['textRotation'])) { if (isset($styleArray['textRotation'])) {
$this->setTextRotation($pStyles['textRotation']); $this->setTextRotation($styleArray['textRotation']);
} }
if (isset($pStyles['wrapText'])) { if (isset($styleArray['wrapText'])) {
$this->setWrapText($pStyles['wrapText']); $this->setWrapText($styleArray['wrapText']);
} }
if (isset($pStyles['shrinkToFit'])) { if (isset($styleArray['shrinkToFit'])) {
$this->setShrinkToFit($pStyles['shrinkToFit']); $this->setShrinkToFit($styleArray['shrinkToFit']);
} }
if (isset($pStyles['indent'])) { if (isset($styleArray['indent'])) {
$this->setIndent($pStyles['indent']); $this->setIndent($styleArray['indent']);
} }
if (isset($pStyles['readOrder'])) { if (isset($styleArray['readOrder'])) {
$this->setReadOrder($pStyles['readOrder']); $this->setReadOrder($styleArray['readOrder']);
} }
} }
@ -267,24 +267,24 @@ class Alignment extends Supervisor
/** /**
* Set TextRotation. * Set TextRotation.
* *
* @param int $rotation * @param int $angleInDegrees
* *
* @return $this * @return $this
*/ */
public function setTextRotation($rotation) public function setTextRotation($angleInDegrees)
{ {
// Excel2007 value 255 => PhpSpreadsheet value -165 // Excel2007 value 255 => PhpSpreadsheet value -165
if ($rotation == self::TEXTROTATION_STACK_EXCEL) { if ($angleInDegrees == self::TEXTROTATION_STACK_EXCEL) {
$rotation = self::TEXTROTATION_STACK_PHPSPREADSHEET; $angleInDegrees = self::TEXTROTATION_STACK_PHPSPREADSHEET;
} }
// Set rotation // 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) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['textRotation' => $rotation]); $styleArray = $this->getStyleArray(['textRotation' => $angleInDegrees]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->textRotation = $rotation; $this->textRotation = $angleInDegrees;
} }
} else { } else {
throw new PhpSpreadsheetException('Text rotation should be a value between -90 and 90.'); throw new PhpSpreadsheetException('Text rotation should be a value between -90 and 90.');

View File

@ -115,20 +115,20 @@ class Border extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['borderStyle'])) { if (isset($styleArray['borderStyle'])) {
$this->setBorderStyle($pStyles['borderStyle']); $this->setBorderStyle($styleArray['borderStyle']);
} }
if (isset($pStyles['color'])) { if (isset($styleArray['color'])) {
$this->getColor()->applyFromArray($pStyles['color']); $this->getColor()->applyFromArray($styleArray['color']);
} }
} }

View File

@ -193,38 +193,38 @@ class Borders extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['left'])) { if (isset($styleArray['left'])) {
$this->getLeft()->applyFromArray($pStyles['left']); $this->getLeft()->applyFromArray($styleArray['left']);
} }
if (isset($pStyles['right'])) { if (isset($styleArray['right'])) {
$this->getRight()->applyFromArray($pStyles['right']); $this->getRight()->applyFromArray($styleArray['right']);
} }
if (isset($pStyles['top'])) { if (isset($styleArray['top'])) {
$this->getTop()->applyFromArray($pStyles['top']); $this->getTop()->applyFromArray($styleArray['top']);
} }
if (isset($pStyles['bottom'])) { if (isset($styleArray['bottom'])) {
$this->getBottom()->applyFromArray($pStyles['bottom']); $this->getBottom()->applyFromArray($styleArray['bottom']);
} }
if (isset($pStyles['diagonal'])) { if (isset($styleArray['diagonal'])) {
$this->getDiagonal()->applyFromArray($pStyles['diagonal']); $this->getDiagonal()->applyFromArray($styleArray['diagonal']);
} }
if (isset($pStyles['diagonalDirection'])) { if (isset($styleArray['diagonalDirection'])) {
$this->setDiagonalDirection($pStyles['diagonalDirection']); $this->setDiagonalDirection($styleArray['diagonalDirection']);
} }
if (isset($pStyles['allBorders'])) { if (isset($styleArray['allBorders'])) {
$this->getLeft()->applyFromArray($pStyles['allBorders']); $this->getLeft()->applyFromArray($styleArray['allBorders']);
$this->getRight()->applyFromArray($pStyles['allBorders']); $this->getRight()->applyFromArray($styleArray['allBorders']);
$this->getTop()->applyFromArray($pStyles['allBorders']); $this->getTop()->applyFromArray($styleArray['allBorders']);
$this->getBottom()->applyFromArray($pStyles['allBorders']); $this->getBottom()->applyFromArray($styleArray['allBorders']);
} }
} }
@ -368,20 +368,20 @@ class Borders extends Supervisor
/** /**
* Set DiagonalDirection. * Set DiagonalDirection.
* *
* @param int $pValue see self::DIAGONAL_* * @param int $direction see self::DIAGONAL_*
* *
* @return $this * @return $this
*/ */
public function setDiagonalDirection($pValue) public function setDiagonalDirection($direction)
{ {
if ($pValue == '') { if ($direction == '') {
$pValue = self::DIAGONAL_NONE; $direction = self::DIAGONAL_NONE;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]); $styleArray = $this->getStyleArray(['diagonalDirection' => $direction]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->diagonalDirection = $pValue; $this->diagonalDirection = $direction;
} }
return $this; return $this;

View File

@ -104,20 +104,20 @@ class Color extends Supervisor
* $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']); * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']);
* </code> * </code>
* *
* @param array $styles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $styles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($styles['rgb'])) { if (isset($styleArray['rgb'])) {
$this->setRGB($styles['rgb']); $this->setRGB($styleArray['rgb']);
} }
if (isset($styles['argb'])) { if (isset($styleArray['argb'])) {
$this->setARGB($styles['argb']); $this->setARGB($styleArray['argb']);
} }
} }
@ -211,16 +211,16 @@ class Color extends Supervisor
/** /**
* Get a specified colour component of an RGB value. * 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 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 * @param bool $hex Flag indicating whether the component should be returned as a hex or a
* decimal value * decimal value
* *
* @return string The extracted colour component * @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); return ($hex) ? $colour : hexdec($colour);
} }
@ -228,43 +228,43 @@ class Color extends Supervisor
/** /**
* Get the red colour component of an RGB value. * 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 * @param bool $hex Flag indicating whether the component should be returned as a hex or a
* decimal value * decimal value
* *
* @return string The red colour component * @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. * 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 * @param bool $hex Flag indicating whether the component should be returned as a hex or a
* decimal value * decimal value
* *
* @return string The green colour component * @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. * 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 * @param bool $hex Flag indicating whether the component should be returned as a hex or a
* decimal value * decimal value
* *
* @return string The blue colour component * @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);
} }
/** /**

View File

@ -93,13 +93,13 @@ class Conditional implements IComparable
/** /**
* Set Condition type. * Set Condition type.
* *
* @param string $pValue Condition type, see self::CONDITION_* * @param string $type Condition type, see self::CONDITION_*
* *
* @return $this * @return $this
*/ */
public function setConditionType($pValue) public function setConditionType($type)
{ {
$this->conditionType = $pValue; $this->conditionType = $type;
return $this; return $this;
} }
@ -117,13 +117,13 @@ class Conditional implements IComparable
/** /**
* Set Operator type. * Set Operator type.
* *
* @param string $pValue Conditional operator type, see self::OPERATOR_* * @param string $type Conditional operator type, see self::OPERATOR_*
* *
* @return $this * @return $this
*/ */
public function setOperatorType($pValue) public function setOperatorType($type)
{ {
$this->operatorType = $pValue; $this->operatorType = $type;
return $this; return $this;
} }
@ -141,13 +141,13 @@ class Conditional implements IComparable
/** /**
* Set text. * Set text.
* *
* @param string $value * @param string $text
* *
* @return $this * @return $this
*/ */
public function setText($value) public function setText($text)
{ {
$this->text = $value; $this->text = $text;
return $this; return $this;
} }
@ -165,13 +165,13 @@ class Conditional implements IComparable
/** /**
* Set StopIfTrue. * Set StopIfTrue.
* *
* @param bool $value * @param bool $stopIfTrue
* *
* @return $this * @return $this
*/ */
public function setStopIfTrue($value) public function setStopIfTrue($stopIfTrue)
{ {
$this->stopIfTrue = $value; $this->stopIfTrue = $stopIfTrue;
return $this; return $this;
} }
@ -189,16 +189,16 @@ class Conditional implements IComparable
/** /**
* Set Conditions. * Set Conditions.
* *
* @param string[] $pValue Condition * @param string[] $conditions Condition
* *
* @return $this * @return $this
*/ */
public function setConditions($pValue) public function setConditions($conditions)
{ {
if (!is_array($pValue)) { if (!is_array($conditions)) {
$pValue = [$pValue]; $conditions = [$conditions];
} }
$this->condition = $pValue; $this->condition = $conditions;
return $this; return $this;
} }
@ -206,13 +206,13 @@ class Conditional implements IComparable
/** /**
* Add Condition. * Add Condition.
* *
* @param string $pValue Condition * @param string $comdition Condition
* *
* @return $this * @return $this
*/ */
public function addCondition($pValue) public function addCondition($comdition)
{ {
$this->condition[] = $pValue; $this->condition[] = $comdition;
return $this; return $this;
} }
@ -230,13 +230,13 @@ class Conditional implements IComparable
/** /**
* Set Style. * Set Style.
* *
* @param Style $pValue * @param Style $style
* *
* @return $this * @return $this
*/ */
public function setStyle(?Style $pValue = null) public function setStyle(?Style $style = null)
{ {
$this->style = $pValue; $this->style = $style;
return $this; return $this;
} }

View File

@ -135,30 +135,30 @@ class Fill extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['fillType'])) { if (isset($styleArray['fillType'])) {
$this->setFillType($pStyles['fillType']); $this->setFillType($styleArray['fillType']);
} }
if (isset($pStyles['rotation'])) { if (isset($styleArray['rotation'])) {
$this->setRotation($pStyles['rotation']); $this->setRotation($styleArray['rotation']);
} }
if (isset($pStyles['startColor'])) { if (isset($styleArray['startColor'])) {
$this->getStartColor()->applyFromArray($pStyles['startColor']); $this->getStartColor()->applyFromArray($styleArray['startColor']);
} }
if (isset($pStyles['endColor'])) { if (isset($styleArray['endColor'])) {
$this->getEndColor()->applyFromArray($pStyles['endColor']); $this->getEndColor()->applyFromArray($styleArray['endColor']);
} }
if (isset($pStyles['color'])) { if (isset($styleArray['color'])) {
$this->getStartColor()->applyFromArray($pStyles['color']); $this->getStartColor()->applyFromArray($styleArray['color']);
$this->getEndColor()->applyFromArray($pStyles['color']); $this->getEndColor()->applyFromArray($styleArray['color']);
} }
} }
@ -182,17 +182,17 @@ class Fill extends Supervisor
/** /**
* Set Fill Type. * Set Fill Type.
* *
* @param string $pValue Fill type, see self::FILL_* * @param string $fillType Fill type, see self::FILL_*
* *
* @return $this * @return $this
*/ */
public function setFillType($pValue) public function setFillType($fillType)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['fillType' => $pValue]); $styleArray = $this->getStyleArray(['fillType' => $fillType]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->fillType = $pValue; $this->fillType = $fillType;
} }
return $this; return $this;
@ -215,17 +215,17 @@ class Fill extends Supervisor
/** /**
* Set Rotation. * Set Rotation.
* *
* @param float $pValue * @param float $angleInDegrees
* *
* @return $this * @return $this
*/ */
public function setRotation($pValue) public function setRotation($angleInDegrees)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['rotation' => $pValue]); $styleArray = $this->getStyleArray(['rotation' => $angleInDegrees]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->rotation = $pValue; $this->rotation = $angleInDegrees;
} }
return $this; return $this;
@ -246,10 +246,10 @@ class Fill extends Supervisor
* *
* @return $this * @return $this
*/ */
public function setStartColor(Color $pValue) public function setStartColor(Color $color)
{ {
// make sure parameter is a real color and not a supervisor // 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) { if ($this->isSupervisor) {
$styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]); $styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]);
@ -276,10 +276,10 @@ class Fill extends Supervisor
* *
* @return $this * @return $this
*/ */
public function setEndColor(Color $pValue) public function setEndColor(Color $color)
{ {
// make sure parameter is a real color and not a supervisor // 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) { if ($this->isSupervisor) {
$styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]); $styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]);

View File

@ -155,41 +155,41 @@ class Font extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['name'])) { if (isset($styleArray['name'])) {
$this->setName($pStyles['name']); $this->setName($styleArray['name']);
} }
if (isset($pStyles['bold'])) { if (isset($styleArray['bold'])) {
$this->setBold($pStyles['bold']); $this->setBold($styleArray['bold']);
} }
if (isset($pStyles['italic'])) { if (isset($styleArray['italic'])) {
$this->setItalic($pStyles['italic']); $this->setItalic($styleArray['italic']);
} }
if (isset($pStyles['superscript'])) { if (isset($styleArray['superscript'])) {
$this->setSuperscript($pStyles['superscript']); $this->setSuperscript($styleArray['superscript']);
} }
if (isset($pStyles['subscript'])) { if (isset($styleArray['subscript'])) {
$this->setSubscript($pStyles['subscript']); $this->setSubscript($styleArray['subscript']);
} }
if (isset($pStyles['underline'])) { if (isset($styleArray['underline'])) {
$this->setUnderline($pStyles['underline']); $this->setUnderline($styleArray['underline']);
} }
if (isset($pStyles['strikethrough'])) { if (isset($styleArray['strikethrough'])) {
$this->setStrikethrough($pStyles['strikethrough']); $this->setStrikethrough($styleArray['strikethrough']);
} }
if (isset($pStyles['color'])) { if (isset($styleArray['color'])) {
$this->getColor()->applyFromArray($pStyles['color']); $this->getColor()->applyFromArray($styleArray['color']);
} }
if (isset($pStyles['size'])) { if (isset($styleArray['size'])) {
$this->setSize($pStyles['size']); $this->setSize($styleArray['size']);
} }
} }
@ -213,20 +213,20 @@ class Font extends Supervisor
/** /**
* Set Name. * Set Name.
* *
* @param string $pValue * @param string $fontName
* *
* @return $this * @return $this
*/ */
public function setName($pValue) public function setName($fontName)
{ {
if ($pValue == '') { if ($fontName == '') {
$pValue = 'Calibri'; $fontName = 'Calibri';
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['name' => $pValue]); $styleArray = $this->getStyleArray(['name' => $fontName]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->name = $pValue; $this->name = $fontName;
} }
return $this; return $this;
@ -249,20 +249,20 @@ class Font extends Supervisor
/** /**
* Set Size. * Set Size.
* *
* @param float $pValue * @param float $fontSize
* *
* @return $this * @return $this
*/ */
public function setSize($pValue) public function setSize($fontSize)
{ {
if ($pValue == '') { if ($fontSize == '') {
$pValue = 10; $fontSize = 10;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['size' => $pValue]); $styleArray = $this->getStyleArray(['size' => $fontSize]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->size = $pValue; $this->size = $fontSize;
} }
return $this; return $this;
@ -285,20 +285,20 @@ class Font extends Supervisor
/** /**
* Set Bold. * Set Bold.
* *
* @param bool $pValue * @param bool $bold
* *
* @return $this * @return $this
*/ */
public function setBold($pValue) public function setBold($bold)
{ {
if ($pValue == '') { if ($bold == '') {
$pValue = false; $bold = false;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['bold' => $pValue]); $styleArray = $this->getStyleArray(['bold' => $bold]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->bold = $pValue; $this->bold = $bold;
} }
return $this; return $this;
@ -321,20 +321,20 @@ class Font extends Supervisor
/** /**
* Set Italic. * Set Italic.
* *
* @param bool $pValue * @param bool $italic
* *
* @return $this * @return $this
*/ */
public function setItalic($pValue) public function setItalic($italic)
{ {
if ($pValue == '') { if ($italic == '') {
$pValue = false; $italic = false;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['italic' => $pValue]); $styleArray = $this->getStyleArray(['italic' => $italic]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->italic = $pValue; $this->italic = $italic;
} }
return $this; return $this;
@ -359,13 +359,13 @@ class Font extends Supervisor
* *
* @return $this * @return $this
*/ */
public function setSuperscript(bool $pValue) public function setSuperscript(bool $superscript)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['superscript' => $pValue]); $styleArray = $this->getStyleArray(['superscript' => $superscript]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->superscript = $pValue; $this->superscript = $superscript;
if ($this->superscript) { if ($this->superscript) {
$this->subscript = false; $this->subscript = false;
} }
@ -393,13 +393,13 @@ class Font extends Supervisor
* *
* @return $this * @return $this
*/ */
public function setSubscript(bool $pValue) public function setSubscript(bool $subscript)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['subscript' => $pValue]); $styleArray = $this->getStyleArray(['subscript' => $subscript]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->subscript = $pValue; $this->subscript = $subscript;
if ($this->subscript) { if ($this->subscript) {
$this->superscript = false; $this->superscript = false;
} }
@ -425,24 +425,24 @@ class Font extends Supervisor
/** /**
* Set Underline. * 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, * If a boolean is passed, then TRUE equates to UNDERLINE_SINGLE,
* false equates to UNDERLINE_NONE * false equates to UNDERLINE_NONE
* *
* @return $this * @return $this
*/ */
public function setUnderline($pValue) public function setUnderline($underlineStyle)
{ {
if (is_bool($pValue)) { if (is_bool($underlineStyle)) {
$pValue = ($pValue) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE; $underlineStyle = ($underlineStyle) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE;
} elseif ($pValue == '') { } elseif ($underlineStyle == '') {
$pValue = self::UNDERLINE_NONE; $underlineStyle = self::UNDERLINE_NONE;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['underline' => $pValue]); $styleArray = $this->getStyleArray(['underline' => $underlineStyle]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->underline = $pValue; $this->underline = $underlineStyle;
} }
return $this; return $this;
@ -465,21 +465,21 @@ class Font extends Supervisor
/** /**
* Set Strikethrough. * Set Strikethrough.
* *
* @param bool $pValue * @param bool $strikethru
* *
* @return $this * @return $this
*/ */
public function setStrikethrough($pValue) public function setStrikethrough($strikethru)
{ {
if ($pValue == '') { if ($strikethru == '') {
$pValue = false; $strikethru = false;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['strikethrough' => $pValue]); $styleArray = $this->getStyleArray(['strikethrough' => $strikethru]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->strikethrough = $pValue; $this->strikethrough = $strikethru;
} }
return $this; return $this;
@ -500,10 +500,10 @@ class Font extends Supervisor
* *
* @return $this * @return $this
*/ */
public function setColor(Color $pValue) public function setColor(Color $color)
{ {
// make sure parameter is a real color and not a supervisor // 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) { if ($this->isSupervisor) {
$styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]); $styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]);

View File

@ -134,17 +134,17 @@ class NumberFormat extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['formatCode'])) { if (isset($styleArray['formatCode'])) {
$this->setFormatCode($pStyles['formatCode']); $this->setFormatCode($styleArray['formatCode']);
} }
} }
@ -171,21 +171,21 @@ class NumberFormat extends Supervisor
/** /**
* Set Format Code. * Set Format Code.
* *
* @param string $pValue see self::FORMAT_* * @param string $formatCode see self::FORMAT_*
* *
* @return $this * @return $this
*/ */
public function setFormatCode($pValue) public function setFormatCode($formatCode)
{ {
if ($pValue == '') { if ($formatCode == '') {
$pValue = self::FORMAT_GENERAL; $formatCode = self::FORMAT_GENERAL;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['formatCode' => $pValue]); $styleArray = $this->getStyleArray(['formatCode' => $formatCode]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->formatCode = $pValue; $this->formatCode = $formatCode;
$this->builtInFormatCode = self::builtInFormatCodeIndex($pValue); $this->builtInFormatCode = self::builtInFormatCodeIndex($formatCode);
} }
return $this; return $this;
@ -208,18 +208,18 @@ class NumberFormat extends Supervisor
/** /**
* Set Built-In Format Code. * Set Built-In Format Code.
* *
* @param int $pValue * @param int $formatCodeIndex
* *
* @return $this * @return $this
*/ */
public function setBuiltInFormatCode($pValue) public function setBuiltInFormatCode($formatCodeIndex)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($pValue)]); $styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($formatCodeIndex)]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->builtInFormatCode = $pValue; $this->builtInFormatCode = $formatCodeIndex;
$this->formatCode = self::builtInFormatCode($pValue); $this->formatCode = self::builtInFormatCode($formatCodeIndex);
} }
return $this; return $this;
@ -331,21 +331,21 @@ class NumberFormat extends Supervisor
/** /**
* Get built-in format code. * Get built-in format code.
* *
* @param int $pIndex * @param int $index
* *
* @return string * @return string
*/ */
public static function builtInFormatCode($pIndex) public static function builtInFormatCode($index)
{ {
// Clean parameter // Clean parameter
$pIndex = (int) $pIndex; $index = (int) $index;
// Ensure built-in format codes are available // Ensure built-in format codes are available
self::fillBuiltInFormatCodes(); self::fillBuiltInFormatCodes();
// Lookup format code // Lookup format code
if (isset(self::$builtInFormats[$pIndex])) { if (isset(self::$builtInFormats[$index])) {
return self::$builtInFormats[$pIndex]; return self::$builtInFormats[$index];
} }
return ''; return '';
@ -354,18 +354,18 @@ class NumberFormat extends Supervisor
/** /**
* Get built-in format code index. * Get built-in format code index.
* *
* @param string $formatCode * @param string $formatCodeIndex
* *
* @return bool|int * @return bool|int
*/ */
public static function builtInFormatCodeIndex($formatCode) public static function builtInFormatCodeIndex($formatCodeIndex)
{ {
// Ensure built-in format codes are available // Ensure built-in format codes are available
self::fillBuiltInFormatCodes(); self::fillBuiltInFormatCodes();
// Lookup format code // Lookup format code
if (array_key_exists($formatCode, self::$flippedBuiltInFormats)) { if (array_key_exists($formatCodeIndex, self::$flippedBuiltInFormats)) {
return self::$flippedBuiltInFormats[$formatCode]; return self::$flippedBuiltInFormats[$formatCodeIndex];
} }
return false; return false;

View File

@ -80,20 +80,20 @@ class Protection extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles) public function applyFromArray(array $styleArray)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
} else { } else {
if (isset($pStyles['locked'])) { if (isset($styleArray['locked'])) {
$this->setLocked($pStyles['locked']); $this->setLocked($styleArray['locked']);
} }
if (isset($pStyles['hidden'])) { if (isset($styleArray['hidden'])) {
$this->setHidden($pStyles['hidden']); $this->setHidden($styleArray['hidden']);
} }
} }
@ -117,17 +117,17 @@ class Protection extends Supervisor
/** /**
* Set locked. * Set locked.
* *
* @param string $pValue see self::PROTECTION_* * @param string $lockType see self::PROTECTION_*
* *
* @return $this * @return $this
*/ */
public function setLocked($pValue) public function setLocked($lockType)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['locked' => $pValue]); $styleArray = $this->getStyleArray(['locked' => $lockType]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->locked = $pValue; $this->locked = $lockType;
} }
return $this; return $this;
@ -150,17 +150,17 @@ class Protection extends Supervisor
/** /**
* Set hidden. * Set hidden.
* *
* @param string $pValue see self::PROTECTION_* * @param string $hiddenType see self::PROTECTION_*
* *
* @return $this * @return $this
*/ */
public function setHidden($pValue) public function setHidden($hiddenType)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['hidden' => $pValue]); $styleArray = $this->getStyleArray(['hidden' => $hiddenType]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->hidden = $pValue; $this->hidden = $hiddenType;
} }
return $this; return $this;

View File

@ -184,12 +184,12 @@ class Style extends Supervisor
* ); * );
* </code> * </code>
* *
* @param array $pStyles Array containing style information * @param array $styleArray Array containing style information
* @param bool $pAdvanced advanced mode for setting borders * @param bool $advancedBorders advanced mode for setting borders
* *
* @return $this * @return $this
*/ */
public function applyFromArray(array $pStyles, $pAdvanced = true) public function applyFromArray(array $styleArray, $advancedBorders = true)
{ {
if ($this->isSupervisor) { if ($this->isSupervisor) {
$pRange = $this->getSelectedCells(); $pRange = $this->getSelectedCells();
@ -221,36 +221,36 @@ class Style extends Supervisor
} }
// ADVANCED MODE: // ADVANCED MODE:
if ($pAdvanced && isset($pStyles['borders'])) { if ($advancedBorders && isset($styleArray['borders'])) {
// 'allBorders' is a shorthand property for 'outline' and 'inside' and // 'allBorders' is a shorthand property for 'outline' and 'inside' and
// it applies to components that have not been set explicitly // 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) { foreach (['outline', 'inside'] as $component) {
if (!isset($pStyles['borders'][$component])) { if (!isset($styleArray['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['allBorders']; $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' // 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left'
// it applies to components that have not been set explicitly // 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) { foreach (['top', 'right', 'bottom', 'left'] as $component) {
if (!isset($pStyles['borders'][$component])) { if (!isset($styleArray['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['outline']; $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' // 'inside' is a shorthand property for 'vertical' and 'horizontal'
// it applies to components that have not been set explicitly // 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) { foreach (['vertical', 'horizontal'] as $component) {
if (!isset($pStyles['borders'][$component])) { if (!isset($styleArray['borders'][$component])) {
$pStyles['borders'][$component] = $pStyles['borders']['inside']; $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) // width and height characteristics of selection, 1, 2, or 3 (for 3 or more)
$xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3); $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3);
@ -299,7 +299,7 @@ class Style extends Supervisor
$range = $colStart . $rowStart . ':' . $colEnd . $rowEnd; $range = $colStart . $rowStart . ':' . $colEnd . $rowEnd;
// retrieve relevant style array for region // retrieve relevant style array for region
$regionStyles = $pStyles; $regionStyles = $styleArray;
unset($regionStyles['borders']['inside']); unset($regionStyles['borders']['inside']);
// what are the inner edges of the region when looking at the selection // what are the inner edges of the region when looking at the selection
@ -311,8 +311,8 @@ class Style extends Supervisor
case 'top': case 'top':
case 'bottom': case 'bottom':
// should pick up 'horizontal' border property if set // should pick up 'horizontal' border property if set
if (isset($pStyles['borders']['horizontal'])) { if (isset($styleArray['borders']['horizontal'])) {
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal']; $regionStyles['borders'][$innerEdge] = $styleArray['borders']['horizontal'];
} else { } else {
unset($regionStyles['borders'][$innerEdge]); unset($regionStyles['borders'][$innerEdge]);
} }
@ -321,8 +321,8 @@ class Style extends Supervisor
case 'left': case 'left':
case 'right': case 'right':
// should pick up 'vertical' border property if set // should pick up 'vertical' border property if set
if (isset($pStyles['borders']['vertical'])) { if (isset($styleArray['borders']['vertical'])) {
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical']; $regionStyles['borders'][$innerEdge] = $styleArray['borders']['vertical'];
} else { } else {
unset($regionStyles['borders'][$innerEdge]); unset($regionStyles['borders'][$innerEdge]);
} }
@ -388,7 +388,7 @@ class Style extends Supervisor
foreach ($oldXfIndexes as $oldXfIndex => $dummy) { foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
$style = $workbook->getCellXfByIndex($oldXfIndex); $style = $workbook->getCellXfByIndex($oldXfIndex);
$newStyle = clone $style; $newStyle = clone $style;
$newStyle->applyFromArray($pStyles); $newStyle->applyFromArray($styleArray);
if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) { if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
// there is already such cell Xf in our collection // there is already such cell Xf in our collection
@ -432,26 +432,26 @@ class Style extends Supervisor
} }
} else { } else {
// not a supervisor, just apply the style array directly on style object // not a supervisor, just apply the style array directly on style object
if (isset($pStyles['fill'])) { if (isset($styleArray['fill'])) {
$this->getFill()->applyFromArray($pStyles['fill']); $this->getFill()->applyFromArray($styleArray['fill']);
} }
if (isset($pStyles['font'])) { if (isset($styleArray['font'])) {
$this->getFont()->applyFromArray($pStyles['font']); $this->getFont()->applyFromArray($styleArray['font']);
} }
if (isset($pStyles['borders'])) { if (isset($styleArray['borders'])) {
$this->getBorders()->applyFromArray($pStyles['borders']); $this->getBorders()->applyFromArray($styleArray['borders']);
} }
if (isset($pStyles['alignment'])) { if (isset($styleArray['alignment'])) {
$this->getAlignment()->applyFromArray($pStyles['alignment']); $this->getAlignment()->applyFromArray($styleArray['alignment']);
} }
if (isset($pStyles['numberFormat'])) { if (isset($styleArray['numberFormat'])) {
$this->getNumberFormat()->applyFromArray($pStyles['numberFormat']); $this->getNumberFormat()->applyFromArray($styleArray['numberFormat']);
} }
if (isset($pStyles['protection'])) { if (isset($styleArray['protection'])) {
$this->getProtection()->applyFromArray($pStyles['protection']); $this->getProtection()->applyFromArray($styleArray['protection']);
} }
if (isset($pStyles['quotePrefix'])) { if (isset($styleArray['quotePrefix'])) {
$this->quotePrefix = $pStyles['quotePrefix']; $this->quotePrefix = $styleArray['quotePrefix'];
} }
} }
@ -533,13 +533,13 @@ class Style extends Supervisor
/** /**
* Set Conditional Styles. Only used on supervisor. * Set Conditional Styles. Only used on supervisor.
* *
* @param Conditional[] $pValue Array of conditional styles * @param Conditional[] $conditionalStyleArray Array of conditional styles
* *
* @return $this * @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; return $this;
} }
@ -571,20 +571,20 @@ class Style extends Supervisor
/** /**
* Set quote prefix. * Set quote prefix.
* *
* @param bool $pValue * @param bool $quotePrefix
* *
* @return $this * @return $this
*/ */
public function setQuotePrefix($pValue) public function setQuotePrefix($quotePrefix)
{ {
if ($pValue == '') { if ($quotePrefix == '') {
$pValue = false; $quotePrefix = false;
} }
if ($this->isSupervisor) { if ($this->isSupervisor) {
$styleArray = ['quotePrefix' => $pValue]; $styleArray = ['quotePrefix' => $quotePrefix];
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->quotePrefix = (bool) $pValue; $this->quotePrefix = (bool) $quotePrefix;
} }
return $this; return $this;
@ -628,11 +628,11 @@ class Style extends Supervisor
/** /**
* Set own index in style collection. * 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 protected function exportArray1(): array