/** * This method will check if a certain assertion mismatches the scope of this function. * * @param \TechDivision\PBC\Interfaces\AssertionInterface $assertion The assertion to check for a possible mismatch * within this function context * * @return boolean */ protected function conditionIsMismatch(AssertionInterface $assertion) { // If the minimal scope is above or below function scope we cannot determine if this is a mismatch in // function scope. if ($assertion->getMinScope() !== 'function') { return false; } // We will get all parameters and check if we can find any of it in the assertion string. // If not then we have a mismatch as the condition is only function scoped $assertionString = $assertion->getString(); $parameterIterator = $this->parameterDefinitions->getIterator(); foreach ($parameterIterator as $parameter) { if (strpos($assertionString, $parameter->name) !== false) { return false; } } // Still here, that does not sound good return true; }
/** * Will return a list of parameter definition objects extracted from a given token array * * @param array $tokens The token array * * @return \TechDivision\PBC\Entities\Lists\ParameterDefinitionList * * TODO Does this have to be this long? */ protected function getParameterDefinitionList(array $tokens) { // Check the tokens $parameterString = ''; $parameterDefinitionList = new ParameterDefinitionList(); for ($i = 0; $i < count($tokens); $i++) { // If we got the function definition, no scan everything from the first ( to the next ) if ($tokens[$i][0] === T_FUNCTION) { $bracketPassed = null; for ($j = $i; $j < count($tokens); $j++) { // If we got the function definition, no scan everything from the first ( to the closing ) if ($tokens[$j] === '(') { if ($bracketPassed === null) { $bracketPassed = 0; // We do not want to get this token as well. continue; } else { $bracketPassed++; } } // We got A closing bracket, decrease the counter if ($tokens[$j] === ')') { $bracketPassed--; } if ($bracketPassed >= 0 && $bracketPassed !== null) { // Collect what we get if (is_array($tokens[$j])) { $parameterString .= $tokens[$j][1]; } else { $parameterString .= $tokens[$j]; } } elseif ($bracketPassed !== null) { // If we got the closing bracket we can leave both loops break 2; } } } } // Now lets analyse what we got $parameterStrings = explode(',', $parameterString); foreach ($parameterStrings as $key => $param) { if ($this->getBracketCount($param, '(') > 0) { $param = $param . ', ' . $parameterStrings[$key + 1]; unset($parameterStrings[$key + 1]); } $param = trim($param); $paramPieces = explode('$', $param); // Get a new ParameterDefinition $parameterDefinition = new ParameterDefinition(); // we either get one or two pieces if (count($paramPieces) === 1) { continue; } elseif (count($paramPieces) === 2) { $parameterDefinition->type = trim($paramPieces[0]); // We might have an overload going on $nameArray = explode('=', $paramPieces[1]); $parameterDefinition->name = '$' . trim($nameArray[0]); // check if we got a default value for overloading if (isset($nameArray[1])) { $parameterDefinition->defaultValue = $nameArray[1]; } } // Add the definition to the list $parameterDefinitionList->add($parameterDefinition); } return $parameterDefinitionList; }