Skip to content

Commit e22c4ce

Browse files
committed
fix: Allow vAlign and vMerge on Style\Cell to be set to null (#2673)
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.
1 parent fa0cea0 commit e22c4ce

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/PhpWord/Style/Cell.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Cell extends Border
6969
/**
7070
* Vertical align (top, center, both, bottom).
7171
*
72-
* @var string
72+
* @var null|string
7373
*/
7474
private $vAlign;
7575

@@ -93,7 +93,7 @@ class Cell extends Border
9393
* - restart: Start/restart merged region
9494
* - continue: Continue merged region
9595
*
96-
* @var string
96+
* @var null|string
9797
*/
9898
private $vMerge;
9999

@@ -128,7 +128,7 @@ class Cell extends Border
128128
/**
129129
* Get vertical align.
130130
*
131-
* @return string
131+
* @return null|string
132132
*/
133133
public function getVAlign()
134134
{
@@ -138,12 +138,18 @@ public function getVAlign()
138138
/**
139139
* Set vertical align.
140140
*
141-
* @param string $value
141+
* @param null|string $value
142142
*
143143
* @return self
144144
*/
145145
public function setVAlign($value = null)
146146
{
147+
if ($value === null) {
148+
$this->vAlign = null;
149+
150+
return $this;
151+
}
152+
147153
VerticalJc::validate($value);
148154
$this->vAlign = $this->setEnumVal($value, VerticalJc::values(), $this->vAlign);
149155

@@ -235,7 +241,7 @@ public function setGridSpan($value = null)
235241
/**
236242
* Get vertical merge (rowspan).
237243
*
238-
* @return string
244+
* @return null|string
239245
*/
240246
public function getVMerge()
241247
{
@@ -245,12 +251,18 @@ public function getVMerge()
245251
/**
246252
* Set vertical merge (rowspan).
247253
*
248-
* @param string $value
254+
* @param null|string $value
249255
*
250256
* @return self
251257
*/
252258
public function setVMerge($value = null)
253259
{
260+
if ($value === null) {
261+
$this->vMerge = null;
262+
263+
return $this;
264+
}
265+
254266
$enum = [self::VMERGE_RESTART, self::VMERGE_CONTINUE];
255267
$this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge);
256268

0 commit comments

Comments
 (0)