/** * Extract the list of returned values * * @param ReflectedMethod $method * @return $this */ private function extractReturns(ReflectedMethod $method, $n, TokenCollection $tokens) { $resolver = new TypeResolver(); // PHP 7 // we cannot use specific token. The ":" delimiter is a T_STRING token $following = $this->searcher->getUnder(array('{', ';'), $n, $tokens); if (preg_match('!:(.*)!', $following, $matches)) { $type = trim($matches[1]); if (empty($type)) { return $this; } $return = new ReflectedReturn($type, ReflectedReturn::VALUE_UNKNOW, ReflectedReturn::STRICT_TYPE_HINT); $method->pushReturn($return); return $this; } // array of available values based on code if (preg_match_all('!([\\s;]return\\s|^return\\s+)(.*?);!', $method->getContent(), $matches)) { foreach ($matches[2] as $m) { $value = trim($m, ";\t\n\r\v"); $return = new ReflectedReturn($resolver->resolve($m), $value, ReflectedReturn::ESTIMATED_TYPE_HINT); $method->pushReturn($return); } } return $this; }
/** * Search methods whose share attribute * * @param ReflectedClass $class * @param ReflectedMethod $method * @return array */ private function searchDirectLinkedMethodsByMember(ReflectedClass $class, ReflectedMethod $method) { $linked = array(); $members = array(); if (preg_match_all('!\\$this\\->([\\w\\(]+)!im', $method->getContent(), $matches)) { list(, $members) = $matches; } // search in other methods if they share attribute foreach ($class->getMethods() as $otherMethod) { $otherMembers = array(); if (preg_match_all('!\\$this\\->([\\w\\(]+)!im', $otherMethod->getContent(), $matches)) { list(, $otherMembers) = $matches; } $intersect = array_intersect($members, $otherMembers); // remove calls (members and calls are mixed : regex is too complex to be read) foreach ($intersect as $k => $name) { if (preg_match('!\\($!', $name)) { unset($intersect[$k]); } } if (sizeof($intersect, COUNT_NORMAL) > 0) { array_push($linked, $otherMethod->getName()); } } return $linked; }