-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from phug-php/multitest-php-8
Fix PHP 8 compatibility
- Loading branch information
Showing
12 changed files
with
140 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Phug\Formatter\Util; | ||
|
||
class PhpUnwrapString | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $code; | ||
|
||
public function __construct($code) | ||
{ | ||
$this->code = $code; | ||
} | ||
|
||
public static function withoutOpenTag($code) | ||
{ | ||
$unwrappedCode = new self($code); | ||
$unwrappedCode->unwrapStart(); | ||
$unwrappedCode->movePhugCodeAfterNamespace(); | ||
|
||
return $unwrappedCode; | ||
} | ||
|
||
public function movePhugCodeAfterNamespace() | ||
{ | ||
$this->code = preg_replace( | ||
'/^((?:[ \t]*(?:\\\\Phug\\\\.*\n|\\/\\/.*\n|(?:\?><\?php)?[ \t\n]+)?)*)(namespace (?:.*)\n)/', | ||
'$2$1', | ||
$this->code | ||
); | ||
} | ||
|
||
public function unwrapStart() | ||
{ | ||
$this->code = preg_match('/^<\?php\s/', $this->code) | ||
? mb_substr($this->code, 6) | ||
: '?>'.$this->code; | ||
} | ||
public function unwrapEnd() | ||
{ | ||
$this->code = preg_match('/\s\?>$/', $this->code) && strpos($this->code, '<?=') === false | ||
? mb_substr($this->code, 0, -3).';' | ||
: $this->code.'<?php'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCode() | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Phug\Test\Util; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Phug\Formatter\Util\PhpUnwrapString; | ||
|
||
/** | ||
* @coversDefaultClass \Phug\Formatter\Util\PhpUnwrapString | ||
*/ | ||
class PhpUnwrapStringTest extends TestCase | ||
{ | ||
/** | ||
* @covers \Phug\Formatter\Util\PhpUnwrapString::<public> | ||
* @covers ::<public> | ||
*/ | ||
public function testPhpUnwrapString() | ||
{ | ||
self::assertSame('echo "Foo";', (string) PhpUnwrapString::withoutOpenTag('<?php echo "Foo";')); | ||
self::assertSame('echo "Foo"; ?>', (string) PhpUnwrapString::withoutOpenTag('<?php echo "Foo"; ?>')); | ||
self::assertSame('?><div><?php echo "Foo"; ?></div>', (string) PhpUnwrapString::withoutOpenTag('<div><?php echo "Foo"; ?></div>')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test | ||
test2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
- | ||
namespace Test; | ||
class Req { | ||
public $text; | ||
public function __construct($n = '') { | ||
$this->text = "test$n\n"; | ||
} | ||
public function suffix($n) { | ||
return new Req($n); | ||
} | ||
} | ||
class Test { | ||
static public function app() { | ||
return new Req(); | ||
} | ||
} | ||
= \Test\Test::app()->text | ||
= \Test\Test::app()->suffix(2)->text |