Fix PHPStan parameter type error introduced after update to version 0.12.83

This commit fixes the following PHPStan errors introduced after the update to version 0.12.83:

```
 ------ ----------------------------------------------------------------------
  Line   lib/Newsletter/Renderer/Blocks/Footer.php
 ------ ----------------------------------------------------------------------
  18     Parameter #1 $html of method MailPoet\Util\pQuery\pQuery::parseStr()
         expects string, array|string|null given.
 ------ ----------------------------------------------------------------------

 ------ ----------------------------------------------------------------------
  Line   lib/Newsletter/Renderer/Blocks/Header.php
 ------ ----------------------------------------------------------------------
  18     Parameter #1 $html of method MailPoet\Util\pQuery\pQuery::parseStr()
         expects string, array|string|null given.
 ------ ----------------------------------------------------------------------
```

[MAILPOET-3491]
This commit is contained in:
Rodrigo Primo
2021-04-06 15:23:56 -03:00
committed by Veljko V
parent 90526362cc
commit 030bd8c1c8
4 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,9 @@ class Footer {
$lineHeight = sprintf( $lineHeight = sprintf(
'%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize'] '%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize']
); );
if (!is_string($element['text'])) {
throw new \RuntimeException('$element[\'text\'] should be a string.');
}
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($element['text']); $DOM = $dOMParser->parseStr($element['text']);
if (isset($element['styles']['link'])) { if (isset($element['styles']['link'])) {

View File

@ -14,6 +14,9 @@ class Header {
$lineHeight = sprintf( $lineHeight = sprintf(
'%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize'] '%spx', StylesHelper::$defaultLineHeight * (int)$element['styles']['text']['fontSize']
); );
if (!is_string($element['text'])) {
throw new \RuntimeException('$element[\'text\'] should be a string.');
}
$dOMParser = new pQuery(); $dOMParser = new pQuery();
$DOM = $dOMParser->parseStr($element['text']); $DOM = $dOMParser->parseStr($element['text']);
if (isset($element['styles']['link'])) { if (isset($element['styles']['link'])) {

View File

@ -52,4 +52,10 @@ class FooterTest extends \MailPoetUnitTest {
$output = (new Footer)->render($this->block); $output = (new Footer)->render($this->block);
expect($output)->stringContainsString('<a href="http://example.com" style="color:#aaaaaa;text-decoration:none">link</a>'); expect($output)->stringContainsString('<a href="http://example.com" style="color:#aaaaaa;text-decoration:none">link</a>');
} }
public function testItRaisesExceptionIfTextIsNotString() {
$this->block['text'] = ['some', 'array'];
$this->expectException('RuntimeException');
(new Footer)->render($this->block);
}
} }

View File

@ -52,4 +52,10 @@ class HeaderTest extends \MailPoetUnitTest {
$output = (new Footer)->render($this->block); $output = (new Footer)->render($this->block);
expect($output)->stringContainsString('<a href="http://example.com" style="color:#aaaaaa;text-decoration:underline">link</a>'); expect($output)->stringContainsString('<a href="http://example.com" style="color:#aaaaaa;text-decoration:underline">link</a>');
} }
public function testItRaisesExceptionIfTextIsNotString() {
$this->block['text'] = ['some', 'array'];
$this->expectException('RuntimeException');
(new Header)->render($this->block);
}
} }