jerowork /
graphql-attribute-schema
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Jerowork\GraphqlAttributeSchema\Node; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * @phpstan-type CustomScalarNodePayload array{ |
||
| 9 | * className: class-string, |
||
| 10 | * name: string, |
||
| 11 | * description: null|string, |
||
| 12 | * alias: null|class-string |
||
| 13 | * } |
||
| 14 | * |
||
| 15 | * @internal |
||
| 16 | */ |
||
| 17 | final readonly class ScalarNode implements Node, AliasedNode |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param class-string $className |
||
| 21 | * @param null|class-string $alias |
||
| 22 | */ |
||
| 23 | 11 | public function __construct( |
|
| 24 | public string $className, |
||
| 25 | public string $name, |
||
| 26 | public ?string $description, |
||
| 27 | public ?string $alias, |
||
| 28 | 11 | ) {} |
|
| 29 | |||
| 30 | 8 | public function getClassName(): string |
|
| 31 | { |
||
| 32 | 8 | return $this->className; |
|
| 33 | } |
||
| 34 | |||
| 35 | 6 | public function getAlias(): ?string |
|
| 36 | { |
||
| 37 | 6 | return $this->alias; |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return CustomScalarNodePayload |
||
| 42 | */ |
||
| 43 | 1 | public function toArray(): array |
|
| 44 | { |
||
| 45 | 1 | return [ |
|
| 46 | 1 | 'className' => $this->className, |
|
| 47 | 1 | 'name' => $this->name, |
|
| 48 | 1 | 'description' => $this->description, |
|
| 49 | 1 | 'alias' => $this->alias, |
|
| 50 | 1 | ]; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param CustomScalarNodePayload $payload |
||
| 55 | */ |
||
| 56 | 1 | public static function fromArray(array $payload): ScalarNode |
|
| 57 | { |
||
| 58 | 1 | return new self( |
|
| 59 | 1 | $payload['className'], |
|
| 60 | 1 | $payload['name'], |
|
| 61 | 1 | $payload['description'], |
|
| 62 | 1 | $payload['alias'], |
|
| 63 | 1 | ); |
|
| 64 | } |
||
| 65 | } |
||
| 66 |