generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 125
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
a967b2b
commit b498847
Showing
6 changed files
with
84 additions
and
4 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,29 @@ | ||
<?php | ||
|
||
namespace Dedoc\Scramble\Infer\Handler; | ||
|
||
use Dedoc\Scramble\Infer\Scope\Scope; | ||
use Dedoc\Scramble\Support\Type\ConcatenatedStringType; | ||
use Dedoc\Scramble\Support\Type\SideEffects\SelfTemplateDefinition; | ||
use Dedoc\Scramble\Support\Type\TemplateType; | ||
use Dedoc\Scramble\Support\Type\TypeHelper; | ||
use PhpParser\Node; | ||
|
||
class ConcatHandler | ||
{ | ||
public function shouldHandle($node) | ||
{ | ||
return $node instanceof Node\Expr\BinaryOp\Concat; | ||
} | ||
|
||
public function leave(Node\Expr\BinaryOp\Concat $node, Scope $scope) | ||
{ | ||
$scope->setType( | ||
$node, | ||
new ConcatenatedStringType(TypeHelper::flattenStringConcatTypes([ | ||
$scope->getType($node->left), | ||
$scope->getType($node->right), | ||
])), | ||
); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Dedoc\Scramble\Support\Type; | ||
|
||
class ConcatenatedStringType extends StringType | ||
{ | ||
/** | ||
* @param Type[] $parts Types of parts being concatenated. | ||
*/ | ||
public function __construct(public array $parts) | ||
{ | ||
} | ||
|
||
public function nodes(): array | ||
{ | ||
return ['parts']; | ||
} | ||
|
||
public function isSame(Type $type) | ||
{ | ||
return $this === $type; | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return parent::toString().'('.implode(', ', array_map(fn ($p) => $p->toString(), $this->parts)).')'; | ||
} | ||
} |
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