-
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.
Added Nullable Types and added some just integration-tested coverage in unit tests
- Loading branch information
Showing
12 changed files
with
167 additions
and
22 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,27 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Isfett\PhpAnalyzer\Node\Representation; | ||
|
||
/** | ||
* Class NullableType | ||
*/ | ||
class NullableType extends AbstractRepresentation | ||
{ | ||
/** @var string */ | ||
private const NULLABLE_OPERATOR = '?'; | ||
|
||
/** @var string */ | ||
private const REPRESENTATION_FORMAT = '%s%s'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function representation(): string | ||
{ | ||
/** @var \PhpParser\Node\NullableType $node */ | ||
$node = $this->node; | ||
|
||
return sprintf(self::REPRESENTATION_FORMAT, self::NULLABLE_OPERATOR, $this->representate($node->type)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
class ApplicationTest extends TestCase | ||
{ | ||
/** @var string */ | ||
private const APPLICATION_INFO = 'php-analyzer 1.2.3 by Christopher Stenke <[email protected]>' . \PHP_EOL; | ||
private const APPLICATION_INFO = 'php-analyzer 1.2.4 by Christopher Stenke <[email protected]>' . \PHP_EOL; | ||
|
||
/** @var Application */ | ||
private $application; | ||
|
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,47 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Isfett\PhpAnalyzer\Tests\Unit\Node\Representation; | ||
|
||
use Isfett\PhpAnalyzer\Node\Representation\NullableType; | ||
use PhpParser\Node; | ||
|
||
/** | ||
* Class NullableTypeTest | ||
*/ | ||
class NullableTypeTest extends AbstractNodeRepresentationTest | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetRepresentation(): void | ||
{ | ||
$node = new Node\NullableType( | ||
new Node\Param( | ||
new Node\Expr\Variable('x'), | ||
null, | ||
new Node\Identifier('int'), | ||
false, | ||
false, | ||
$this->getNodeAttributes() | ||
), | ||
$this->getNodeAttributes() | ||
); | ||
|
||
$this->nodeRepresentationService | ||
->method('representationForNode') | ||
->willReturn('int'); | ||
|
||
$representation = new NullableType($this->nodeRepresentationService, $node); | ||
|
||
$this->assertSame('?int', $representation->representation()); | ||
} | ||
} |
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