/** * Returns an exception description detail. * * @return string */ public function getDetail() { if (0 === $this->getStream()->count()) { return parent::getDetail() . 'The token stream was empty.'; } elseif (empty($this->token)) { return parent::getDetail() . 'The token stream was read out of its bounds.'; } else { return parent::getDetail() . sprintf("\nThe cause of the exception was the %s token (line %s) in following part of %s source code:\n\n%s", $this->tokenName, $this->token[2], $this->sender && $this->sender->getName() ? $this->sender->getPrettyName() : 'the', $this->getSourcePart(true)); } }
/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if (!$parent instanceof ReflectionClass) { throw new Exception\ParseException($this, $tokenStream, 'The parent object has to be an instance of TokenReflection\\ReflectionClass.', Exception\ParseException::INVALID_PARENT); } $this->declaringClassName = $parent->getName(); if ($parent->isTrait()) { $this->declaringTraitName = $parent->getName(); } return parent::processParent($parent, $tokenStream); }
/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if (!$parent instanceof ReflectionFunctionBase) { throw new Exception\ParseException($this, $tokenStream, 'The parent object has to be an instance of TokenReflection\\ReflectionFunctionBase.', Exception\ParseException::INVALID_PARENT); } // Declaring function name $this->declaringFunctionName = $parent->getName(); // Position $this->position = count($parent->getParameters()); // Declaring class name if ($parent instanceof ReflectionMethod) { $this->declaringClassName = $parent->getDeclaringClassName(); } return parent::processParent($parent, $tokenStream); }
/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if ($parent instanceof ReflectionFileNamespace) { $this->namespaceName = $parent->getName(); $this->aliases = $parent->getNamespaceAliases(); } elseif ($parent instanceof ReflectionClass) { $this->declaringClassName = $parent->getName(); } else { throw new Exception\ParseException($this, $tokenStream, sprintf('Invalid parent reflection provided: "%s".', get_class($parent)), Exception\ParseException::INVALID_PARENT); } return parent::processParent($parent, $tokenStream); }
/** * Processes the parent reflection object. * * @param \TokenReflection\IReflection $parent Parent reflection object * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream * * @return \TokenReflection\ReflectionElement * @throws \TokenReflection\Exception\ParseException If an invalid parent reflection object was provided. */ protected function processParent(IReflection $parent, Stream $tokenStream) { if (!$parent instanceof ReflectionFileNamespace) { throw new Exception\ParseException($this, $tokenStream, 'The parent object has to be an instance of TokenReflection\\ReflectionFileNamespace.', Exception\ParseException::INVALID_PARENT); } $this->namespaceName = $parent->getName(); $this->aliases = $parent->getNamespaceAliases(); return parent::processParent($parent, $tokenStream); }
/** * Will store any given structure reflection * * @param IReflection $structureReflection Reflection instance to store in our cache * * @return null */ public function store(IReflection $structureReflection) { $filePath = $this->calculateCachePath($structureReflection->getName()); file_put_contents($filePath, serialize($structureReflection)); }
/** * 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)); } } } }
/** * Reduces a reference in a given context * * @access public * @param string $reference The reference to reduce * @param IReflection $context The reflection context for reduction * @return string The reduced reference */ public function reduce($reference, IReflection $context) { $member = NULL; if (strpos($reference, '::') !== FALSE) { list($reference, $member) = explode('::', $reference); } $reduction = $reference; if (!self::isStandardType($reference)) { $parts = explode('\\', $reduction); $reduction = '\\' . $reduction; $aliases = array_merge(['' => $context->getName()], $context->getNamespaceAliases()); foreach ($aliases as $alias => $namespace) { $namespace_parts = explode('\\', $namespace); if (count($parts) < count($namespace_parts)) { continue; } if ($namespace_parts == array_slice($parts, 0, count($namespace_parts))) { $reduction = implode('\\', !$alias ? array_slice($parts, count($namespace_parts)) : array_merge([$alias], array_slice($parts, count($namespace_parts)))); break; } } } return $member ? implode('::', [$reduction, $member]) : $reduction; }