Skip to content

Commit

Permalink
Merge pull request #128 from wvega/issue-127/keep-parenthesis-around-…
Browse files Browse the repository at this point in the history
…anonymous-class-parameters

Keep parenthesis around anonymous class parameters
  • Loading branch information
antecedent authored Feb 7, 2022
2 parents dbe712f + 0b23e0b commit 535fd48
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CodeManipulation/Actions/RedefinitionOfNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function hasExtraParentheses(Source $s, $new)
T_ARRAY,
T_PRINT,
T_ECHO,
T_CLASS,
Generic\NAME_FULLY_QUALIFIED,
Generic\NAME_QUALIFIED,
Generic\NAME_RELATIVE,
Expand Down
27 changes: 27 additions & 0 deletions tests/includes/RedefinitionOfNewAsAnonymousClassParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Foo
{
class TestClass
{
}
}

namespace Bar
{
use Foo\TestClass;
use stdClass;

\Patchwork\redefine('new Foo\TestClass', \Patchwork\always(new stdClass));

$test = new class(new TestClass()) {
public $object;

public function __construct($object)
{
$this->object = $object;
}
};

assert($test->object instanceof stdClass);
}
20 changes: 20 additions & 0 deletions tests/redefine-new-anonymous-class-paramter.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
https://github.com/antecedent/patchwork/issues/127

--FILE--
<?php

assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
error_reporting(E_ALL | E_STRICT);

$_SERVER['PHP_SELF'] = __FILE__;

require __DIR__ . "/../Patchwork.php";
require __DIR__ . "/includes/RedefinitionOfNewAsAnonymousClassParameter.php";

?>
===DONE===

--EXPECT--
===DONE===

0 comments on commit 535fd48

Please sign in to comment.