Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up PHP 8.2 compatibility, duplicated test run #119

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Html2Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,17 @@ private function legacyConstruct($html = '', $fromFile = false, array $options =
*/
public function __construct($html = '', $options = array())
{
$this->htmlFuncFlags = (PHP_VERSION_ID < 50400)
? ENT_QUOTES
: ENT_QUOTES | ENT_HTML5;

// for backwards compatibility
if (!is_array($options)) {
return call_user_func_array(array($this, 'legacyConstruct'), func_get_args());
}

$this->html = $html;
$this->options = array_merge($this->options, $options);
$this->htmlFuncFlags = (PHP_VERSION_ID < 50400)
? ENT_QUOTES
: ENT_QUOTES | ENT_HTML5;
}

/**
Expand Down Expand Up @@ -351,7 +352,7 @@ protected function doConvert()
{
$this->linkList = array();

$text = trim($this->html);
$text = trim($this->html ?? '');

$this->converter($text);

Expand Down Expand Up @@ -389,7 +390,7 @@ protected function converter(&$text)
$text = preg_replace("/[\n]{3,}/", "\n\n", $text);

// remove leading empty lines (can be produced by eg. P tag on the beginning)
$text = ltrim($text, "\n");
$text = ltrim($text ?? '', "\n");

if ($this->options['width'] > 0) {
$text = wordwrap($text, $this->options['width']);
Expand Down
4 changes: 2 additions & 2 deletions test/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ImageTest extends TestCase
{
public function testImageDataProvider() {
public function imageDataProvider() {
return array(
'Without alt tag' => array(
'html' => '<img src="http://example.com/example.jpg">',
Expand Down Expand Up @@ -36,7 +36,7 @@ public function testImageDataProvider() {
}

/**
* @dataProvider testImageDataProvider
* @dataProvider imageDataProvider
*/
public function testImages($html, $expected)
{
Expand Down
8 changes: 4 additions & 4 deletions test/PrintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class PrintTest extends TestCase

public function testP()
{
$this->html = new Html2Text(self::TEST_HTML);
$this->html->p();
$html = new Html2Text(self::TEST_HTML);
$html->p();
$this->expectOutputString(self::EXPECTED);
}

public function testPrint_text()
{
$this->html = new Html2Text(self::TEST_HTML);
$this->html->print_text();
$html = new Html2Text(self::TEST_HTML);
$html->print_text();
$this->expectOutputString(self::EXPECTED);
}
}