|
23 | 23 | use PhpOffice\PhpWord\Media;
|
24 | 24 | use PhpOffice\PhpWord\PhpWord;
|
25 | 25 | use PhpOffice\PhpWord\Style;
|
| 26 | +use PhpOffice\PhpWord\Style\AbstractStyle; |
| 27 | + |
| 28 | +use function is_array; |
26 | 29 |
|
27 | 30 | /**
|
28 | 31 | * Element abstract class.
|
@@ -256,7 +259,7 @@ public function getElementId()
|
256 | 259 | */
|
257 | 260 | public function setElementId(): void
|
258 | 261 | {
|
259 |
| - $this->elementId = substr(md5(mt_rand()), 0, 6); |
| 262 | + $this->elementId = substr(md5((string) mt_rand()), 0, 6); |
260 | 263 | }
|
261 | 264 |
|
262 | 265 | /**
|
@@ -481,22 +484,24 @@ public function isInSection()
|
481 | 484 | /**
|
482 | 485 | * Set new style value.
|
483 | 486 | *
|
484 |
| - * @param mixed $styleObject Style object |
485 |
| - * @param null|array|string|Style $styleValue Style value |
| 487 | + * @param AbstractStyle $styleObject Style object |
| 488 | + * @param null|string|array|AbstractStyle $styleValue Style value |
486 | 489 | * @param bool $returnObject Always return object
|
487 | 490 | *
|
488 |
| - * @return mixed |
| 491 | + * @return null|string|array|AbstractStyle |
489 | 492 | */
|
490 | 493 | protected function setNewStyle($styleObject, $styleValue = null, $returnObject = false)
|
491 | 494 | {
|
492 |
| - if (null !== $styleValue && is_array($styleValue)) { |
| 495 | + if ($styleValue instanceof AbstractStyle && get_class($styleValue) === get_class($styleObject)) { |
| 496 | + return clone $styleValue; |
| 497 | + } |
| 498 | + |
| 499 | + if (is_array($styleValue)) { |
493 | 500 | $styleObject->setStyleByArray($styleValue);
|
494 |
| - $style = $styleObject; |
495 |
| - } else { |
496 |
| - $style = $returnObject ? $styleObject : $styleValue; |
| 501 | + return $styleObject; |
497 | 502 | }
|
498 | 503 |
|
499 |
| - return $style; |
| 504 | + return $returnObject === true ? $styleObject : $styleValue; |
500 | 505 | }
|
501 | 506 |
|
502 | 507 | /**
|
|
0 commit comments