Skip to content

Commit

Permalink
fix: Allow vAlign and vMerge on Style\Cell to be set to null (#2673)
Browse files Browse the repository at this point in the history
vAlign and vMerge are initialized as `null` in every style until it is explicitly set.
Right now, it is not possible to unset them, after it has been set once.

I've added a null-check to skip the validation, based on the default
parameter value of `null`, which indicates to me that it once was intended to work like this.

I've also fixed the type-hints, which were wrong from the start.
  • Loading branch information
SpraxDev committed Sep 12, 2024
1 parent 2e4f3cf commit c5207f2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/PhpWord/Style/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Cell extends Border
/**
* Vertical align (top, center, both, bottom).
*
* @var string
* @var null|string
*/
private $vAlign;

Expand All @@ -93,7 +93,7 @@ class Cell extends Border
* - restart: Start/restart merged region
* - continue: Continue merged region
*
* @var string
* @var null|string
*/
private $vMerge;

Expand Down Expand Up @@ -128,7 +128,7 @@ class Cell extends Border
/**
* Get vertical align.
*
* @return string
* @return null|string
*/
public function getVAlign()
{
Expand All @@ -138,12 +138,18 @@ public function getVAlign()
/**
* Set vertical align.
*
* @param string $value
* @param null|string $value
*
* @return self
*/
public function setVAlign($value = null)
{
if ($value === null) {
$this->vAlign = null;

return $this;
}

VerticalJc::validate($value);
$this->vAlign = $this->setEnumVal($value, VerticalJc::values(), $this->vAlign);

Expand Down Expand Up @@ -235,7 +241,7 @@ public function setGridSpan($value = null)
/**
* Get vertical merge (rowspan).
*
* @return string
* @return null|string
*/
public function getVMerge()
{
Expand All @@ -245,12 +251,18 @@ public function getVMerge()
/**
* Set vertical merge (rowspan).
*
* @param string $value
* @param null|string $value
*
* @return self
*/
public function setVMerge($value = null)
{
if ($value === null) {
$this->vMerge = null;

return $this;
}

$enum = [self::VMERGE_RESTART, self::VMERGE_CONTINUE];
$this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge);

Expand Down

0 comments on commit c5207f2

Please sign in to comment.