/** * 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); } } }
/** * @param IReflectionClass $class * * @return string */ private function writeObjectType(IReflectionClass $class) { $return = 'class'; if (true === $class->isInterface()) { $return = 'interface'; } return $return; }