-
Notifications
You must be signed in to change notification settings - Fork 61
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
1 parent
d3753fc
commit 882eabc
Showing
5 changed files
with
467 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\PhpDocParser\Ast\Type; | ||
|
||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode; | ||
use PHPStan\PhpDocParser\Ast\NodeAttributes; | ||
use function sprintf; | ||
|
||
class ObjectShapeItemNode implements TypeNode | ||
{ | ||
|
||
use NodeAttributes; | ||
|
||
/** @var ConstExprStringNode|IdentifierTypeNode */ | ||
public $keyName; | ||
|
||
/** @var bool */ | ||
public $optional; | ||
|
||
/** @var TypeNode */ | ||
public $valueType; | ||
|
||
/** | ||
* @param ConstExprStringNode|IdentifierTypeNode $keyName | ||
*/ | ||
public function __construct($keyName, bool $optional, TypeNode $valueType) | ||
{ | ||
$this->keyName = $keyName; | ||
$this->optional = $optional; | ||
$this->valueType = $valueType; | ||
} | ||
|
||
|
||
public function __toString(): string | ||
{ | ||
if ($this->keyName !== null) { | ||
return sprintf( | ||
'%s%s: %s', | ||
(string) $this->keyName, | ||
$this->optional ? '?' : '', | ||
(string) $this->valueType | ||
); | ||
} | ||
|
||
return (string) $this->valueType; | ||
} | ||
|
||
} |
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,28 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\PhpDocParser\Ast\Type; | ||
|
||
use PHPStan\PhpDocParser\Ast\NodeAttributes; | ||
use function implode; | ||
|
||
class ObjectShapeNode implements TypeNode | ||
{ | ||
|
||
use NodeAttributes; | ||
|
||
/** @var ObjectShapeItemNode[] */ | ||
public $items; | ||
|
||
public function __construct(array $items) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
$items = $this->items; | ||
|
||
return 'object{' . implode(', ', $items) . '}'; | ||
} | ||
|
||
} |
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
Oops, something went wrong.