mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
feat: always use attributes instead of annotations
This commit is contained in:
31
src/Evaluators/Attributes.php
Normal file
31
src/Evaluators/Attributes.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Evaluators;
|
||||
|
||||
use Pest\Factories\Attribute;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Attributes
|
||||
{
|
||||
/**
|
||||
* Evaluates the given attributes and returns the code.
|
||||
*/
|
||||
public static function code(iterable $attributes): string
|
||||
{
|
||||
return implode(PHP_EOL, array_map(function (Attribute $attribute): string {
|
||||
$name = $attribute->name;
|
||||
|
||||
if ($attribute->arguments === []) {
|
||||
return " #[\\{$name}]";
|
||||
}
|
||||
|
||||
$arguments = array_map(fn (string $argument): string => var_export($argument, true), $attribute->arguments);
|
||||
|
||||
return sprintf(' #[\\%s(%s)]', $name, implode(', ', $arguments));
|
||||
}, $attributes));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user