Total Complexity | 4 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | final class DynamicContent |
||
11 | { |
||
12 | private string $id; |
||
13 | private array $parameters; |
||
14 | |||
15 | /** |
||
16 | * @var callable |
||
17 | */ |
||
18 | private $contentGenerator; |
||
19 | |||
20 | /** |
||
21 | * @param string $id The unique identifier of the dynamic content. |
||
22 | * @param callable $contentGenerator PHP callable with the signature: `function (array $parameters = []): string;`. |
||
23 | * @param array $parameters The parameters (name-value pairs) that will be passed in the $contentGenerator context. |
||
24 | */ |
||
25 | 5 | public function __construct(string $id, callable $contentGenerator, array $parameters = []) |
|
30 | 5 | } |
|
31 | |||
32 | /** |
||
33 | * Returns the he unique identifier of the dynamic content. |
||
34 | * |
||
35 | * @return string The unique identifier of the dynamic content. |
||
36 | */ |
||
37 | 5 | public function id(): string |
|
38 | { |
||
39 | 5 | return $this->id; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Generates the dynamic content. |
||
44 | * |
||
45 | * @return string The generated dynamic content. |
||
46 | */ |
||
47 | 5 | public function content(): string |
|
48 | { |
||
49 | 5 | return ($this->contentGenerator)($this->parameters); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Returns the placeholder of the dynamic content. |
||
54 | * |
||
55 | * @return string The placeholder of the dynamic content. |
||
56 | */ |
||
57 | 5 | public function placeholder(): string |
|
60 | } |
||
61 | } |
||
62 |