/** * testMagicWakeupMethodInvokesSetSourceFileOnChildNodes * * @return void * @group pdepend * @group pdepend::code * @group unittest */ public function testMagicWakeupMethodInvokesSetSourceFileOnChildNodes() { $node = $this->getMock(PHP_Depend_Code_Class::CLAZZ, array('setSourceFile'), array(__CLASS__)); $node->expects($this->once())->method('setSourceFile')->with(self::isInstanceOf(PHP_Depend_Code_File::CLAZZ)); $file = new PHP_Depend_Code_File(__FILE__); $file->addChild($node); $file->__wakeup(); }
/** * Parses an optional statement or returns <b>null</b>. * * @return PHP_Depend_Code_ASTNode * @since 0.9.8 */ private function _parseOptionalStatement() { $tokenType = $this->tokenizer->peek(); switch ($tokenType) { case self::T_ECHO: return $this->_parseEchoStatement(); case self::T_SWITCH: return $this->_parseSwitchStatement(); case self::T_TRY: return $this->_parseTryStatement(); case self::T_THROW: return $this->_parseThrowStatement(); case self::T_IF: return $this->_parseIfStatement(); case self::T_FOR: return $this->_parseForStatement(); case self::T_FOREACH: return $this->_parseForeachStatement(); case self::T_DO: return $this->_parseDoWhileStatement(); case self::T_WHILE: return $this->_parseWhileStatement(); case self::T_RETURN: return $this->_parseReturnStatement(); case self::T_BREAK: return $this->_parseBreakStatement(); case self::T_CONTINUE: return $this->_parseContinueStatement(); case self::T_GOTO: return $this->_parseGotoStatement(); case self::T_GLOBAL: return $this->_parseGlobalStatement(); case self::T_UNSET: return $this->_parseUnsetStatement(); case self::T_STRING: if ($this->tokenizer->peekNext() === self::T_COLON) { return $this->_parseLabelStatement(); } break; case self::T_CONST: return $this->_parseConstantDefinition(); case self::T_FUNCTION: return $this->_parseFunctionOrClosureDeclaration(); case self::T_COMMENT: return $this->_parseCommentWithOptionalInlineClassOrInterfaceReference(); case self::T_DOC_COMMENT: return $this->builder->buildASTComment($this->consumeToken(self::T_DOC_COMMENT)->image); case self::T_CURLY_BRACE_OPEN: return $this->_parseRegularScope(); case self::T_DECLARE: return $this->_parseDeclareStatement(); case self::T_ELSE: case self::T_ENDIF: case self::T_ELSEIF: case self::T_ENDFOR: case self::T_ENDWHILE: case self::T_ENDSWITCH: case self::T_ENDDECLARE: case self::T_ENDFOREACH: case self::T_CURLY_BRACE_CLOSE: return null; case self::T_DECLARE: return $this->_parseDeclareStatement(); case self::T_CLOSE_TAG: if (($tokenType = $this->_parseNonePhpCode()) === self::T_EOF) { return null; } return $this->_parseOptionalStatement(); case self::T_TRAIT: $package = $this->_getNamespaceOrPackage(); $package->addType($trait = $this->_parseTraitDeclaration()); $this->builder->restoreTrait($trait); $this->_sourceFile->addChild($trait); return $trait; case self::T_INTERFACE: $package = $this->_getNamespaceOrPackage(); $package->addType($interface = $this->_parseInterfaceDeclaration()); $this->builder->restoreInterface($interface); $this->_sourceFile->addChild($interface); return $interface; case self::T_CLASS: case self::T_FINAL: case self::T_ABSTRACT: $package = $this->_getNamespaceOrPackage(); $package->addType($class = $this->_parseClassDeclaration()); $this->builder->restoreClass($class); $this->_sourceFile->addChild($class); return $class; } $this->_tokenStack->push(); $stmt = $this->builder->buildASTStatement(); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); } $this->_parseStatementTermination(); return $this->_setNodePositionsAndReturn($stmt); }
/** * This method parses a function declaration. * * @return PHP_Depend_Code_Function * @since 0.9.5 */ private function _parseFunctionDeclaration() { $this->consumeComments(); // Next token must be the function identifier $functionName = $this->parseFunctionName(); $function = $this->_builder->buildFunction($functionName); $function->setSourceFile($this->_sourceFile); $function->setUUID($this->_uuidBuilder->forFunction($function)); $this->_parseCallableDeclaration($function); // First check for an existing namespace if ($this->_namespaceName !== null) { $packageName = $this->_namespaceName; } else { if ($this->_packageName !== self::DEFAULT_PACKAGE) { $packageName = $this->_packageName; } else { $packageName = $this->_globalPackageName; } } $this->_builder->buildPackage($packageName)->addFunction($function); // Store function in source file, because we need them during the file's // __wakeup() phase for function declarations within another function or // method declaration. $this->_sourceFile->addChild($function); return $function; }