Skip to content

Commit

Permalink
Add "StringLiteralNode::createFromValue()" method
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Jul 2, 2024
1 parent 882e9af commit 79054a7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Node/Literal/StringLiteralNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ final public function __construct(
parent::__construct($raw ?? $this->value);
}

public static function createFromValue(string $value): static
{
return new static(
value: $value,
raw: \sprintf('"%s"', \addcslashes($value, '"')),
);
}

public static function parse(string $value): static
{
assert(\strlen($value) >= 2, new \InvalidArgumentException('Could not parse non-quoted string'));
Expand Down

0 comments on commit 79054a7

Please sign in to comment.