private function isBooleanValue(ASTValue $value = null) { return $value && $value->isValueAvailable() && ($value->getValue() === true || $value->getValue() === false); }
/** * This method will parse a static default value as it is used for a * parameter, property or constant declaration. * * @return \PDepend\Source\AST\ASTValue * @since 0.9.5 */ protected function parseStaticValue() { $defaultValue = new ASTValue(); $this->consumeComments(); // By default all parameters positive signed $signed = 1; $tokenType = $this->tokenizer->peek(); while ($tokenType !== Tokenizer::T_EOF) { switch ($tokenType) { case Tokens::T_COMMA: case Tokens::T_SEMICOLON: case Tokens::T_PARENTHESIS_CLOSE: if ($defaultValue->isValueAvailable() === true) { return $defaultValue; } throw new MissingValueException($this->tokenizer); case Tokens::T_NULL: $this->consumeToken(Tokens::T_NULL); $defaultValue->setValue(null); break; case Tokens::T_TRUE: $this->consumeToken(Tokens::T_TRUE); $defaultValue->setValue(true); break; case Tokens::T_FALSE: $this->consumeToken(Tokens::T_FALSE); $defaultValue->setValue(false); break; case Tokens::T_LNUMBER: $token = $this->consumeToken(Tokens::T_LNUMBER); $defaultValue->setValue($signed * (int) $token->image); break; case Tokens::T_DNUMBER: $token = $this->consumeToken(Tokens::T_DNUMBER); $defaultValue->setValue($signed * (double) $token->image); break; case Tokens::T_CONSTANT_ENCAPSED_STRING: $token = $this->consumeToken(Tokens::T_CONSTANT_ENCAPSED_STRING); $defaultValue->setValue(substr($token->image, 1, -1)); break; case Tokens::T_DOUBLE_COLON: $this->consumeToken(Tokens::T_DOUBLE_COLON); break; case Tokens::T_CLASS_FQN: $this->consumeToken(Tokens::T_CLASS_FQN); break; case Tokens::T_PLUS: $this->consumeToken(Tokens::T_PLUS); break; case Tokens::T_MINUS: $this->consumeToken(Tokens::T_MINUS); $signed *= -1; break; case Tokens::T_DOUBLE_QUOTE: $defaultValue->setValue($this->parseStringSequence($tokenType)); break; case Tokens::T_DIR: case Tokens::T_FILE: case Tokens::T_LINE: case Tokens::T_SELF: case Tokens::T_NS_C: case Tokens::T_FUNC_C: case Tokens::T_PARENT: case Tokens::T_STRING: case Tokens::T_STATIC: case Tokens::T_CLASS_C: case Tokens::T_METHOD_C: case Tokens::T_BACKSLASH: case Tokens::T_SQUARED_BRACKET_OPEN: case Tokens::T_SQUARED_BRACKET_CLOSE: // There is a default value but we don't handle it at the moment. $defaultValue->setValue(null); $this->consumeToken($tokenType); break; case Tokens::T_START_HEREDOC: $defaultValue->setValue($this->parseHeredoc()->getChild(0)->getImage()); break; default: return $this->parseStaticValueVersionSpecific($defaultValue); } $this->consumeComments(); $tokenType = $this->tokenizer->peek(); } // We should never reach this, so throw an exception throw new TokenStreamEndException($this->tokenizer); }
/** * testIsValueAvailableReturnsTrueForNullValue * * @return void */ public function testIsValueAvailableReturnsTrueForNullValue() { $value = new ASTValue(); $value->setValue(null); $this->assertTrue($value->isValueAvailable()); }