@@ 60-100 (lines=41) @@ | ||
57 | * |
|
58 | * @return string |
|
59 | */ |
|
60 | public function filterChunk($chunk, FunctionDefinitionList $functionDefinitions) |
|
61 | { |
|
62 | // Get the tokens |
|
63 | $tokens = token_get_all($chunk); |
|
64 | ||
65 | // Go through the tokens and check what we found |
|
66 | $tokensCount = count($tokens); |
|
67 | for ($i = 0; $i < $tokensCount; $i++) { |
|
68 | // Did we find a function? If so check if we know that thing and insert the code of its preconditions. |
|
69 | if (is_array($tokens[$i]) && $tokens[$i][0] === T_FUNCTION && is_array($tokens[$i + 2])) { |
|
70 | // Get the name of the function |
|
71 | $functionName = $tokens[$i + 2][1]; |
|
72 | ||
73 | // Check if we got the function in our list, if not continue |
|
74 | $functionDefinition = $functionDefinitions->get($functionName); |
|
75 | ||
76 | if (!$functionDefinition instanceof FunctionDefinition) { |
|
77 | continue; |
|
78 | ||
79 | } else { |
|
80 | // Get the code for the assertions |
|
81 | $code = $this->generateCode($functionDefinition->getAllPreconditions(), $functionName); |
|
82 | ||
83 | // Insert the code |
|
84 | $chunk = str_replace( |
|
85 | Placeholders::PRECONDITION . $functionDefinition->getName() . |
|
86 | Placeholders::PLACEHOLDER_CLOSE, |
|
87 | $code, |
|
88 | $chunk |
|
89 | ); |
|
90 | ||
91 | // "Destroy" code and function definition |
|
92 | $code = null; |
|
93 | $functionDefinition = null; |
|
94 | } |
|
95 | } |
|
96 | } |
|
97 | ||
98 | // Tell them how much we already processed, and stuff it back into the output |
|
99 | return $chunk; |
|
100 | } |
|
101 | ||
102 | /** |
|
103 | * Will generate the code needed to enforce made precondition assertions |
@@ 60-99 (lines=40) @@ | ||
57 | * |
|
58 | * @return string |
|
59 | */ |
|
60 | public function filterChunk($chunk, FunctionDefinitionList $functionDefinitions) |
|
61 | { |
|
62 | // Get the tokens |
|
63 | $tokens = token_get_all($chunk); |
|
64 | ||
65 | // Go through the tokens and check what we found |
|
66 | $tokensCount = count($tokens); |
|
67 | for ($i = 0; $i < $tokensCount; $i++) { |
|
68 | // Did we find a function? If so check if we know that thing and insert the code of its preconditions |
|
69 | if (is_array($tokens[$i]) && $tokens[$i][0] === T_FUNCTION && is_array($tokens[$i + 2])) { |
|
70 | // Get the name of the function |
|
71 | $functionName = $tokens[$i + 2][1]; |
|
72 | ||
73 | // Check if we got the function in our list, if not continue |
|
74 | $functionDefinition = $functionDefinitions->get($functionName); |
|
75 | ||
76 | if (!$functionDefinition instanceof FunctionDefinition) { |
|
77 | continue; |
|
78 | ||
79 | } else { |
|
80 | // Get the code for the needed call |
|
81 | $code = $this->generateCode($functionDefinition); |
|
82 | ||
83 | // Insert the code |
|
84 | $chunk = str_replace( |
|
85 | Placeholders::AROUND_JOINPOINT . $functionDefinition->getName() . |
|
86 | Placeholders::PLACEHOLDER_CLOSE, |
|
87 | $code, |
|
88 | $chunk |
|
89 | ); |
|
90 | ||
91 | // "Destroy" code and function definition |
|
92 | $code = null; |
|
93 | $functionDefinition = null; |
|
94 | } |
|
95 | } |
|
96 | } |
|
97 | ||
98 | return $chunk; |
|
99 | } |
|
100 | ||
101 | /** |
|
102 | * Will generate the code to call the original method logic |