-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
smoench
committed
Sep 18, 2020
1 parent
b6a886b
commit 9ca72bf
Showing
5 changed files
with
176 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\Types; | ||
|
||
use phpDocumentor\Reflection\Fqsen; | ||
use phpDocumentor\Reflection\Type; | ||
|
||
/** | ||
* Value Object representing the type 'string'. | ||
* | ||
* @psalm-immutable | ||
*/ | ||
final class InterfaceString implements Type | ||
{ | ||
/** @var Fqsen|null */ | ||
private $fqsen; | ||
|
||
/** | ||
* Initializes this representation of a class string with the given Fqsen. | ||
*/ | ||
public function __construct(?Fqsen $fqsen = null) | ||
{ | ||
$this->fqsen = $fqsen; | ||
} | ||
|
||
/** | ||
* Returns the FQSEN associated with this object. | ||
*/ | ||
public function getFqsen() : ?Fqsen | ||
{ | ||
return $this->fqsen; | ||
} | ||
|
||
/** | ||
* Returns a rendered output of the Type as it would be used in a DocBlock. | ||
*/ | ||
public function __toString() : string | ||
{ | ||
if ($this->fqsen === null) { | ||
return 'interface-string'; | ||
} | ||
|
||
return 'interface-string<' . (string) $this->fqsen . '>'; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\Types; | ||
|
||
use phpDocumentor\Reflection\Fqsen; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \phpDocumentor\Reflection\Types\ClassString | ||
*/ | ||
class InterfaceStringTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideInterfaceStrings | ||
* @covers ::__toString | ||
*/ | ||
public function testInterfaceStringStringifyCorrectly(ClassString $array, string $expectedString) : void | ||
{ | ||
$this->assertSame($expectedString, (string) $array); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function provideInterfaceStrings() : array | ||
{ | ||
return [ | ||
'generic interface string' => [new InterfaceString(), 'interface-string'], | ||
'typed interface string' => [new InterfaceString(new Fqsen('\Foo\Bar')), 'interface-string<\Foo\Bar>'], | ||
]; | ||
} | ||
} |