@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | abstract class Mailcode_Variables_Collection |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var Mailcode_Variables_Variable[] |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var Mailcode_Variables_Variable[] |
|
| 25 | + */ |
|
| 26 | 26 | protected array $variables = array(); |
| 27 | 27 | |
| 28 | 28 | public function __construct() |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | return count($this->variables); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Checks whether the collection contains a variable with the specified name. |
|
| 57 | - * |
|
| 58 | - * @param string $fullName The variable name, with or without $ sign. |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 55 | + /** |
|
| 56 | + * Checks whether the collection contains a variable with the specified name. |
|
| 57 | + * |
|
| 58 | + * @param string $fullName The variable name, with or without $ sign. |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | 61 | public function hasVariableName(string $fullName) : bool |
| 62 | 62 | { |
| 63 | 63 | $fullName = $this->fixName($fullName); |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Retrieves a collection of all variable instances for |
|
| 78 | - * the specified name (there can be several with differing |
|
| 79 | - * matched texts because of spacing). |
|
| 80 | - * |
|
| 81 | - * @param string $fullName |
|
| 82 | - * @return Mailcode_Variables_Collection |
|
| 83 | - */ |
|
| 76 | + /** |
|
| 77 | + * Retrieves a collection of all variable instances for |
|
| 78 | + * the specified name (there can be several with differing |
|
| 79 | + * matched texts because of spacing). |
|
| 80 | + * |
|
| 81 | + * @param string $fullName |
|
| 82 | + * @return Mailcode_Variables_Collection |
|
| 83 | + */ |
|
| 84 | 84 | public function getByFullName(string $fullName) : Mailcode_Variables_Collection |
| 85 | 85 | { |
| 86 | 86 | $fullName = $this->fixName($fullName); |
@@ -98,23 +98,23 @@ discard block |
||
| 98 | 98 | return $collection; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Prepends the $ sign to a variable name if it does not have it. |
|
| 103 | - * |
|
| 104 | - * @param string $fullName |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 101 | + /** |
|
| 102 | + * Prepends the $ sign to a variable name if it does not have it. |
|
| 103 | + * |
|
| 104 | + * @param string $fullName |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | 107 | protected function fixName(string $fullName) : string |
| 108 | 108 | { |
| 109 | 109 | return dollarize($fullName); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Retrieves all variables, grouped by their hash - meaning |
|
| 114 | - * unique matched strings. |
|
| 115 | - * |
|
| 116 | - * @return Mailcode_Variables_Variable[] |
|
| 117 | - */ |
|
| 112 | + /** |
|
| 113 | + * Retrieves all variables, grouped by their hash - meaning |
|
| 114 | + * unique matched strings. |
|
| 115 | + * |
|
| 116 | + * @return Mailcode_Variables_Variable[] |
|
| 117 | + */ |
|
| 118 | 118 | public function getGroupedByHash() : array |
| 119 | 119 | { |
| 120 | 120 | $entries = array(); |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | return $this->sortVariables($entries); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Retrieves all variables, grouped by their name. |
|
| 132 | - * |
|
| 133 | - * @return Mailcode_Variables_Variable[] |
|
| 134 | - */ |
|
| 130 | + /** |
|
| 131 | + * Retrieves all variables, grouped by their name. |
|
| 132 | + * |
|
| 133 | + * @return Mailcode_Variables_Variable[] |
|
| 134 | + */ |
|
| 135 | 135 | public function getGroupedByName() : array |
| 136 | 136 | { |
| 137 | 137 | $entries = array(); |
@@ -163,19 +163,19 @@ discard block |
||
| 163 | 163 | return $this->sortVariables($entries); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Retrieves all variables, in the order they were addded. |
|
| 168 | - * @return Mailcode_Variables_Variable[] |
|
| 169 | - */ |
|
| 166 | + /** |
|
| 167 | + * Retrieves all variables, in the order they were addded. |
|
| 168 | + * @return Mailcode_Variables_Variable[] |
|
| 169 | + */ |
|
| 170 | 170 | public function getAll() |
| 171 | 171 | { |
| 172 | 172 | return $this->variables; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Retrieves the full names of the variables that are present in the collection. |
|
| 177 | - * @return string[] |
|
| 178 | - */ |
|
| 175 | + /** |
|
| 176 | + * Retrieves the full names of the variables that are present in the collection. |
|
| 177 | + * @return string[] |
|
| 178 | + */ |
|
| 179 | 179 | public function getNames() : array |
| 180 | 180 | { |
| 181 | 181 | $result = array(); |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | return $result; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Takes a list of variables and sorts them, throwing away |
|
| 198 | - * the source array's keys. |
|
| 199 | - * |
|
| 200 | - * @param Mailcode_Variables_Variable[] $entries |
|
| 201 | - * @return Mailcode_Variables_Variable[] |
|
| 202 | - */ |
|
| 196 | + /** |
|
| 197 | + * Takes a list of variables and sorts them, throwing away |
|
| 198 | + * the source array's keys. |
|
| 199 | + * |
|
| 200 | + * @param Mailcode_Variables_Variable[] $entries |
|
| 201 | + * @return Mailcode_Variables_Variable[] |
|
| 202 | + */ |
|
| 203 | 203 | protected function sortVariables(array $entries) |
| 204 | 204 | { |
| 205 | 205 | $result = array_values($entries); |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | return $result; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Merges the variables collection with the target collection |
|
| 217 | - * by inheriting all that collection's variables. |
|
| 218 | - * |
|
| 219 | - * @param Mailcode_Variables_Collection $collection |
|
| 220 | - * @return Mailcode_Variables_Collection |
|
| 221 | - */ |
|
| 215 | + /** |
|
| 216 | + * Merges the variables collection with the target collection |
|
| 217 | + * by inheriting all that collection's variables. |
|
| 218 | + * |
|
| 219 | + * @param Mailcode_Variables_Collection $collection |
|
| 220 | + * @return Mailcode_Variables_Collection |
|
| 221 | + */ |
|
| 222 | 222 | public function mergeWith(Mailcode_Variables_Collection $collection) : Mailcode_Variables_Collection |
| 223 | 223 | { |
| 224 | 224 | $variables = $collection->getGroupedByHash(); |
@@ -225,27 +225,27 @@ |
||
| 225 | 225 | * @return array<string,string> |
| 226 | 226 | * @throws Mailcode_Exception |
| 227 | 227 | */ |
| 228 | - private function parseVarName() : array |
|
| 229 | - { |
|
| 230 | - $tokens = explode('.', undollarize($this->variable->getFullName())); |
|
| 231 | - |
|
| 232 | - if(count($tokens) === 2) |
|
| 233 | - { |
|
| 234 | - return array( |
|
| 235 | - 'path' => $tokens[0], |
|
| 236 | - 'name' => $tokens[1] |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - throw new Mailcode_Exception( |
|
| 241 | - 'Invalid variable name for a list property.', |
|
| 242 | - sprintf( |
|
| 243 | - 'Exactly 2 parts are required, variable [%s] has [%s].', |
|
| 244 | - $this->variable->getFullName(), |
|
| 245 | - count($tokens) |
|
| 246 | - ), |
|
| 247 | - self::ERROR_INVALID_LIST_VARIABLE_NAME |
|
| 248 | - ); |
|
| 249 | - } |
|
| 228 | + private function parseVarName() : array |
|
| 229 | + { |
|
| 230 | + $tokens = explode('.', undollarize($this->variable->getFullName())); |
|
| 231 | + |
|
| 232 | + if(count($tokens) === 2) |
|
| 233 | + { |
|
| 234 | + return array( |
|
| 235 | + 'path' => $tokens[0], |
|
| 236 | + 'name' => $tokens[1] |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + throw new Mailcode_Exception( |
|
| 241 | + 'Invalid variable name for a list property.', |
|
| 242 | + sprintf( |
|
| 243 | + 'Exactly 2 parts are required, variable [%s] has [%s].', |
|
| 244 | + $this->variable->getFullName(), |
|
| 245 | + count($tokens) |
|
| 246 | + ), |
|
| 247 | + self::ERROR_INVALID_LIST_VARIABLE_NAME |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | 250 | } |
| 251 | 251 | |