Skip to content

Commit

Permalink
PHP 8.0 | PSR12/ClassInstantiation: allow for nullsafe object operator
Browse files Browse the repository at this point in the history
Includes unit tests.
  • Loading branch information
jrfnl committed Sep 1, 2020
1 parent 85f3521 commit 877e89f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Standards/PSR12/Sniffs/Classes/ClassInstantiationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public function process(File $phpcsFile, $stackPtr)

// Find the class name.
$allowed = [
T_STRING => T_STRING,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_SELF => T_SELF,
T_STATIC => T_STATIC,
T_VARIABLE => T_VARIABLE,
T_DOLLAR => T_DOLLAR,
T_OBJECT_OPERATOR => T_OBJECT_OPERATOR,
T_DOUBLE_COLON => T_DOUBLE_COLON,
T_STRING => T_STRING,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_SELF => T_SELF,
T_STATIC => T_STATIC,
T_VARIABLE => T_VARIABLE,
T_DOLLAR => T_DOLLAR,
T_OBJECT_OPERATOR => T_OBJECT_OPERATOR,
T_NULLSAFE_OBJECT_OPERATOR => T_NULLSAFE_OBJECT_OPERATOR,
T_DOUBLE_COLON => T_DOUBLE_COLON,
];

$allowed += Tokens::$emptyTokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ $foo = new $bar['a'] [$baz['a']/* comment */ ['b']]['b'];
$a = new self::$transport[$cap_string];
$renderer = new $this->inline_diff_renderer;
$a = new ${$varHoldingClassName};

$class = new $obj?->classname();
$class = new $obj?->classname;
$class = new ${$obj?->classname};
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ $foo = new $bar['a'] [$baz['a']/* comment */ ['b']]['b']();
$a = new self::$transport[$cap_string]();
$renderer = new $this->inline_diff_renderer();
$a = new ${$varHoldingClassName}();

$class = new $obj?->classname();
$class = new $obj?->classname();
$class = new ${$obj?->classname}();
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function getErrorList()
32 => 1,
33 => 1,
34 => 1,
37 => 1,
38 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 877e89f

Please sign in to comment.