Added KH 3.3.0

This commit is contained in:
Deon George
2013-03-19 14:39:17 +11:00
parent 715f7efe9b
commit 2e134ea609
1283 changed files with 145138 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
PHP_TokenStream 1.1
===================
This is the list of changes for the PHP_TokenStream 1.1 release series.
PHP_TokenStream 1.1.5
---------------------
* No changes.
PHP_TokenStream 1.1.4
---------------------
* No changes.
PHP_TokenStream 1.1.3
---------------------
* Added class for the `T_TRAIT_C` token that was added in PHP 5.4.
PHP_TokenStream 1.1.2
---------------------
* Added classes for the `T_CALLABLE` and `T_INSTEADOF` tokens that were added in PHP 5.4.
* Added support for namespaced functions.
PHP_TokenStream 1.1.1
---------------------
* Fixed issue #19: Notice in `PHP_Token_INTERFACE::hasInterfaces()`.
PHP_TokenStream 1.1.0
---------------------
* Moved `phptok` tool to separate package.

View File

@@ -0,0 +1,33 @@
PHP_TokenStream
Copyright (c) 2009-2012, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Sebastian Bergmann nor the names of his
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,717 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
/**
* A PHP token.
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/tree
* @since Class available since Release 1.0.0
*/
abstract class PHP_Token
{
/**
* @var string
*/
protected $text;
/**
* @var integer
*/
protected $line;
/**
* @var PHP_Token_Stream
*/
protected $tokenStream;
/**
* @var integer
*/
protected $id;
/**
* Constructor.
*
* @param string $text
* @param integer $line
* @param PHP_Token_Stream $tokenStream
* @param integer $id
*/
public function __construct($text, $line, PHP_Token_Stream $tokenStream, $id)
{
$this->text = $text;
$this->line = $line;
$this->tokenStream = $tokenStream;
$this->id = $id;
}
/**
* @return string
*/
public function __toString()
{
return $this->text;
}
/**
* @return integer
*/
public function getLine()
{
return $this->line;
}
}
abstract class PHP_TokenWithScope extends PHP_Token
{
protected $endTokenId;
/**
* Get the docblock for this token
*
* This method will fetch the docblock belonging to the current token. The
* docblock must be placed on the line directly above the token to be
* recognized.
*
* @return string|null Returns the docblock as a string if found
*/
public function getDocblock()
{
$tokens = $this->tokenStream->tokens();
$currentLineNumber = $tokens[$this->id]->getLine();
$prevLineNumber = $currentLineNumber - 1;
for ($i = $this->id - 1; $i; $i--) {
if (!isset($tokens[$i])) {
return;
}
if ($tokens[$i] instanceof PHP_Token_FUNCTION ||
$tokens[$i] instanceof PHP_Token_CLASS ||
$tokens[$i] instanceof PHP_Token_TRAIT) {
// Some other trait, class or function, no docblock can be
// used for the current token
break;
}
$line = $tokens[$i]->getLine();
if ($line == $currentLineNumber ||
($line == $prevLineNumber &&
$tokens[$i] instanceof PHP_Token_WHITESPACE)) {
continue;
}
if ($line < $currentLineNumber &&
!$tokens[$i] instanceof PHP_Token_DOC_COMMENT) {
break;
}
return (string)$tokens[$i];
}
}
public function getEndTokenId()
{
$block = 0;
$i = $this->id;
$tokens = $this->tokenStream->tokens();
while ($this->endTokenId === NULL && isset($tokens[$i])) {
if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY ||
$tokens[$i] instanceof PHP_Token_CURLY_OPEN) {
$block++;
}
else if ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) {
$block--;
if ($block === 0) {
$this->endTokenId = $i;
}
}
else if (($this instanceof PHP_Token_FUNCTION ||
$this instanceof PHP_Token_NAMESPACE) &&
$tokens[$i] instanceof PHP_Token_SEMICOLON) {
if ($block === 0) {
$this->endTokenId = $i;
}
}
$i++;
}
if ($this->endTokenId === NULL) {
$this->endTokenId = $this->id;
}
return $this->endTokenId;
}
public function getEndLine()
{
return $this->tokenStream[$this->getEndTokenId()]->getLine();
}
}
abstract class PHP_TokenWithScopeAndVisibility extends PHP_TokenWithScope {
public function getVisibility()
{
$tokens = $this->tokenStream->tokens();
for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) {
if (isset($tokens[$i]) &&
($tokens[$i] instanceof PHP_Token_PRIVATE ||
$tokens[$i] instanceof PHP_Token_PROTECTED ||
$tokens[$i] instanceof PHP_Token_PUBLIC)) {
return strtolower(
str_replace('PHP_Token_', '', get_class($tokens[$i]))
);
}
if (isset($tokens[$i]) &&
!($tokens[$i] instanceof PHP_Token_STATIC ||
$tokens[$i] instanceof PHP_Token_FINAL ||
$tokens[$i] instanceof PHP_Token_ABSTRACT)) {
// no keywords; stop visibility search
break;
}
}
}
public function getKeywords()
{
$keywords = array();
$tokens = $this->tokenStream->tokens();
for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) {
if (isset($tokens[$i]) &&
($tokens[$i] instanceof PHP_Token_PRIVATE ||
$tokens[$i] instanceof PHP_Token_PROTECTED ||
$tokens[$i] instanceof PHP_Token_PUBLIC)) {
continue;
}
if (isset($tokens[$i]) &&
($tokens[$i] instanceof PHP_Token_STATIC ||
$tokens[$i] instanceof PHP_Token_FINAL ||
$tokens[$i] instanceof PHP_Token_ABSTRACT)) {
$keywords[] = strtolower(
str_replace('PHP_Token_', '', get_class($tokens[$i]))
);
}
}
return implode(',', $keywords);
}
}
abstract class PHP_Token_Includes extends PHP_Token
{
protected $name;
protected $type;
public function getName()
{
if ($this->name !== NULL) {
return $this->name;
}
$tokens = $this->tokenStream->tokens();
if ($tokens[$this->id+2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) {
$this->name = trim($tokens[$this->id+2], "'\"");
$this->type = strtolower(
str_replace('PHP_Token_', '', get_class($tokens[$this->id]))
);
}
return $this->name;
}
public function getType()
{
$this->getName();
return $this->type;
}
}
class PHP_Token_REQUIRE_ONCE extends PHP_Token_Includes {}
class PHP_Token_REQUIRE extends PHP_Token_Includes {}
class PHP_Token_EVAL extends PHP_Token {}
class PHP_Token_INCLUDE_ONCE extends PHP_Token_Includes {}
class PHP_Token_INCLUDE extends PHP_Token_Includes {}
class PHP_Token_LOGICAL_OR extends PHP_Token {}
class PHP_Token_LOGICAL_XOR extends PHP_Token {}
class PHP_Token_LOGICAL_AND extends PHP_Token {}
class PHP_Token_PRINT extends PHP_Token {}
class PHP_Token_SR_EQUAL extends PHP_Token {}
class PHP_Token_SL_EQUAL extends PHP_Token {}
class PHP_Token_XOR_EQUAL extends PHP_Token {}
class PHP_Token_OR_EQUAL extends PHP_Token {}
class PHP_Token_AND_EQUAL extends PHP_Token {}
class PHP_Token_MOD_EQUAL extends PHP_Token {}
class PHP_Token_CONCAT_EQUAL extends PHP_Token {}
class PHP_Token_DIV_EQUAL extends PHP_Token {}
class PHP_Token_MUL_EQUAL extends PHP_Token {}
class PHP_Token_MINUS_EQUAL extends PHP_Token {}
class PHP_Token_PLUS_EQUAL extends PHP_Token {}
class PHP_Token_BOOLEAN_OR extends PHP_Token {}
class PHP_Token_BOOLEAN_AND extends PHP_Token {}
class PHP_Token_IS_NOT_IDENTICAL extends PHP_Token {}
class PHP_Token_IS_IDENTICAL extends PHP_Token {}
class PHP_Token_IS_NOT_EQUAL extends PHP_Token {}
class PHP_Token_IS_EQUAL extends PHP_Token {}
class PHP_Token_IS_GREATER_OR_EQUAL extends PHP_Token {}
class PHP_Token_IS_SMALLER_OR_EQUAL extends PHP_Token {}
class PHP_Token_SR extends PHP_Token {}
class PHP_Token_SL extends PHP_Token {}
class PHP_Token_INSTANCEOF extends PHP_Token {}
class PHP_Token_UNSET_CAST extends PHP_Token {}
class PHP_Token_BOOL_CAST extends PHP_Token {}
class PHP_Token_OBJECT_CAST extends PHP_Token {}
class PHP_Token_ARRAY_CAST extends PHP_Token {}
class PHP_Token_STRING_CAST extends PHP_Token {}
class PHP_Token_DOUBLE_CAST extends PHP_Token {}
class PHP_Token_INT_CAST extends PHP_Token {}
class PHP_Token_DEC extends PHP_Token {}
class PHP_Token_INC extends PHP_Token {}
class PHP_Token_CLONE extends PHP_Token {}
class PHP_Token_NEW extends PHP_Token {}
class PHP_Token_EXIT extends PHP_Token {}
class PHP_Token_IF extends PHP_Token {}
class PHP_Token_ELSEIF extends PHP_Token {}
class PHP_Token_ELSE extends PHP_Token {}
class PHP_Token_ENDIF extends PHP_Token {}
class PHP_Token_LNUMBER extends PHP_Token {}
class PHP_Token_DNUMBER extends PHP_Token {}
class PHP_Token_STRING extends PHP_Token {}
class PHP_Token_STRING_VARNAME extends PHP_Token {}
class PHP_Token_VARIABLE extends PHP_Token {}
class PHP_Token_NUM_STRING extends PHP_Token {}
class PHP_Token_INLINE_HTML extends PHP_Token {}
class PHP_Token_CHARACTER extends PHP_Token {}
class PHP_Token_BAD_CHARACTER extends PHP_Token {}
class PHP_Token_ENCAPSED_AND_WHITESPACE extends PHP_Token {}
class PHP_Token_CONSTANT_ENCAPSED_STRING extends PHP_Token {}
class PHP_Token_ECHO extends PHP_Token {}
class PHP_Token_DO extends PHP_Token {}
class PHP_Token_WHILE extends PHP_Token {}
class PHP_Token_ENDWHILE extends PHP_Token {}
class PHP_Token_FOR extends PHP_Token {}
class PHP_Token_ENDFOR extends PHP_Token {}
class PHP_Token_FOREACH extends PHP_Token {}
class PHP_Token_ENDFOREACH extends PHP_Token {}
class PHP_Token_DECLARE extends PHP_Token {}
class PHP_Token_ENDDECLARE extends PHP_Token {}
class PHP_Token_AS extends PHP_Token {}
class PHP_Token_SWITCH extends PHP_Token {}
class PHP_Token_ENDSWITCH extends PHP_Token {}
class PHP_Token_CASE extends PHP_Token {}
class PHP_Token_DEFAULT extends PHP_Token {}
class PHP_Token_BREAK extends PHP_Token {}
class PHP_Token_CONTINUE extends PHP_Token {}
class PHP_Token_GOTO extends PHP_Token {}
class PHP_Token_CALLABLE extends PHP_Token {}
class PHP_Token_INSTEADOF extends PHP_Token {}
class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility
{
protected $arguments;
protected $ccn;
protected $name;
protected $signature;
public function getArguments()
{
if ($this->arguments !== NULL) {
return $this->arguments;
}
$this->arguments = array();
$i = $this->id + 3;
$tokens = $this->tokenStream->tokens();
$typeHint = NULL;
while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
if ($tokens[$i] instanceof PHP_Token_STRING) {
$typeHint = (string)$tokens[$i];
}
else if ($tokens[$i] instanceof PHP_Token_VARIABLE) {
$this->arguments[(string)$tokens[$i]] = $typeHint;
$typeHint = NULL;
}
$i++;
}
return $this->arguments;
}
public function getName()
{
if ($this->name !== NULL) {
return $this->name;
}
$tokens = $this->tokenStream->tokens();
if ($tokens[$this->id+2] instanceof PHP_Token_STRING) {
$this->name = (string)$tokens[$this->id+2];
}
else if ($tokens[$this->id+2] instanceof PHP_Token_AMPERSAND &&
$tokens[$this->id+3] instanceof PHP_Token_STRING) {
$this->name = (string)$tokens[$this->id+3];
}
else {
$this->name = 'anonymous function';
}
if ($this->name != 'anonymous function') {
for ($i = $this->id; $i; --$i) {
if ($tokens[$i] instanceof PHP_Token_NAMESPACE) {
$this->name = $tokens[$i]->getName() . '\\' . $this->name;
break;
}
if ($tokens[$i] instanceof PHP_Token_INTERFACE) {
break;
}
}
}
return $this->name;
}
public function getCCN()
{
if ($this->ccn !== NULL) {
return $this->ccn;
}
$this->ccn = 1;
$end = $this->getEndTokenId();
$tokens = $this->tokenStream->tokens();
for ($i = $this->id; $i <= $end; $i++) {
switch (get_class($tokens[$i])) {
case 'PHP_Token_IF':
case 'PHP_Token_ELSEIF':
case 'PHP_Token_FOR':
case 'PHP_Token_FOREACH':
case 'PHP_Token_WHILE':
case 'PHP_Token_CASE':
case 'PHP_Token_CATCH':
case 'PHP_Token_BOOLEAN_AND':
case 'PHP_Token_LOGICAL_AND':
case 'PHP_Token_BOOLEAN_OR':
case 'PHP_Token_LOGICAL_OR':
case 'PHP_Token_QUESTION_MARK': {
$this->ccn++;
}
break;
}
}
return $this->ccn;
}
public function getSignature()
{
if ($this->signature !== NULL) {
return $this->signature;
}
if ($this->getName() == 'anonymous function') {
$this->signature = 'anonymous function';
$i = $this->id + 1;
} else {
$this->signature = '';
$i = $this->id + 2;
}
$tokens = $this->tokenStream->tokens();
while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
$this->signature .= $tokens[$i++];
}
$this->signature .= ')';
return $this->signature;
}
}
class PHP_Token_CONST extends PHP_Token {}
class PHP_Token_RETURN extends PHP_Token {}
class PHP_Token_TRY extends PHP_Token {}
class PHP_Token_CATCH extends PHP_Token {}
class PHP_Token_THROW extends PHP_Token {}
class PHP_Token_USE extends PHP_Token {}
class PHP_Token_GLOBAL extends PHP_Token {}
class PHP_Token_PUBLIC extends PHP_Token {}
class PHP_Token_PROTECTED extends PHP_Token {}
class PHP_Token_PRIVATE extends PHP_Token {}
class PHP_Token_FINAL extends PHP_Token {}
class PHP_Token_ABSTRACT extends PHP_Token {}
class PHP_Token_STATIC extends PHP_Token {}
class PHP_Token_VAR extends PHP_Token {}
class PHP_Token_UNSET extends PHP_Token {}
class PHP_Token_ISSET extends PHP_Token {}
class PHP_Token_EMPTY extends PHP_Token {}
class PHP_Token_HALT_COMPILER extends PHP_Token {}
class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility
{
protected $interfaces;
public function getName()
{
return (string)$this->tokenStream[$this->id + 2];
}
public function hasParent()
{
return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS;
}
public function getPackage()
{
$className = $this->getName();
$docComment = $this->getDocblock();
$result = array(
'namespace' => '',
'fullPackage' => '',
'category' => '',
'package' => '',
'subpackage' => ''
);
for ($i = $this->id; $i; --$i) {
if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) {
$result['namespace'] = $this->tokenStream[$i]->getName();
break;
}
}
if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) {
$result['category'] = $matches[1];
}
if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) {
$result['package'] = $matches[1];
$result['fullPackage'] = $matches[1];
}
if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) {
$result['subpackage'] = $matches[1];
$result['fullPackage'] .= '.' . $matches[1];
}
if (empty($result['fullPackage'])) {
$result['fullPackage'] = $this->arrayToName(
explode('_', str_replace('\\', '_', $className)), '.'
);
}
return $result;
}
protected function arrayToName(array $parts, $join = '\\')
{
$result = '';
if (count($parts) > 1) {
array_pop($parts);
$result = join($join, $parts);
}
return $result;
}
public function getParent()
{
if (!$this->hasParent()) {
return FALSE;
}
$i = $this->id + 6;
$tokens = $this->tokenStream->tokens();
$className = (string)$tokens[$i];
while (isset($tokens[$i+1]) &&
!$tokens[$i+1] instanceof PHP_Token_WHITESPACE) {
$className .= (string)$tokens[++$i];
}
return $className;
}
public function hasInterfaces()
{
return (isset($this->tokenStream[$this->id + 4]) &&
$this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) ||
(isset($this->tokenStream[$this->id + 8]) &&
$this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS);
}
public function getInterfaces()
{
if ($this->interfaces !== NULL) {
return $this->interfaces;
}
if (!$this->hasInterfaces()) {
return ($this->interfaces = FALSE);
}
if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) {
$i = $this->id + 3;
} else {
$i = $this->id + 7;
}
$tokens = $this->tokenStream->tokens();
while (!$tokens[$i+1] instanceof PHP_Token_OPEN_CURLY) {
$i++;
if ($tokens[$i] instanceof PHP_Token_STRING) {
$this->interfaces[] = (string)$tokens[$i];
}
}
return $this->interfaces;
}
}
class PHP_Token_CLASS extends PHP_Token_INTERFACE {}
class PHP_Token_TRAIT extends PHP_Token_INTERFACE {}
class PHP_Token_EXTENDS extends PHP_Token {}
class PHP_Token_IMPLEMENTS extends PHP_Token {}
class PHP_Token_OBJECT_OPERATOR extends PHP_Token {}
class PHP_Token_DOUBLE_ARROW extends PHP_Token {}
class PHP_Token_LIST extends PHP_Token {}
class PHP_Token_ARRAY extends PHP_Token {}
class PHP_Token_CLASS_C extends PHP_Token {}
class PHP_Token_TRAIT_C extends PHP_Token {}
class PHP_Token_METHOD_C extends PHP_Token {}
class PHP_Token_FUNC_C extends PHP_Token {}
class PHP_Token_LINE extends PHP_Token {}
class PHP_Token_FILE extends PHP_Token {}
class PHP_Token_COMMENT extends PHP_Token {}
class PHP_Token_DOC_COMMENT extends PHP_Token {}
class PHP_Token_OPEN_TAG extends PHP_Token {}
class PHP_Token_OPEN_TAG_WITH_ECHO extends PHP_Token {}
class PHP_Token_CLOSE_TAG extends PHP_Token {}
class PHP_Token_WHITESPACE extends PHP_Token {}
class PHP_Token_START_HEREDOC extends PHP_Token {}
class PHP_Token_END_HEREDOC extends PHP_Token {}
class PHP_Token_DOLLAR_OPEN_CURLY_BRACES extends PHP_Token {}
class PHP_Token_CURLY_OPEN extends PHP_Token {}
class PHP_Token_PAAMAYIM_NEKUDOTAYIM extends PHP_Token {}
class PHP_Token_NAMESPACE extends PHP_TokenWithScope
{
public function getName()
{
$tokens = $this->tokenStream->tokens();
$namespace = (string)$tokens[$this->id+2];
for ($i = $this->id + 3; ; $i += 2) {
if (isset($tokens[$i]) &&
$tokens[$i] instanceof PHP_Token_NS_SEPARATOR) {
$namespace .= '\\' . $tokens[$i+1];
} else {
break;
}
}
return $namespace;
}
}
class PHP_Token_NS_C extends PHP_Token {}
class PHP_Token_DIR extends PHP_Token {}
class PHP_Token_NS_SEPARATOR extends PHP_Token {}
class PHP_Token_DOUBLE_COLON extends PHP_Token {}
class PHP_Token_OPEN_BRACKET extends PHP_Token {}
class PHP_Token_CLOSE_BRACKET extends PHP_Token {}
class PHP_Token_OPEN_SQUARE extends PHP_Token {}
class PHP_Token_CLOSE_SQUARE extends PHP_Token {}
class PHP_Token_OPEN_CURLY extends PHP_Token {}
class PHP_Token_CLOSE_CURLY extends PHP_Token {}
class PHP_Token_SEMICOLON extends PHP_Token {}
class PHP_Token_DOT extends PHP_Token {}
class PHP_Token_COMMA extends PHP_Token {}
class PHP_Token_EQUAL extends PHP_Token {}
class PHP_Token_LT extends PHP_Token {}
class PHP_Token_GT extends PHP_Token {}
class PHP_Token_PLUS extends PHP_Token {}
class PHP_Token_MINUS extends PHP_Token {}
class PHP_Token_MULT extends PHP_Token {}
class PHP_Token_DIV extends PHP_Token {}
class PHP_Token_QUESTION_MARK extends PHP_Token {}
class PHP_Token_EXCLAMATION_MARK extends PHP_Token {}
class PHP_Token_COLON extends PHP_Token {}
class PHP_Token_DOUBLE_QUOTES extends PHP_Token {}
class PHP_Token_AT extends PHP_Token {}
class PHP_Token_AMPERSAND extends PHP_Token {}
class PHP_Token_PERCENT extends PHP_Token {}
class PHP_Token_PIPE extends PHP_Token {}
class PHP_Token_DOLLAR extends PHP_Token {}
class PHP_Token_CARET extends PHP_Token {}
class PHP_Token_TILDE extends PHP_Token {}
class PHP_Token_BACKTICK extends PHP_Token {}

View File

@@ -0,0 +1,568 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
/**
* A stream of PHP tokens.
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/tree
* @since Class available since Release 1.0.0
*/
class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
{
/**
* @var array
*/
protected static $customTokens = array(
'(' => 'PHP_Token_OPEN_BRACKET',
')' => 'PHP_Token_CLOSE_BRACKET',
'[' => 'PHP_Token_OPEN_SQUARE',
']' => 'PHP_Token_CLOSE_SQUARE',
'{' => 'PHP_Token_OPEN_CURLY',
'}' => 'PHP_Token_CLOSE_CURLY',
';' => 'PHP_Token_SEMICOLON',
'.' => 'PHP_Token_DOT',
',' => 'PHP_Token_COMMA',
'=' => 'PHP_Token_EQUAL',
'<' => 'PHP_Token_LT',
'>' => 'PHP_Token_GT',
'+' => 'PHP_Token_PLUS',
'-' => 'PHP_Token_MINUS',
'*' => 'PHP_Token_MULT',
'/' => 'PHP_Token_DIV',
'?' => 'PHP_Token_QUESTION_MARK',
'!' => 'PHP_Token_EXCLAMATION_MARK',
':' => 'PHP_Token_COLON',
'"' => 'PHP_Token_DOUBLE_QUOTES',
'@' => 'PHP_Token_AT',
'&' => 'PHP_Token_AMPERSAND',
'%' => 'PHP_Token_PERCENT',
'|' => 'PHP_Token_PIPE',
'$' => 'PHP_Token_DOLLAR',
'^' => 'PHP_Token_CARET',
'~' => 'PHP_Token_TILDE',
'`' => 'PHP_Token_BACKTICK'
);
/**
* @var string
*/
protected $filename;
/**
* @var array
*/
protected $tokens = array();
/**
* @var integer
*/
protected $position = 0;
/**
* @var array
*/
protected $linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
/**
* @var array
*/
protected $classes;
/**
* @var array
*/
protected $functions;
/**
* @var array
*/
protected $includes;
/**
* @var array
*/
protected $interfaces;
/**
* @var array
*/
protected $traits;
/**
* Constructor.
*
* @param string $sourceCode
*/
public function __construct($sourceCode)
{
if (is_file($sourceCode)) {
$this->filename = $sourceCode;
$sourceCode = file_get_contents($sourceCode);
}
$this->scan($sourceCode);
}
/**
* Destructor.
*/
public function __destruct()
{
$this->tokens = array();
}
/**
* @return string
*/
public function __toString()
{
$buffer = '';
foreach ($this as $token) {
$buffer .= $token;
}
return $buffer;
}
/**
* @return string
* @since Method available since Release 1.1.0
*/
public function getFilename()
{
return $this->filename;
}
/**
* Scans the source for sequences of characters and converts them into a
* stream of tokens.
*
* @param string $sourceCode
*/
protected function scan($sourceCode)
{
$line = 1;
$tokens = token_get_all($sourceCode);
$numTokens = count($tokens);
for ($i = 0; $i < $numTokens; ++$i) {
$token = $tokens[$i];
unset($tokens[$i]);
if (is_array($token)) {
$text = $token[1];
$tokenClass = 'PHP_Token_' . substr(token_name($token[0]), 2);
} else {
$text = $token;
$tokenClass = self::$customTokens[$token];
}
$this->tokens[] = new $tokenClass($text, $line, $this, $i);
$lines = substr_count($text, "\n");
$line += $lines;
if ($tokenClass == 'PHP_Token_HALT_COMPILER') {
break;
}
else if ($tokenClass == 'PHP_Token_COMMENT' ||
$tokenClass == 'PHP_Token_DOC_COMMENT') {
$this->linesOfCode['cloc'] += $lines + 1;
}
}
$this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
$this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] -
$this->linesOfCode['cloc'];
}
/**
* @return integer
*/
public function count()
{
return count($this->tokens);
}
/**
* @return PHP_Token[]
*/
public function tokens()
{
return $this->tokens;
}
/**
* @return array
*/
public function getClasses()
{
if ($this->classes !== NULL) {
return $this->classes;
}
$this->parse();
return $this->classes;
}
/**
* @return array
*/
public function getFunctions()
{
if ($this->functions !== NULL) {
return $this->functions;
}
$this->parse();
return $this->functions;
}
/**
* @return array
*/
public function getInterfaces()
{
if ($this->interfaces !== NULL) {
return $this->interfaces;
}
$this->parse();
return $this->interfaces;
}
/**
* @return array
* @since Method available since Release 1.1.0
*/
public function getTraits()
{
if ($this->traits !== NULL) {
return $this->traits;
}
$this->parse();
return $this->traits;
}
/**
* Gets the names of all files that have been included
* using include(), include_once(), require() or require_once().
*
* Parameter $categorize set to TRUE causing this function to return a
* multi-dimensional array with categories in the keys of the first dimension
* and constants and their values in the second dimension.
*
* Parameter $category allow to filter following specific inclusion type
*
* @param bool $categorize OPTIONAL
* @param string $category OPTIONAL Either 'require_once', 'require',
* 'include_once', 'include'.
* @return array
* @since Method available since Release 1.1.0
*/
public function getIncludes($categorize = FALSE, $category = NULL)
{
if ($this->includes === NULL) {
$this->includes = array(
'require_once' => array(),
'require' => array(),
'include_once' => array(),
'include' => array()
);
foreach ($this->tokens as $token) {
switch (get_class($token)) {
case 'PHP_Token_REQUIRE_ONCE':
case 'PHP_Token_REQUIRE':
case 'PHP_Token_INCLUDE_ONCE':
case 'PHP_Token_INCLUDE': {
$this->includes[$token->getType()][] = $token->getName();
}
break;
}
}
}
if (isset($this->includes[$category])) {
$includes = $this->includes[$category];
}
else if ($categorize === FALSE) {
$includes = array_merge(
$this->includes['require_once'],
$this->includes['require'],
$this->includes['include_once'],
$this->includes['include']
);
} else {
$includes = $this->includes;
}
return $includes;
}
protected function parse()
{
$this->interfaces = array();
$this->classes = array();
$this->traits = array();
$this->functions = array();
$class = FALSE;
$classEndLine = FALSE;
$trait = FALSE;
$traitEndLine = FALSE;
$interface = FALSE;
$interfaceEndLine = FALSE;
foreach ($this->tokens as $token) {
switch (get_class($token)) {
case 'PHP_Token_HALT_COMPILER': {
return;
}
break;
case 'PHP_Token_INTERFACE': {
$interface = $token->getName();
$interfaceEndLine = $token->getEndLine();
$this->interfaces[$interface] = array(
'methods' => array(),
'parent' => $token->getParent(),
'keywords' => $token->getKeywords(),
'docblock' => $token->getDocblock(),
'startLine' => $token->getLine(),
'endLine' => $interfaceEndLine,
'package' => $token->getPackage(),
'file' => $this->filename
);
}
break;
case 'PHP_Token_CLASS':
case 'PHP_Token_TRAIT': {
$tmp = array(
'methods' => array(),
'parent' => $token->getParent(),
'interfaces'=> $token->getInterfaces(),
'keywords' => $token->getKeywords(),
'docblock' => $token->getDocblock(),
'startLine' => $token->getLine(),
'endLine' => $token->getEndLine(),
'package' => $token->getPackage(),
'file' => $this->filename
);
if ($token instanceof PHP_Token_CLASS) {
$class = $token->getName();
$classEndLine = $token->getEndLine();
$this->classes[$class] = $tmp;
} else {
$trait = $token->getName();
$traitEndLine = $token->getEndLine();
$this->traits[$trait] = $tmp;
}
}
break;
case 'PHP_Token_FUNCTION': {
$name = $token->getName();
$tmp = array(
'docblock' => $token->getDocblock(),
'keywords' => $token->getKeywords(),
'visibility'=> $token->getVisibility(),
'signature' => $token->getSignature(),
'startLine' => $token->getLine(),
'endLine' => $token->getEndLine(),
'ccn' => $token->getCCN(),
'file' => $this->filename
);
if ($class === FALSE &&
$trait === FALSE &&
$interface === FALSE) {
$this->functions[$name] = $tmp;
}
else if ($class !== FALSE) {
$this->classes[$class]['methods'][$name] = $tmp;
}
else if ($trait !== FALSE) {
$this->traits[$trait]['methods'][$name] = $tmp;
}
else {
$this->interfaces[$interface]['methods'][$name] = $tmp;
}
}
break;
case 'PHP_Token_CLOSE_CURLY': {
if ($classEndLine !== FALSE &&
$classEndLine == $token->getLine()) {
$class = FALSE;
$classEndLine = FALSE;
}
else if ($traitEndLine !== FALSE &&
$traitEndLine == $token->getLine()) {
$trait = FALSE;
$traitEndLine = FALSE;
}
else if ($interfaceEndLine !== FALSE &&
$interfaceEndLine == $token->getLine()) {
$interface = FALSE;
$interfaceEndLine = FALSE;
}
}
break;
}
}
}
/**
* @return array
*/
public function getLinesOfCode()
{
return $this->linesOfCode;
}
/**
*/
public function rewind()
{
$this->position = 0;
}
/**
* @return boolean
*/
public function valid()
{
return isset($this->tokens[$this->position]);
}
/**
* @return integer
*/
public function key()
{
return $this->position;
}
/**
* @return PHP_Token
*/
public function current()
{
return $this->tokens[$this->position];
}
/**
*/
public function next()
{
$this->position++;
}
/**
* @param mixed $offset
*/
public function offsetExists($offset)
{
return isset($this->tokens[$offset]);
}
/**
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->tokens[$offset];
}
/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
$this->tokens[$offset] = $value;
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
unset($this->tokens[$offset]);
}
/**
* Seek to an absolute position.
*
* @param integer $position
* @throws OutOfBoundsException
*/
public function seek($position)
{
$this->position = $position;
if (!$this->valid()) {
throw new OutOfBoundsException('Invalid seek position');
}
}
}

View File

@@ -0,0 +1,226 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://github.com/sebastianbergmann/php-token-stream/tree
* @since File available since Release 1.1.0
*/
spl_autoload_register(
function ($class)
{
static $classes = NULL;
static $path = NULL;;
if ($classes === NULL) {
$classes = array(
'php_token' => '/Token.php',
'php_token_abstract' => '/Token.php',
'php_token_ampersand' => '/Token.php',
'php_token_and_equal' => '/Token.php',
'php_token_array' => '/Token.php',
'php_token_array_cast' => '/Token.php',
'php_token_as' => '/Token.php',
'php_token_at' => '/Token.php',
'php_token_backtick' => '/Token.php',
'php_token_bad_character' => '/Token.php',
'php_token_bool_cast' => '/Token.php',
'php_token_boolean_and' => '/Token.php',
'php_token_boolean_or' => '/Token.php',
'php_token_break' => '/Token.php',
'php_token_callable' => '/Token.php',
'php_token_caret' => '/Token.php',
'php_token_case' => '/Token.php',
'php_token_catch' => '/Token.php',
'php_token_character' => '/Token.php',
'php_token_class' => '/Token.php',
'php_token_class_c' => '/Token.php',
'php_token_clone' => '/Token.php',
'php_token_close_bracket' => '/Token.php',
'php_token_close_curly' => '/Token.php',
'php_token_close_square' => '/Token.php',
'php_token_close_tag' => '/Token.php',
'php_token_colon' => '/Token.php',
'php_token_comma' => '/Token.php',
'php_token_comment' => '/Token.php',
'php_token_concat_equal' => '/Token.php',
'php_token_const' => '/Token.php',
'php_token_constant_encapsed_string' => '/Token.php',
'php_token_continue' => '/Token.php',
'php_token_curly_open' => '/Token.php',
'php_token_dec' => '/Token.php',
'php_token_declare' => '/Token.php',
'php_token_default' => '/Token.php',
'php_token_dir' => '/Token.php',
'php_token_div' => '/Token.php',
'php_token_div_equal' => '/Token.php',
'php_token_dnumber' => '/Token.php',
'php_token_do' => '/Token.php',
'php_token_doc_comment' => '/Token.php',
'php_token_dollar' => '/Token.php',
'php_token_dollar_open_curly_braces' => '/Token.php',
'php_token_dot' => '/Token.php',
'php_token_double_arrow' => '/Token.php',
'php_token_double_cast' => '/Token.php',
'php_token_double_colon' => '/Token.php',
'php_token_double_quotes' => '/Token.php',
'php_token_echo' => '/Token.php',
'php_token_else' => '/Token.php',
'php_token_elseif' => '/Token.php',
'php_token_empty' => '/Token.php',
'php_token_encapsed_and_whitespace' => '/Token.php',
'php_token_end_heredoc' => '/Token.php',
'php_token_enddeclare' => '/Token.php',
'php_token_endfor' => '/Token.php',
'php_token_endforeach' => '/Token.php',
'php_token_endif' => '/Token.php',
'php_token_endswitch' => '/Token.php',
'php_token_endwhile' => '/Token.php',
'php_token_equal' => '/Token.php',
'php_token_eval' => '/Token.php',
'php_token_exclamation_mark' => '/Token.php',
'php_token_exit' => '/Token.php',
'php_token_extends' => '/Token.php',
'php_token_file' => '/Token.php',
'php_token_final' => '/Token.php',
'php_token_for' => '/Token.php',
'php_token_foreach' => '/Token.php',
'php_token_func_c' => '/Token.php',
'php_token_function' => '/Token.php',
'php_token_global' => '/Token.php',
'php_token_goto' => '/Token.php',
'php_token_gt' => '/Token.php',
'php_token_halt_compiler' => '/Token.php',
'php_token_if' => '/Token.php',
'php_token_implements' => '/Token.php',
'php_token_inc' => '/Token.php',
'php_token_include' => '/Token.php',
'php_token_include_once' => '/Token.php',
'php_token_includes' => '/Token.php',
'php_token_inline_html' => '/Token.php',
'php_token_instanceof' => '/Token.php',
'php_token_insteadof' => '/Token.php',
'php_token_int_cast' => '/Token.php',
'php_token_interface' => '/Token.php',
'php_token_is_equal' => '/Token.php',
'php_token_is_greater_or_equal' => '/Token.php',
'php_token_is_identical' => '/Token.php',
'php_token_is_not_equal' => '/Token.php',
'php_token_is_not_identical' => '/Token.php',
'php_token_is_smaller_or_equal' => '/Token.php',
'php_token_isset' => '/Token.php',
'php_token_line' => '/Token.php',
'php_token_list' => '/Token.php',
'php_token_lnumber' => '/Token.php',
'php_token_logical_and' => '/Token.php',
'php_token_logical_or' => '/Token.php',
'php_token_logical_xor' => '/Token.php',
'php_token_lt' => '/Token.php',
'php_token_method_c' => '/Token.php',
'php_token_minus' => '/Token.php',
'php_token_minus_equal' => '/Token.php',
'php_token_mod_equal' => '/Token.php',
'php_token_mul_equal' => '/Token.php',
'php_token_mult' => '/Token.php',
'php_token_namespace' => '/Token.php',
'php_token_new' => '/Token.php',
'php_token_ns_c' => '/Token.php',
'php_token_ns_separator' => '/Token.php',
'php_token_num_string' => '/Token.php',
'php_token_object_cast' => '/Token.php',
'php_token_object_operator' => '/Token.php',
'php_token_open_bracket' => '/Token.php',
'php_token_open_curly' => '/Token.php',
'php_token_open_square' => '/Token.php',
'php_token_open_tag' => '/Token.php',
'php_token_open_tag_with_echo' => '/Token.php',
'php_token_or_equal' => '/Token.php',
'php_token_paamayim_nekudotayim' => '/Token.php',
'php_token_percent' => '/Token.php',
'php_token_pipe' => '/Token.php',
'php_token_plus' => '/Token.php',
'php_token_plus_equal' => '/Token.php',
'php_token_print' => '/Token.php',
'php_token_private' => '/Token.php',
'php_token_protected' => '/Token.php',
'php_token_public' => '/Token.php',
'php_token_question_mark' => '/Token.php',
'php_token_require' => '/Token.php',
'php_token_require_once' => '/Token.php',
'php_token_return' => '/Token.php',
'php_token_semicolon' => '/Token.php',
'php_token_sl' => '/Token.php',
'php_token_sl_equal' => '/Token.php',
'php_token_sr' => '/Token.php',
'php_token_sr_equal' => '/Token.php',
'php_token_start_heredoc' => '/Token.php',
'php_token_static' => '/Token.php',
'php_token_stream' => '/Token/Stream.php',
'php_token_stream_cachingfactory' => '/Token/Stream/CachingFactory.php',
'php_token_string' => '/Token.php',
'php_token_string_cast' => '/Token.php',
'php_token_string_varname' => '/Token.php',
'php_token_switch' => '/Token.php',
'php_token_throw' => '/Token.php',
'php_token_tilde' => '/Token.php',
'php_token_trait' => '/Token.php',
'php_token_trait_c' => '/Token.php',
'php_token_try' => '/Token.php',
'php_token_unset' => '/Token.php',
'php_token_unset_cast' => '/Token.php',
'php_token_use' => '/Token.php',
'php_token_var' => '/Token.php',
'php_token_variable' => '/Token.php',
'php_token_while' => '/Token.php',
'php_token_whitespace' => '/Token.php',
'php_token_xor_equal' => '/Token.php',
'php_tokenwithscope' => '/Token.php',
'php_tokenwithscopeandvisibility' => '/Token.php'
);
$path = dirname(dirname(dirname(__FILE__)));
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
);

View File

@@ -0,0 +1,65 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://github.com/sebastianbergmann/php-token-stream/tree
* @since File available since Release 1.1.0
*/
spl_autoload_register(
function ($class)
{
static $classes = NULL;
static $path = NULL;;
if ($classes === NULL) {
$classes = array(
___CLASSLIST___
);
$path = dirname(dirname(dirname(__FILE__)));
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
);

View File

@@ -0,0 +1,85 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
/**
* A caching factory for token stream objects.
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/tree
* @since Class available since Release 1.0.0
*/
class PHP_Token_Stream_CachingFactory
{
/**
* @var array
*/
protected static $cache = array();
/**
* @param string $filename
* @return PHP_Token_Stream
*/
public static function get($filename)
{
if (!isset(self::$cache[$filename])) {
self::$cache[$filename] = new PHP_Token_Stream($filename);
}
return self::$cache[$filename];
}
/**
* @param string $filename
*/
public static function clear($filename = NULL)
{
if (is_string($filename)) {
unset(self::$cache[$filename]);
} else {
self::$cache = array();
}
}
}

View File

@@ -0,0 +1,23 @@
PHP_TokenStream
===============
Installation
------------
PHP_TokenStream should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.
The PEAR channel (`pear.phpunit.de`) that is used to distribute PHP_TokenStream needs to be registered with the local PEAR environment:
sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded
This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:
sb@ubuntu tokenstream % pear install phpunit/PHP_TokenStream-beta
downloading PHP_TokenStream-0.9.1.tgz ...
Starting to download PHP_TokenStream-0.9.1.tgz (5,113 bytes)
...done: 5,113 bytes
install ok: channel://pear.phpunit.de/PHP_TokenStream-0.9.1
After the installation you can find the PHP_TokenStream source files inside your local PEAR directory; the path is usually `/usr/lib/php/PHP`.

View File

@@ -0,0 +1,122 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.2
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .
'_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token_CLASS class.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.2
*/
class PHP_Token_ClassTest extends PHPUnit_Framework_TestCase
{
protected $class;
protected $function;
protected function setUp()
{
$ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source2.php');
foreach ($ts as $token) {
if ($token instanceof PHP_Token_CLASS) {
$this->class = $token;
}
if ($token instanceof PHP_Token_FUNCTION) {
$this->function = $token;
break;
}
}
}
/**
* @covers PHP_Token_CLASS::getKeywords
*/
public function testGetClassKeywords()
{
$this->assertEquals('abstract', $this->class->getKeywords());
}
/**
* @covers PHP_Token_FUNCTION::getKeywords
*/
public function testGetFunctionKeywords()
{
$this->assertEquals('abstract,static', $this->function->getKeywords());
}
/**
* @covers PHP_Token_FUNCTION::getVisibility
*/
public function testGetFunctionVisibility()
{
$this->assertEquals('public', $this->function->getVisibility());
}
public function testIssue19()
{
$ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue19.php');
foreach ($ts as $token) {
if ($token instanceof PHP_Token_CLASS) {
$this->assertFalse($token->hasInterfaces());
}
}
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .
'_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token_FUNCTION class.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.0
*/
class PHP_Token_FunctionTest extends PHPUnit_Framework_TestCase
{
protected $functions;
protected function setUp()
{
$ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php');
foreach ($ts as $token) {
if ($token instanceof PHP_Token_FUNCTION) {
$this->functions[] = $token;
}
}
}
/**
* @covers PHP_Token_FUNCTION::getArguments
*/
public function testGetArguments()
{
$this->assertEquals(array(), $this->functions[0]->getArguments());
$this->assertEquals(
array('$baz' => 'Baz'), $this->functions[1]->getArguments()
);
$this->assertEquals(
array('$foobar' => 'Foobar'), $this->functions[2]->getArguments()
);
$this->assertEquals(
array('$barfoo' => 'Barfoo'), $this->functions[3]->getArguments()
);
$this->assertEquals(array(), $this->functions[4]->getArguments());
}
/**
* @covers PHP_Token_FUNCTION::getName
*/
public function testGetName()
{
$this->assertEquals('foo', $this->functions[0]->getName());
$this->assertEquals('bar', $this->functions[1]->getName());
$this->assertEquals('foobar', $this->functions[2]->getName());
$this->assertEquals('barfoo', $this->functions[3]->getName());
$this->assertEquals('baz', $this->functions[4]->getName());
}
/**
* @covers PHP_Token::getLine
*/
public function testGetLine()
{
$this->assertEquals(5, $this->functions[0]->getLine());
$this->assertEquals(10, $this->functions[1]->getLine());
$this->assertEquals(17, $this->functions[2]->getLine());
$this->assertEquals(21, $this->functions[3]->getLine());
$this->assertEquals(29, $this->functions[4]->getLine());
}
/**
* @covers PHP_TokenWithScope::getEndLine
*/
public function testGetEndLine()
{
$this->assertEquals(5, $this->functions[0]->getEndLine());
$this->assertEquals(12, $this->functions[1]->getEndLine());
$this->assertEquals(19, $this->functions[2]->getEndLine());
$this->assertEquals(23, $this->functions[3]->getEndLine());
$this->assertEquals(31, $this->functions[4]->getEndLine());
}
/**
* @covers PHP_Token_FUNCTION::getDocblock
*/
public function testGetDocblock()
{
$this->assertNull($this->functions[0]->getDocblock());
$this->assertEquals(
"/**\n * @param Baz \$baz\n */",
$this->functions[1]->getDocblock()
);
$this->assertEquals(
"/**\n * @param Foobar \$foobar\n */",
$this->functions[2]->getDocblock()
);
$this->assertNull($this->functions[3]->getDocblock());
$this->assertNull($this->functions[4]->getDocblock());
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.2
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .
'_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token_REQUIRE_ONCE, PHP_Token_REQUIRE
* PHP_Token_INCLUDE_ONCE and PHP_Token_INCLUDE_ONCE classes.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.2
*/
class PHP_Token_IncludeTest extends PHPUnit_Framework_TestCase
{
protected $ts;
protected function setUp()
{
$this->ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source3.php');
}
/**
* @covers PHP_Token_Includes::getName
* @covers PHP_Token_Includes::getType
*/
public function testGetIncludes()
{
$this->assertSame(
array('test4.php', 'test3.php', 'test2.php', 'test1.php'),
$this->ts->getIncludes()
);
}
/**
* @covers PHP_Token_Includes::getName
* @covers PHP_Token_Includes::getType
*/
public function testGetIncludesCategorized()
{
$this->assertSame(
array(
'require_once' => array('test4.php'),
'require' => array('test3.php'),
'include_once' => array('test2.php'),
'include' => array('test1.php')
),
$this->ts->getIncludes(TRUE)
);
}
/**
* @covers PHP_Token_Includes::getName
* @covers PHP_Token_Includes::getType
*/
public function testGetIncludesCategory()
{
$this->assertSame(
array('test4.php'),
$this->ts->getIncludes(TRUE, 'require_once')
);
}
}

View File

@@ -0,0 +1,236 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .
'_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token_INTERFACE class.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.0
*/
class PHP_Token_InterfaceTest extends PHPUnit_Framework_TestCase
{
protected $class;
protected $interfaces;
protected function setUp()
{
$ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source4.php');
$i = 0;
foreach ($ts as $token) {
if ($token instanceof PHP_Token_CLASS) {
$this->class = $token;
}
elseif ($token instanceof PHP_Token_INTERFACE) {
$this->interfaces[$i] = $token;
$i++;
}
}
}
/**
* @covers PHP_Token_INTERFACE::getName
*/
public function testGetName()
{
$this->assertEquals(
'iTemplate', $this->interfaces[0]->getName()
);
}
/**
* @covers PHP_Token_INTERFACE::getParent
*/
public function testGetParentNotExists()
{
$this->assertFalse(
$this->interfaces[0]->getParent()
);
}
/**
* @covers PHP_Token_INTERFACE::hasParent
*/
public function testHasParentNotExists()
{
$this->assertFalse(
$this->interfaces[0]->hasParent()
);
}
/**
* @covers PHP_Token_INTERFACE::getParent
*/
public function testGetParentExists()
{
$this->assertEquals(
'a', $this->interfaces[2]->getParent()
);
}
/**
* @covers PHP_Token_INTERFACE::hasParent
*/
public function testHasParentExists()
{
$this->assertTrue(
$this->interfaces[2]->hasParent()
);
}
/**
* @covers PHP_Token_INTERFACE::getInterfaces
*/
public function testGetInterfacesExists()
{
$this->assertEquals(
array('b'),
$this->class->getInterfaces()
);
}
/**
* @covers PHP_Token_INTERFACE::hasInterfaces
*/
public function testHasInterfacesExists()
{
$this->assertTrue(
$this->class->hasInterfaces()
);
}
/**
* @covers PHP_Token_INTERFACE::getPackage
*/
public function testGetPackageNamespace() {
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
foreach($tokenStream as $token) {
if($token instanceOf PHP_Token_INTERFACE) {
$package = $token->getPackage();
$this->assertSame('Foo\\Bar', $package['namespace']);
}
}
}
public function provideFilesWithClassesWithinMultipleNamespaces() {
return array(
array(TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingBraces.php'),
array(TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingNonBraceSyntax.php'),
);
}
/**
* @dataProvider provideFilesWithClassesWithinMultipleNamespaces
* @covers PHP_Token_INTERFACE::getPackage
*/
public function testGetPackageNamespaceForFileWithMultipleNamespaces($filepath) {
$tokenStream = new PHP_Token_Stream($filepath);
$firstClassFound = false;
foreach($tokenStream as $token) {
if($firstClassFound === false && $token instanceOf PHP_Token_INTERFACE) {
$package = $token->getPackage();
$this->assertSame('TestClassInBar', $token->getName());
$this->assertSame('Foo\\Bar', $package['namespace']);
$firstClassFound = true;
continue;
}
// Secound class
if($token instanceOf PHP_Token_INTERFACE) {
$package = $token->getPackage();
$this->assertSame('TestClassInBaz', $token->getName());
$this->assertSame('Foo\\Baz', $package['namespace']);
return;
}
}
$this->fail("Seachring for 2 classes failed");
}
public function testGetPackageNamespaceIsEmptyForInterfacesThatAreNotWithinNamespaces() {
foreach($this->interfaces as $token) {
$package = $token->getPackage();
$this->assertSame("", $package['namespace']);
}
}
/**
* @covers PHP_Token_INTERFACE::getPackage
*/
public function testGetPackageNamespaceWhenExtentingFromNamespaceClass() {
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classExtendsNamespacedClass.php');
$firstClassFound = false;
foreach($tokenStream as $token) {
if($firstClassFound === false && $token instanceOf PHP_Token_INTERFACE) {
$package = $token->getPackage();
$this->assertSame('Baz', $token->getName());
$this->assertSame('Foo\\Bar', $package['namespace']);
$firstClassFound = true;
continue;
}
if($token instanceOf PHP_Token_INTERFACE) {
$package = $token->getPackage();
$this->assertSame('Extender', $token->getName());
$this->assertSame('Other\\Space', $package['namespace']);
return;
}
}
$this->fail("Searching for 2 classes failed");
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .
'_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token_NAMESPACE class.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.0
*/
class PHP_Token_NamespaceTest extends PHPUnit_Framework_TestCase
{
/**
* @covers PHP_Token_NAMESPACE::getName
*/
public function testGetName()
{
$tokenStream = new PHP_Token_Stream(
TEST_FILES_PATH . 'classInNamespace.php'
);
foreach ($tokenStream as $token) {
if ($token instanceof PHP_Token_NAMESPACE) {
$this->assertSame('Foo\\Bar', $token->getName());
}
}
}
public function testGetStartLineWithUnscopedNamespace()
{
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
foreach($tokenStream as $token) {
if($token instanceOf PHP_Token_NAMESPACE) {
$this->assertSame(2, $token->getLine());
}
}
}
public function testGetEndLineWithUnscopedNamespace()
{
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php');
foreach($tokenStream as $token) {
if($token instanceOf PHP_Token_NAMESPACE) {
$this->assertSame(2, $token->getEndLine());
}
}
}
public function testGetStartLineWithScopedNamespace()
{
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
foreach($tokenStream as $token) {
if($token instanceOf PHP_Token_NAMESPACE) {
$this->assertSame(2, $token->getLine());
}
}
}
public function testGetEndLineWithScopedNamespace()
{
$tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php');
foreach($tokenStream as $token) {
if($token instanceOf PHP_Token_NAMESPACE) {
$this->assertSame(8, $token->getEndLine());
}
}
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* php-token-stream
*
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
if (!defined('TEST_FILES_PATH')) {
define(
'TEST_FILES_PATH',
dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR
);
}
require_once 'PHP/Token/Stream.php';
/**
* Tests for the PHP_Token class.
*
* @package PHP_TokenStream
* @subpackage Tests
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://github.com/sebastianbergmann/php-token-stream/
* @since Class available since Release 1.0.0
*/
class PHP_TokenTest extends PHPUnit_Framework_TestCase
{
/**
* @covers PHP_Token::__construct
* @covers PHP_Token::__toString
*/
public function testToString()
{
$this->markTestIncomplete();
}
/**
* @covers PHP_Token::__construct
* @covers PHP_Token::getLine
*/
public function testGetLine()
{
$this->markTestIncomplete();
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Foo\Bar;
class Baz {}
namespace Other\Space;
class Extender extends \Foo\Bar\Baz {}

View File

@@ -0,0 +1,6 @@
<?php
namespace Foo\Bar;
class TestClass
{
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Foo\BarScoped {
class TestClass {
}
}

View File

@@ -0,0 +1,3 @@
<?php
class TestClass {
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Foo\Bar;
class TestClassInBar
{
}
namespace Foo\Baz;
class TestClassInBaz
{
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Foo\Bar
{
class TestClassInBar
{
}
}
namespace Foo\Baz
{
class TestClassInBaz
{
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Some comment
*/
class Foo{function foo(){}
/**
* @param Baz $baz
*/
public function bar(Baz $baz)
{
}
/**
* @param Foobar $foobar
*/
static public function foobar(Foobar $foobar)
{
}
public function barfoo(Barfoo $barfoo)
{
}
/**
* This docblock does not belong to the baz function
*/
public function baz()
{
}
}

View File

@@ -0,0 +1,6 @@
<?php
// short desc
abstract class A {
/* abst meth: */
public static abstract function method();
}

View File

@@ -0,0 +1,14 @@
<?php
// This file is example#1
// from http://www.php.net/manual/en/function.get-included-files.php
include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename\n";
}

View File

@@ -0,0 +1,30 @@
<?php
// Declare the interface 'iTemplate'
interface iTemplate
{
public function setVariable($name, $var);
public function
getHtml($template);
}
interface a
{
public function foo();
}
interface b extends a
{
public function baz(Baz $baz);
}
// short desc for class that implement a unique interface
class c implements b
{
public function foo()
{
}
public function baz(Baz $baz)
{
}
}

View File

@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="PHP_TokenStream" default="build">
<property name="php" value="php"/>
<property name="phpunit" value="phpunit"/>
<target name="build"
depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,phpunit,phpcb"/>
<target name="build-parallel"
depends="prepare,lint,tools-parallel,phpunit,phpcb"/>
<target name="tools-parallel"
description="Run tools in parallel">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs-ci"/>
<antcall target="phploc"/>
</parallel>
</target>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/code-browser"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
</target>
<target name="prepare" depends="clean,phpab"
description="Prepare for build">
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>
<target name="phpab" description="Generate autoloader scripts">
<exec executable="phpab">
<arg value="--output" />
<arg path="PHP/Token/Stream/Autoload.php" />
<arg value="--template" />
<arg path="PHP/Token/Stream/Autoload.php.in" />
<arg value="--indent" />
<arg value=" " />
<arg path="PHP" />
</exec>
</target>
<target name="lint">
<apply executable="${php}" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/PHP">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/Tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="phploc">
<arg value="--log-csv" />
<arg value="${basedir}/build/logs/phploc.csv" />
<arg path="${basedir}/PHP" />
</exec>
</target>
<target name="pdepend"
description="Calculate software metrics using PHP_Depend">
<exec executable="pdepend">
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
<arg path="${basedir}/PHP" />
</exec>
</target>
<target name="phpmd"
description="Perform project mess detection using PHPMD">
<exec executable="phpmd">
<arg path="${basedir}/PHP" />
<arg value="text" />
<arg value="${basedir}/build/phpmd.xml" />
</exec>
</target>
<target name="phpmd-ci"
description="Perform project mess detection using PHPMD">
<exec executable="phpmd">
<arg path="${basedir}/PHP" />
<arg value="xml" />
<arg value="${basedir}/build/phpmd.xml" />
<arg value="--reportfile" />
<arg value="${basedir}/build/logs/pmd.xml" />
</exec>
</target>
<target name="phpcs"
description="Find coding standard violations using PHP_CodeSniffer">
<exec executable="phpcs">
<arg value="--standard=${basedir}/build/PHPCS" />
<arg value="--extensions=php" />
<arg value="--ignore=Autoload.php" />
<arg path="${basedir}/PHP" />
<arg path="${basedir}/Tests" />
</exec>
</target>
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer">
<exec executable="phpcs" output="/dev/null">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=${basedir}/build/PHPCS" />
<arg value="--extensions=php" />
<arg value="--ignore=Autoload.php" />
<arg path="${basedir}/PHP" />
<arg path="${basedir}/Tests" />
</exec>
</target>
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--log-pmd" />
<arg value="${basedir}/build/logs/pmd-cpd.xml" />
<arg path="${basedir}/PHP" />
</exec>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit">
<condition property="phpunit_cmd" value="${php} ${phpunit}" else="${phpunit}">
<not>
<equals arg1="${phpunit}" arg2="phpunit" />
</not>
</condition>
<exec executable="${phpunit_cmd}" failonerror="true"/>
</target>
<target name="phpcb"
description="Aggregate tool output with PHP_CodeBrowser">
<exec executable="phpcb">
<arg value="--log" />
<arg path="${basedir}/build/logs" />
<arg value="--source" />
<arg path="${basedir}/PHP" />
<arg value="--output" />
<arg path="${basedir}/build/code-browser" />
</exec>
</target>
</project>

View File

@@ -0,0 +1,22 @@
<?php
class PHPCS_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
{
public function __construct()
{
parent::__construct(true);
}
protected function getPatterns()
{
return array(
'do {EOL...} while (...);EOL',
'while (...) {EOL',
'for (...) {EOL',
'if (...) {EOL',
'foreach (...) {EOL',
'}EOLelse if (...) {EOL',
'}EOLelse {EOL',
'do {EOL',
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
class PHPCS_Sniffs_Whitespace_ConcatenationSpacingSniff implements PHP_CodeSniffer_Sniff
{
public function register()
{
return array(T_STRING_CONCAT);
}
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE ||
$tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$phpcsFile->addError(
'Concatenation operator must be surrounded by whitespace',
$stackPtr
);
}
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruleset name="Sebastian">
<description>Sebastian Bergmann's coding standard</description>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="PEAR.NamingConventions.ValidClassName"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.NoSilencedErrors"/>
<rule ref="Generic.PHP.UpperCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
</ruleset>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="Sebastian"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Sebastian Bergmann's ruleset</description>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity" />
<rule ref="rulesets/codesize.xml/NPathComplexity" />
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity" />
<rule ref="rulesets/codesize.xml/ExcessiveClassLength" />
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength" />
<rule ref="rulesets/codesize.xml/ExcessiveParameterList" />
<rule ref="rulesets/design.xml/EvalExpression" />
<rule ref="rulesets/design.xml/ExitExpression" />
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter" />
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" />
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField" />
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod" />
</ruleset>

View File

@@ -0,0 +1,33 @@
{
"name": "phpunit/php-token-stream",
"description": "Wrapper around PHP's tokenizer extension.",
"type": "library",
"keywords": [
"tokenizer"
],
"homepage": "http://www.phpunit.de/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-token-stream/issues",
"irc": "irc://irc.freenode.net/phpunit"
},
"require": {
"php": ">=5.3.3",
"ext-tokenizer": "*"
},
"autoload": {
"classmap": [
"PHP/"
]
},
"include-path": [
""
]
}

View File

@@ -0,0 +1,19 @@
{
"name": "phpunit/php-token-stream",
"keywords": [ "tokenizer" ],
"license": "BSD-3-Clause",
"homepage": "http://www.phpunit.de/",
"dependency_map": { },
"support": {
"issues": "https://github.com/sebastianbergmann/php-token-stream/issues",
"irc": "irc://irc.freenode.net/phpunit"
},
"autoload": {
"classmap": [ "PHP/" ]
},
"include_path": [
""
],
"version": false,
"time": false
}

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.4.10" version="2.0"
xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
<name>PHP_TokenStream</name>
<channel>pear.phpunit.de</channel>
<summary>Wrapper around PHP's tokenizer extension.</summary>
<description>Wrapper around PHP's tokenizer extension.</description>
<lead>
<name>Sebastian Bergmann</name>
<user>sb</user>
<email>sb@sebastian-bergmann.de</email>
<active>yes</active>
</lead>
<date>2012-10-05</date>
<version>
<release>1.1.5</release>
<api>1.1.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license>The BSD 3-Clause License</license>
<notes>http://github.com/sebastianbergmann/php-token-stream/tree</notes>
<contents>
<dir name="/">
<dir name="PHP">
<dir name="Token">
<dir name="Stream">
<file baseinstalldir="/" name="Autoload.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file baseinstalldir="/" name="CachingFactory.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
<file baseinstalldir="/" name="Stream.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
<file baseinstalldir="/" name="Token.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
<file baseinstalldir="/" name="ChangeLog.markdown" role="doc"/>
<file baseinstalldir="/" name="LICENSE" role="doc"/>
<file baseinstalldir="/" name="README.markdown" role="doc"/>
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.3.3</min>
</php>
<pearinstaller>
<min>1.9.4</min>
</pearinstaller>
<extension>
<name>tokenizer</name>
</extension>
</required>
</dependencies>
<phprelease/>
</package>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false"
bootstrap="PHP/Token/Stream/Autoload.php"
strict="true">
<testsuites>
<testsuite name="php-token-stream">
<directory suffix="Test.php">Tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build/coverage" title="PHP_TokenStream"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">PHP</directory>
</whitelist>
</filter>
</phpunit>