Ejemplo n.º 1
0
 /**
  * @param \TokenReflection\IReflectionMethod $method
  * @return string
  */
 private function writeParameters(IReflectionMethod $method)
 {
     $parameters = array();
     foreach ($method->getParameters() as $parameter) {
         /** @var $parameter \TokenReflection\IReflectionParameter */
         $parameters[] = $this->writeParameter($method, $parameter);
     }
     return '(' . implode(', ', $parameters) . ')';
 }
Ejemplo n.º 2
0
 /**
  * Gets an array of simplified information about the parameters of this
  * method
  *
  * @return array
  */
 protected function getParameterInfo()
 {
     $params = array();
     $parameters = $this->reflection->getParameters();
     /** @var ReflectionParameter $parameter */
     foreach ($parameters as $parameter) {
         $params[$parameter->getName()] = array('name' => $parameter->getName(), 'hint_type' => $parameter->getOriginalTypeHint(), 'type' => $parameter->getOriginalTypeHint(), 'comment' => null);
         if ($parameter->isDefaultValueAvailable()) {
             try {
                 $params[$parameter->getName()]['default'] = trim($parameter->getDefaultValueDefinition());
             } catch (RuntimeException $e) {
                 // Just don't provide a default
             }
         }
     }
     $annotations = array_filter($this->getParser()->getAnnotations(), function ($v) {
         $e = explode(' ', $v);
         return isset($e[0]) && $e[0] == '@param';
     });
     foreach ($annotations as $parameter) {
         $parts = explode(' ', $parameter);
         if (count($parts) < 3) {
             continue;
         }
         $type = trim($parts[1]);
         $name = trim(str_replace('$', '', $parts[2]));
         $comment = trim(implode(' ', array_slice($parts, 3)));
         if (isset($params[$name])) {
             if ($params[$name]['type'] == null && $type) {
                 $params[$name]['type'] = $type;
             }
             if ($comment) {
                 $params[$name]['comment'] = $comment;
             }
         }
     }
     return $params;
 }
Ejemplo n.º 3
0
 /**
  * Will test if the typehint of a parameter has been changed in a restrictive way and if a parameter has been added
  *
  * @param \TokenReflection\IReflection       $structureReflection The current structure reflection to inspect
  * @param \TokenReflection\IReflectionMethod $currentMethod       The current method reflection to inspect
  * @param \TokenReflection\IReflectionMethod $formerMethod        The former method reflection to compare to
  *
  * @return boolean
  */
 protected function didParametersChangeType(IReflection $structureReflection, IReflectionMethod $currentMethod, IReflectionMethod $formerMethod)
 {
     $formerParameters = $formerMethod->getParameters();
     $currentParameters = $currentMethod->getParameters();
     $parameterCount = count($currentParameters);
     for ($i = 0; $i < $parameterCount; $i++) {
         // if both methods have the parameter we compare types, otherwise we check for optionality
         if (isset($formerParameters[$i])) {
             // the parameter has been here before, but are the types consisten?
             if ($formerParameters[$i]->getOriginalTypeHint() !== $currentParameters[$i]->getOriginalTypeHint()) {
                 $this->result->addReason(new Reason($structureReflection->getName(), $currentMethod->getName(), Reason::TYPEHINT_RESTRICTED, $this->mapper));
             }
         } else {
             // the parameter has not been here before, is it optional?
             if (!$currentParameters[$i]->isDefaultValueAvailable()) {
                 $this->result->addReason(new Reason($structureReflection->getName(), $currentMethod->getName(), Reason::PARAMETER_ADDED, $this->mapper));
             }
         }
     }
 }