Пример #1
0
 /**
  * Attach method
  * This method consolidated dependencies
  *
  * @param ReflectedMethod $method
  * @return $this
  */
 public function pushMethod(ReflectedMethod $method)
 {
     $this->methods[$method->getName()] = $method;
     return $this;
 }
Пример #2
0
 /**
  * Extracts usage of method
  *
  * @param ReflectedMethod $method
  * @return $this
  */
 private function extractUsage(ReflectedMethod $method)
 {
     $tokens = $method->getTokens();
     $codes = $values = array();
     foreach ($tokens as $token) {
         if (in_array($token->getType(), array(T_WHITESPACE, T_BOOL_CAST, T_INT_CAST, T_STRING_CAST, T_DOUBLE_CAST, T_OBJECT_CAST))) {
             continue;
         }
         array_push($codes, $token->getType());
         array_push($values, $token->getValue());
     }
     switch (true) {
         case preg_match('!^(get)|(is)|(has).*!', $method->getName()) && $codes == array(T_RETURN, T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING):
             $method->setUsage(MethodUsage::USAGE_GETTER);
             break;
             // basic setter
         // basic setter
         case preg_match('!^set.*!', $method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING, T_VARIABLE, T_STRING) && $values[3] == '=':
             // fluent setter
         // fluent setter
         case preg_match('!^set.*!', $method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING, T_VARIABLE, T_STRING, T_RETURN, T_VARIABLE, T_STRING) && $values[3] == '=' && $values[7] == '$this':
             $method->setUsage(MethodUsage::USAGE_SETTER);
             break;
         default:
             $method->setUsage(MethodUsage::USAGE_UNKNWON);
     }
     return $this;
 }
Пример #3
0
 /**
  * Extract the list of returned values
  *
  * @param ReflectedMethod $method
  * @param string $content
  * @return $this
  */
 private function extractReturns(ReflectedMethod $method, $content)
 {
     if (preg_match_all('!([\\s;]return\\s|^return\\s)!', $content, $matches)) {
         foreach ($matches[1] as $m) {
             $method->pushReturn($m);
         }
     }
     return $this;
 }
Пример #4
0
 /**
  * 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;
 }