1 | <?php |
||
7 | class PlaceholderContainer extends Collection |
||
8 | { |
||
9 | /** |
||
10 | * Hash used in placeholders. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $replacementHash; |
||
15 | |||
16 | /** |
||
17 | * Create a new placeholdercontainer. |
||
18 | * |
||
19 | * @param array $items |
||
20 | */ |
||
21 | 24 | public function __construct($items = []) |
|
27 | |||
28 | /** |
||
29 | * @param string $contents |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | 3 | public function restorePlaceholders($contents) |
|
34 | { |
||
35 | 3 | foreach ($this->all() as $placeholder => $original) { |
|
36 | $contents = str_replace($placeholder, $original, $contents); |
||
37 | } |
||
38 | |||
39 | 3 | return $contents; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Store a placeholder in the container. |
||
44 | * |
||
45 | * @param string $originalContent |
||
46 | * |
||
47 | * @return string $placeholder |
||
|
|||
48 | */ |
||
49 | 1 | public function addPlaceholder($originalContent) |
|
50 | { |
||
51 | 1 | if (($key = array_search($originalContent, $this->all()))) { |
|
52 | $placeholder = $key; |
||
53 | } else { |
||
54 | 1 | $placeholder = $this->createUniquePlaceholder(); |
|
55 | } |
||
56 | |||
57 | 1 | $originalContent = $this->removeNestedPlaceholders($originalContent); |
|
58 | 1 | $this->items[$placeholder] = $originalContent; |
|
59 | |||
60 | 1 | return $placeholder; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Create an unique placeholder. |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 1 | protected function createUniquePlaceholder() |
|
72 | |||
73 | /** |
||
74 | * Remove nested placeholders so no nested placholders remain in the original contents. |
||
75 | * |
||
76 | * @param string $originalContent |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | 1 | protected function removeNestedPlaceholders($originalContent) |
|
86 | |||
87 | 3 | public function getPlaceholderSize() |
|
93 | |||
94 | public function getOriginalSize() |
||
100 | } |
||
101 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.