/**
  * @param \TokenReflection\IReflectionClass $class
  * @return string
  */
 public function writeMethods(IReflectionClass $class)
 {
     $written = '';
     $docComment = (string) $class->getDocComment();
     $matches = array();
     preg_match_all('/\\*\\h+@method\\h+([^\\h]+)\\h+([^(\\s]+)(?:\\h*\\(\\h*([^)]*)\\h*\\))?\\s/', (string) $docComment, $matches);
     foreach ($matches[2] as $i => $name) {
         $written .= $this->writeMethod($name, $matches[3][$i], $matches[1][$i]);
     }
     return $written;
 }
Ejemplo n.º 2
0
 /**
  * @param \TokenReflection\IReflectionClass $declaringClass The class using the namespace aliases
  * @param string $aliasedClassName The class name used in the declaring class
  * @return string
  */
 protected function expandNamespaceAlias(IReflectionClass $declaringClass, $aliasedClassName)
 {
     $aliasedClassName = trim($aliasedClassName);
     foreach ($declaringClass->getNamespaceAliases() as $namespaceAlias) {
         if (1 === preg_match('/\\\\' . preg_quote($aliasedClassName) . '$/', $namespaceAlias)) {
             $aliasedClassName = $namespaceAlias;
             break;
         }
     }
     return $aliasedClassName;
 }
Ejemplo n.º 3
0
 /**
  * @return int
  */
 public function getEndLine()
 {
     return $this->reflection->getEndLine();
 }
Ejemplo n.º 4
0
 /**
  * Will start the inspection for a specific interface
  *
  * @param \TokenReflection\IReflectionClass $reflectionInterface The current reflection to inspect
  * @param \TokenReflection\IReflectionClass $formerReflection    The former inspection to compare to
  *
  * @return null
  */
 protected function inspectInterface(IReflectionClass $reflectionInterface, IReflectionClass $formerReflection)
 {
     // double check if the reflections are interfaces as we cannot make sure by type
     if (!$reflectionInterface->isInterface() || !$formerReflection->isInterface()) {
         throw new \Exception(sprintf('Both %s and %s must be interfaces, common classes found', $reflectionInterface->getName(), $formerReflection->getName()));
     }
     // set the mapper instance we need
     $this->mapper = new InterfaceMapper();
     // does the current class have less public methods
     $this->didRemoveMethod($reflectionInterface, $formerReflection);
     // iterate all structure methods and check them
     foreach ($reflectionInterface->getMethods() as $currentMethod) {
         // get the structure- and method name for faster access
         $methodName = $currentMethod->getName();
         // check if the method did even exist before
         $formerMethod = null;
         if ($this->didMethodExistBefore($formerReflection, $methodName)) {
             $formerMethod = $formerReflection->getMethod($methodName);
         } else {
             // if there was no former method this is a reason for a version bump
             $this->result->addReason(new Reason($currentMethod, $formerReflection, Reason::METHOD_ADDED, $this->mapper));
             continue;
         }
         // only proceed for public methods (but check if it was public before)
         if ($currentMethod->isPrivate() || $currentMethod->isProtected()) {
             $this->didRestrictVisibility($reflectionInterface, $currentMethod, $formerMethod);
             continue;
         }
         // check if the method has been made public recently
         if ($this->didOpenVisibility($reflectionInterface, $currentMethod, $formerMethod)) {
             continue;
         }
         // are there less parameters now than before?
         if ($this->didRemoveParameter($reflectionInterface, $currentMethod, $formerMethod)) {
             continue;
         } else {
             // we have to check if the new parameters are optional or the parameters changed types
             $this->didParametersChangeType($reflectionInterface, $currentMethod, $formerMethod);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param IReflectionClass $class
  *
  * @return string
  */
 private function writeObjectType(IReflectionClass $class)
 {
     $return = 'class';
     if (true === $class->isInterface()) {
         $return = 'interface';
     }
     return $return;
 }