Skip to content

Commit 17e2f02

Browse files
committed
Type checks on style writers
1 parent 9567c6a commit 17e2f02

File tree

22 files changed

+207
-19
lines changed

22 files changed

+207
-19
lines changed

src/PhpWord/Writer/HTML/Style/Font.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class Font extends AbstractStyle
3535
public function write()
3636
{
3737
$style = $this->getStyle();
38+
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
39+
return;
40+
}
3841
$css = array();
3942

4043
$font = $style->getName();

src/PhpWord/Writer/HTML/Style/Image.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Image extends AbstractStyle
3232
public function write()
3333
{
3434
$style = $this->getStyle();
35+
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
36+
return;
37+
}
3538
$css = array();
3639

3740
$css['width'] = $this->getValueIf($style->getWidth(), $style->getWidth() . 'px');

src/PhpWord/Writer/HTML/Style/Paragraph.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class Paragraph extends AbstractStyle
3434
public function write()
3535
{
3636
$style = $this->getStyle();
37+
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
38+
return;
39+
}
3740
$css = array();
3841

3942
// Alignment

src/PhpWord/Writer/ODText/Style/Font.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class Font extends AbstractStyle
3434
*/
3535
public function write()
3636
{
37-
if (is_null($style = $this->getStyle())) {
37+
$style = $this->getStyle();
38+
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
3839
return;
3940
}
4041
$xmlWriter = $this->getXmlWriter();

src/PhpWord/Writer/ODText/Style/Paragraph.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class Paragraph extends AbstractStyle
3434
*/
3535
public function write()
3636
{
37-
if (is_null($style = $this->getStyle())) {
37+
$style = $this->getStyle();
38+
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
3839
return;
3940
}
4041
$xmlWriter = $this->getXmlWriter();

src/PhpWord/Writer/Word2007/Style/Cell.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class Cell extends AbstractStyle
3131
*/
3232
public function write()
3333
{
34-
if (is_null($style = $this->getStyle())) {
34+
$style = $this->getStyle();
35+
if (!$style instanceof \PhpOffice\PhpWord\Style\Cell) {
3536
return;
3637
}
3738
$xmlWriter = $this->getXmlWriter();

src/PhpWord/Writer/Word2007/Style/Font.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function write()
5757
*/
5858
private function writeStyle()
5959
{
60-
if (is_null($style = $this->getStyle())) {
60+
$style = $this->getStyle();
61+
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
6162
return;
6263
}
6364
$xmlWriter = $this->getXmlWriter();

src/PhpWord/Writer/Word2007/Style/Image.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ class Image extends AbstractStyle
3838
*/
3939
public function write()
4040
{
41-
if (!is_null($this->getStyle())) {
42-
$this->writeStyle();
41+
$style = $this->getStyle();
42+
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
43+
return;
4344
}
45+
$this->writeStyle();
4446
}
4547

4648
/**

src/PhpWord/Writer/Word2007/Style/Indentation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class Indentation extends AbstractStyle
2929
*/
3030
public function write()
3131
{
32-
if (is_null($style = $this->getStyle())) {
32+
$style = $this->getStyle();
33+
if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) {
3334
return;
3435
}
3536
$xmlWriter = $this->getXmlWriter();

src/PhpWord/Writer/Word2007/Style/LineNumbering.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class LineNumbering extends AbstractStyle
3131
*/
3232
public function write()
3333
{
34-
if (is_null($style = $this->getStyle())) {
34+
$style = $this->getStyle();
35+
if (!$style instanceof \PhpOffice\PhpWord\Style\LineNumbering) {
3536
return;
3637
}
3738
$xmlWriter = $this->getXmlWriter();

0 commit comments

Comments
 (0)