-
-
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.
Add support for object and list shape types
- Loading branch information
Showing
12 changed files
with
263 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
||
use function implode; | ||
|
||
final class ListShape extends ArrayShape | ||
Check failure on line 9 in src/PseudoTypes/ListShape.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
Check failure on line 9 in src/PseudoTypes/ListShape.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
|
||
{ | ||
public function __toString(): string | ||
Check failure on line 11 in src/PseudoTypes/ListShape.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
|
||
{ | ||
return 'list{' . implode(', ', $this->getItems()) . '}'; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
||
final class ListShapeItem extends ArrayShapeItem | ||
{ | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
||
use phpDocumentor\Reflection\PseudoType; | ||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\Types\Object_; | ||
|
||
use function implode; | ||
|
||
final class ObjectShape implements PseudoType | ||
Check failure on line 13 in src/PseudoTypes/ObjectShape.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
|
||
{ | ||
/** @var ObjectShapeItem[] */ | ||
private $items; | ||
|
||
public function __construct(ObjectShapeItem ...$items) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @return ObjectShapeItem[] | ||
*/ | ||
public function getItems(): array | ||
{ | ||
return $this->items; | ||
} | ||
|
||
public function underlyingType(): Type | ||
{ | ||
return new Object_(); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return 'object{' . implode(', ', $this->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
||
final class ObjectShapeItem extends ShapeItem | ||
{ | ||
} |
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); | ||
|
||
namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\Types\Mixed_; | ||
|
||
use function sprintf; | ||
|
||
abstract class ShapeItem | ||
{ | ||
/** @var string|null */ | ||
private $key; | ||
/** @var Type */ | ||
private $value; | ||
/** @var bool */ | ||
private $optional; | ||
|
||
public function __construct(?string $key, ?Type $value, bool $optional) | ||
{ | ||
$this->key = $key; | ||
$this->value = $value ?? new Mixed_(); | ||
$this->optional = $optional; | ||
} | ||
|
||
public function getKey(): ?string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function getValue(): Type | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function isOptional(): bool | ||
{ | ||
return $this->optional; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
if ($this->key !== null) { | ||
return sprintf( | ||
'%s%s: %s', | ||
$this->key, | ||
$this->optional ? '?' : '', | ||
(string) $this->value | ||
); | ||
} | ||
|
||
return (string) $this->value; | ||
} | ||
} |
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.