/** * @covers \DCarbone\PHPClassBuilder\Utilities\NameUtils::isValidVariableName */ public function testReturnFalseWithInvalidVariableNames() { $this->assertFalse(NameUtils::isValidVariableName('91notvalid')); $this->assertFalse(NameUtils::isValidVariableName('nope nope')); $this->assertFalse(NameUtils::isValidVariableName('')); $this->assertFalse(NameUtils::isValidVariableName(true)); $this->assertFalse(NameUtils::isValidVariableName(null)); $this->assertFalse(NameUtils::isValidVariableName(12345)); }
/** * @param array $opts * @return string */ public function compile(array $opts = array()) { if (false === NameUtils::isValidVariableName($this->getName())) { throw $this->createMissingNameException('Variable name not defined at compile time'); } list($type, $includeComment, $leadingSpaces, $includeDefaultValue) = $this->parseCompileOpts($opts); switch ($type) { case self::COMPILETYPE_VARIABLE: return $this->_compileAsVariable($includeComment, $leadingSpaces, $includeDefaultValue); case self::COMPILETYPE_PROPERTY: return $this->_compileAsClassProperty($includeComment, $leadingSpaces, $includeDefaultValue); case self::COMPILETYPE_PARAMETER: return $this->_compileAsMethodParameter($includeDefaultValue); // TODO: Should not be reachable, but do something? // TODO: Should not be reachable, but do something? default: return ''; } }