public function getDependentServices(Tokenize $tokenize) { /** 0000163(00027) - T_VARIABLE: '$container' 0000164(00027) - T_OBJECT_OPERATOR: '->' 0000165(00027) - T_STRING: 'get' 0000166(-----) - CHARACTER: '(' 0000167(00027) - T_CONSTANT_ENCAPSED_STRING: ''annotation_reader'' 0000168(-----) - CHARACTER: ')' **/ $i = 0; $containerGets = array(); while ($i = $tokenize->findExactOffsetAfter($i, T_VARIABLE, '$container')) { if (preg_match('/(\\$[\\w]+)\\s+=\\s+\\$container->get\\(/', $tokenize->getLineAt($i), $match)) { $i = $tokenize->findExactOffsetAfter($i, T_STRING, 'get'); $i = $tokenize->findAfter($i, T_CONSTANT_ENCAPSED_STRING); $containerGets[$tokenize->extractStringAt($i)] = $match[1]; } } $methodsToMock = array(); foreach ($containerGets as $serviceId => $instance) { $methods = array(); $i = 0; while ($i = $tokenize->findExactOffsetAfter($i, T_VARIABLE, $instance)) { //$tokenize->dumpAround($i, 5); if (T_WHITESPACE == $tokenize->getTokenTypeAt($i + 1)) { continue; } $i = $tokenize->findAfter($i, T_STRING); $methods[] = $tokenize->getStringAt($i); } $methodsToMock[$serviceId] = $methods; } return $methodsToMock; }
private function tokenizeArguments(Tokenize $tokenize) { $dependencies = array(); $i = 0; while ($i = $tokenize->findAfter($i, T_FUNCTION)) { $buffer = $tokenize->getLineAt($i); ++$i; $matches = array(); preg_match_all('/([a-zA-Z0-9\\\\]+)\\s+\\$\\w+/s', $buffer, $matches); if (!empty($matches)) { foreach ($matches[1] as $typeHint) { if ('array' == strtolower($typeHint)) { continue; } $dependencies[] = $typeHint; } } } return $dependencies; }