@@ -4,33 +4,33 @@ |
||
| 4 | 4 | */ |
| 5 | 5 | class Foo{function foo(){} |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @param Baz $baz |
|
| 9 | - */ |
|
| 10 | - public function bar(Baz $baz) |
|
| 11 | - { |
|
| 12 | - } |
|
| 7 | + /** |
|
| 8 | + * @param Baz $baz |
|
| 9 | + */ |
|
| 10 | + public function bar(Baz $baz) |
|
| 11 | + { |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param Foobar $foobar |
|
| 16 | - */ |
|
| 17 | - static public function foobar(Foobar $foobar) |
|
| 18 | - { |
|
| 19 | - } |
|
| 14 | + /** |
|
| 15 | + * @param Foobar $foobar |
|
| 16 | + */ |
|
| 17 | + static public function foobar(Foobar $foobar) |
|
| 18 | + { |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function barfoo(Barfoo $barfoo) |
|
| 22 | - { |
|
| 23 | - } |
|
| 21 | + public function barfoo(Barfoo $barfoo) |
|
| 22 | + { |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This docblock does not belong to the baz function |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * This docblock does not belong to the baz function |
|
| 27 | + */ |
|
| 28 | 28 | |
| 29 | - public function baz() |
|
| 30 | - { |
|
| 31 | - } |
|
| 29 | + public function baz() |
|
| 30 | + { |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function blaz($x, $y) |
|
| 34 | - { |
|
| 35 | - } |
|
| 33 | + public function blaz($x, $y) |
|
| 34 | + { |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | /** |
| 3 | 3 | * Some comment |
| 4 | 4 | */ |
| 5 | -class Foo{function foo(){} |
|
| 5 | +class Foo {function foo() {} |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * @param Baz $baz |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | require __DIR__ . '/../vendor/autoload.php'; |
| 11 | 11 | |
| 12 | 12 | define( |
| 13 | - 'TEST_FILES_PATH', |
|
| 14 | - __DIR__ . DIRECTORY_SEPARATOR . '_fixture' . DIRECTORY_SEPARATOR |
|
| 13 | + 'TEST_FILES_PATH', |
|
| 14 | + __DIR__ . DIRECTORY_SEPARATOR . '_fixture' . DIRECTORY_SEPARATOR |
|
| 15 | 15 | ); |
@@ -7,9 +7,9 @@ |
||
| 7 | 7 | * For the full copyright and license information, please view the LICENSE |
| 8 | 8 | * file that was distributed with this source code. |
| 9 | 9 | */ |
| 10 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 10 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 11 | 11 | |
| 12 | 12 | define( |
| 13 | 13 | 'TEST_FILES_PATH', |
| 14 | - __DIR__ . DIRECTORY_SEPARATOR . '_fixture' . DIRECTORY_SEPARATOR |
|
| 14 | + __DIR__.DIRECTORY_SEPARATOR.'_fixture'.DIRECTORY_SEPARATOR |
|
| 15 | 15 | ); |
@@ -12,58 +12,58 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_NamespaceTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @covers PHP_Token_NAMESPACE::getName |
|
| 17 | - */ |
|
| 18 | - public function testGetName() |
|
| 19 | - { |
|
| 20 | - $tokenStream = new PHP_Token_Stream( |
|
| 21 | - TEST_FILES_PATH . 'classInNamespace.php' |
|
| 22 | - ); |
|
| 15 | + /** |
|
| 16 | + * @covers PHP_Token_NAMESPACE::getName |
|
| 17 | + */ |
|
| 18 | + public function testGetName() |
|
| 19 | + { |
|
| 20 | + $tokenStream = new PHP_Token_Stream( |
|
| 21 | + TEST_FILES_PATH . 'classInNamespace.php' |
|
| 22 | + ); |
|
| 23 | 23 | |
| 24 | - foreach ($tokenStream as $token) { |
|
| 25 | - if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 26 | - $this->assertSame('Foo\\Bar', $token->getName()); |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 24 | + foreach ($tokenStream as $token) { |
|
| 25 | + if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 26 | + $this->assertSame('Foo\\Bar', $token->getName()); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function testGetStartLineWithUnscopedNamespace() |
|
| 32 | - { |
|
| 33 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 34 | - foreach ($tokenStream as $token) { |
|
| 35 | - if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 36 | - $this->assertSame(2, $token->getLine()); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - } |
|
| 31 | + public function testGetStartLineWithUnscopedNamespace() |
|
| 32 | + { |
|
| 33 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 34 | + foreach ($tokenStream as $token) { |
|
| 35 | + if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 36 | + $this->assertSame(2, $token->getLine()); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function testGetEndLineWithUnscopedNamespace() |
|
| 42 | - { |
|
| 43 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 44 | - foreach ($tokenStream as $token) { |
|
| 45 | - if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 46 | - $this->assertSame(2, $token->getEndLine()); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - public function testGetStartLineWithScopedNamespace() |
|
| 51 | - { |
|
| 52 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 53 | - foreach ($tokenStream as $token) { |
|
| 54 | - if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 55 | - $this->assertSame(2, $token->getLine()); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 41 | + public function testGetEndLineWithUnscopedNamespace() |
|
| 42 | + { |
|
| 43 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 44 | + foreach ($tokenStream as $token) { |
|
| 45 | + if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 46 | + $this->assertSame(2, $token->getEndLine()); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + public function testGetStartLineWithScopedNamespace() |
|
| 51 | + { |
|
| 52 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 53 | + foreach ($tokenStream as $token) { |
|
| 54 | + if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 55 | + $this->assertSame(2, $token->getLine()); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function testGetEndLineWithScopedNamespace() |
|
| 61 | - { |
|
| 62 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 63 | - foreach ($tokenStream as $token) { |
|
| 64 | - if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 65 | - $this->assertSame(8, $token->getEndLine()); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 60 | + public function testGetEndLineWithScopedNamespace() |
|
| 61 | + { |
|
| 62 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 63 | + foreach ($tokenStream as $token) { |
|
| 64 | + if ($token instanceof PHP_Token_NAMESPACE) { |
|
| 65 | + $this->assertSame(8, $token->getEndLine()); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | public function testGetName() |
| 19 | 19 | { |
| 20 | 20 | $tokenStream = new PHP_Token_Stream( |
| 21 | - TEST_FILES_PATH . 'classInNamespace.php' |
|
| 21 | + TEST_FILES_PATH.'classInNamespace.php' |
|
| 22 | 22 | ); |
| 23 | 23 | |
| 24 | 24 | foreach ($tokenStream as $token) { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function testGetStartLineWithUnscopedNamespace() |
| 32 | 32 | { |
| 33 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 33 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classInNamespace.php'); |
|
| 34 | 34 | foreach ($tokenStream as $token) { |
| 35 | 35 | if ($token instanceof PHP_Token_NAMESPACE) { |
| 36 | 36 | $this->assertSame(2, $token->getLine()); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function testGetEndLineWithUnscopedNamespace() |
| 42 | 42 | { |
| 43 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 43 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classInNamespace.php'); |
|
| 44 | 44 | foreach ($tokenStream as $token) { |
| 45 | 45 | if ($token instanceof PHP_Token_NAMESPACE) { |
| 46 | 46 | $this->assertSame(2, $token->getEndLine()); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | public function testGetStartLineWithScopedNamespace() |
| 51 | 51 | { |
| 52 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 52 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classInScopedNamespace.php'); |
|
| 53 | 53 | foreach ($tokenStream as $token) { |
| 54 | 54 | if ($token instanceof PHP_Token_NAMESPACE) { |
| 55 | 55 | $this->assertSame(2, $token->getLine()); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | public function testGetEndLineWithScopedNamespace() |
| 61 | 61 | { |
| 62 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInScopedNamespace.php'); |
|
| 62 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classInScopedNamespace.php'); |
|
| 63 | 63 | foreach ($tokenStream as $token) { |
| 64 | 64 | if ($token instanceof PHP_Token_NAMESPACE) { |
| 65 | 65 | $this->assertSame(8, $token->getEndLine()); |
@@ -12,184 +12,184 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_InterfaceTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var PHP_Token_CLASS |
|
| 17 | - */ |
|
| 18 | - private $class; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var PHP_Token_INTERFACE[] |
|
| 22 | - */ |
|
| 23 | - private $interfaces; |
|
| 24 | - |
|
| 25 | - protected function setUp() |
|
| 26 | - { |
|
| 27 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source4.php'); |
|
| 28 | - $i = 0; |
|
| 29 | - |
|
| 30 | - foreach ($ts as $token) { |
|
| 31 | - if ($token instanceof PHP_Token_CLASS) { |
|
| 32 | - $this->class = $token; |
|
| 33 | - } elseif ($token instanceof PHP_Token_INTERFACE) { |
|
| 34 | - $this->interfaces[$i] = $token; |
|
| 35 | - $i++; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @covers PHP_Token_INTERFACE::getName |
|
| 42 | - */ |
|
| 43 | - public function testGetName() |
|
| 44 | - { |
|
| 45 | - $this->assertEquals( |
|
| 46 | - 'iTemplate', $this->interfaces[0]->getName() |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @covers PHP_Token_INTERFACE::getParent |
|
| 52 | - */ |
|
| 53 | - public function testGetParentNotExists() |
|
| 54 | - { |
|
| 55 | - $this->assertFalse( |
|
| 56 | - $this->interfaces[0]->getParent() |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @covers PHP_Token_INTERFACE::hasParent |
|
| 62 | - */ |
|
| 63 | - public function testHasParentNotExists() |
|
| 64 | - { |
|
| 65 | - $this->assertFalse( |
|
| 66 | - $this->interfaces[0]->hasParent() |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @covers PHP_Token_INTERFACE::getParent |
|
| 72 | - */ |
|
| 73 | - public function testGetParentExists() |
|
| 74 | - { |
|
| 75 | - $this->assertEquals( |
|
| 76 | - 'a', $this->interfaces[2]->getParent() |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @covers PHP_Token_INTERFACE::hasParent |
|
| 82 | - */ |
|
| 83 | - public function testHasParentExists() |
|
| 84 | - { |
|
| 85 | - $this->assertTrue( |
|
| 86 | - $this->interfaces[2]->hasParent() |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @covers PHP_Token_INTERFACE::getInterfaces |
|
| 92 | - */ |
|
| 93 | - public function testGetInterfacesExists() |
|
| 94 | - { |
|
| 95 | - $this->assertEquals( |
|
| 96 | - ['b'], |
|
| 97 | - $this->class->getInterfaces() |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @covers PHP_Token_INTERFACE::hasInterfaces |
|
| 103 | - */ |
|
| 104 | - public function testHasInterfacesExists() |
|
| 105 | - { |
|
| 106 | - $this->assertTrue( |
|
| 107 | - $this->class->hasInterfaces() |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @covers PHP_Token_INTERFACE::getPackage |
|
| 113 | - */ |
|
| 114 | - public function testGetPackageNamespace() |
|
| 115 | - { |
|
| 116 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 117 | - foreach ($tokenStream as $token) { |
|
| 118 | - if ($token instanceof PHP_Token_INTERFACE) { |
|
| 119 | - $package = $token->getPackage(); |
|
| 120 | - $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - public function provideFilesWithClassesWithinMultipleNamespaces() |
|
| 127 | - { |
|
| 128 | - return [ |
|
| 129 | - [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingBraces.php'], |
|
| 130 | - [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingNonBraceSyntax.php'], |
|
| 131 | - ]; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @dataProvider provideFilesWithClassesWithinMultipleNamespaces |
|
| 136 | - * @covers PHP_Token_INTERFACE::getPackage |
|
| 137 | - */ |
|
| 138 | - public function testGetPackageNamespaceForFileWithMultipleNamespaces($filepath) |
|
| 139 | - { |
|
| 140 | - $tokenStream = new PHP_Token_Stream($filepath); |
|
| 141 | - $firstClassFound = false; |
|
| 142 | - foreach ($tokenStream as $token) { |
|
| 143 | - if ($firstClassFound === false && $token instanceof PHP_Token_INTERFACE) { |
|
| 144 | - $package = $token->getPackage(); |
|
| 145 | - $this->assertSame('TestClassInBar', $token->getName()); |
|
| 146 | - $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 147 | - $firstClassFound = true; |
|
| 148 | - continue; |
|
| 149 | - } |
|
| 150 | - // Secound class |
|
| 151 | - if ($token instanceof PHP_Token_INTERFACE) { |
|
| 152 | - $package = $token->getPackage(); |
|
| 153 | - $this->assertSame('TestClassInBaz', $token->getName()); |
|
| 154 | - $this->assertSame('Foo\\Baz', $package['namespace']); |
|
| 155 | - |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - $this->fail('Seachring for 2 classes failed'); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function testGetPackageNamespaceIsEmptyForInterfacesThatAreNotWithinNamespaces() |
|
| 163 | - { |
|
| 164 | - foreach ($this->interfaces as $token) { |
|
| 165 | - $package = $token->getPackage(); |
|
| 166 | - $this->assertSame('', $package['namespace']); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @covers PHP_Token_INTERFACE::getPackage |
|
| 172 | - */ |
|
| 173 | - public function testGetPackageNamespaceWhenExtentingFromNamespaceClass() |
|
| 174 | - { |
|
| 175 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classExtendsNamespacedClass.php'); |
|
| 176 | - $firstClassFound = false; |
|
| 177 | - foreach ($tokenStream as $token) { |
|
| 178 | - if ($firstClassFound === false && $token instanceof PHP_Token_INTERFACE) { |
|
| 179 | - $package = $token->getPackage(); |
|
| 180 | - $this->assertSame('Baz', $token->getName()); |
|
| 181 | - $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 182 | - $firstClassFound = true; |
|
| 183 | - continue; |
|
| 184 | - } |
|
| 185 | - if ($token instanceof PHP_Token_INTERFACE) { |
|
| 186 | - $package = $token->getPackage(); |
|
| 187 | - $this->assertSame('Extender', $token->getName()); |
|
| 188 | - $this->assertSame('Other\\Space', $package['namespace']); |
|
| 189 | - |
|
| 190 | - return; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - $this->fail('Searching for 2 classes failed'); |
|
| 194 | - } |
|
| 15 | + /** |
|
| 16 | + * @var PHP_Token_CLASS |
|
| 17 | + */ |
|
| 18 | + private $class; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var PHP_Token_INTERFACE[] |
|
| 22 | + */ |
|
| 23 | + private $interfaces; |
|
| 24 | + |
|
| 25 | + protected function setUp() |
|
| 26 | + { |
|
| 27 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source4.php'); |
|
| 28 | + $i = 0; |
|
| 29 | + |
|
| 30 | + foreach ($ts as $token) { |
|
| 31 | + if ($token instanceof PHP_Token_CLASS) { |
|
| 32 | + $this->class = $token; |
|
| 33 | + } elseif ($token instanceof PHP_Token_INTERFACE) { |
|
| 34 | + $this->interfaces[$i] = $token; |
|
| 35 | + $i++; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @covers PHP_Token_INTERFACE::getName |
|
| 42 | + */ |
|
| 43 | + public function testGetName() |
|
| 44 | + { |
|
| 45 | + $this->assertEquals( |
|
| 46 | + 'iTemplate', $this->interfaces[0]->getName() |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @covers PHP_Token_INTERFACE::getParent |
|
| 52 | + */ |
|
| 53 | + public function testGetParentNotExists() |
|
| 54 | + { |
|
| 55 | + $this->assertFalse( |
|
| 56 | + $this->interfaces[0]->getParent() |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @covers PHP_Token_INTERFACE::hasParent |
|
| 62 | + */ |
|
| 63 | + public function testHasParentNotExists() |
|
| 64 | + { |
|
| 65 | + $this->assertFalse( |
|
| 66 | + $this->interfaces[0]->hasParent() |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @covers PHP_Token_INTERFACE::getParent |
|
| 72 | + */ |
|
| 73 | + public function testGetParentExists() |
|
| 74 | + { |
|
| 75 | + $this->assertEquals( |
|
| 76 | + 'a', $this->interfaces[2]->getParent() |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @covers PHP_Token_INTERFACE::hasParent |
|
| 82 | + */ |
|
| 83 | + public function testHasParentExists() |
|
| 84 | + { |
|
| 85 | + $this->assertTrue( |
|
| 86 | + $this->interfaces[2]->hasParent() |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @covers PHP_Token_INTERFACE::getInterfaces |
|
| 92 | + */ |
|
| 93 | + public function testGetInterfacesExists() |
|
| 94 | + { |
|
| 95 | + $this->assertEquals( |
|
| 96 | + ['b'], |
|
| 97 | + $this->class->getInterfaces() |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @covers PHP_Token_INTERFACE::hasInterfaces |
|
| 103 | + */ |
|
| 104 | + public function testHasInterfacesExists() |
|
| 105 | + { |
|
| 106 | + $this->assertTrue( |
|
| 107 | + $this->class->hasInterfaces() |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @covers PHP_Token_INTERFACE::getPackage |
|
| 113 | + */ |
|
| 114 | + public function testGetPackageNamespace() |
|
| 115 | + { |
|
| 116 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 117 | + foreach ($tokenStream as $token) { |
|
| 118 | + if ($token instanceof PHP_Token_INTERFACE) { |
|
| 119 | + $package = $token->getPackage(); |
|
| 120 | + $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + public function provideFilesWithClassesWithinMultipleNamespaces() |
|
| 127 | + { |
|
| 128 | + return [ |
|
| 129 | + [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingBraces.php'], |
|
| 130 | + [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingNonBraceSyntax.php'], |
|
| 131 | + ]; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @dataProvider provideFilesWithClassesWithinMultipleNamespaces |
|
| 136 | + * @covers PHP_Token_INTERFACE::getPackage |
|
| 137 | + */ |
|
| 138 | + public function testGetPackageNamespaceForFileWithMultipleNamespaces($filepath) |
|
| 139 | + { |
|
| 140 | + $tokenStream = new PHP_Token_Stream($filepath); |
|
| 141 | + $firstClassFound = false; |
|
| 142 | + foreach ($tokenStream as $token) { |
|
| 143 | + if ($firstClassFound === false && $token instanceof PHP_Token_INTERFACE) { |
|
| 144 | + $package = $token->getPackage(); |
|
| 145 | + $this->assertSame('TestClassInBar', $token->getName()); |
|
| 146 | + $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 147 | + $firstClassFound = true; |
|
| 148 | + continue; |
|
| 149 | + } |
|
| 150 | + // Secound class |
|
| 151 | + if ($token instanceof PHP_Token_INTERFACE) { |
|
| 152 | + $package = $token->getPackage(); |
|
| 153 | + $this->assertSame('TestClassInBaz', $token->getName()); |
|
| 154 | + $this->assertSame('Foo\\Baz', $package['namespace']); |
|
| 155 | + |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + $this->fail('Seachring for 2 classes failed'); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function testGetPackageNamespaceIsEmptyForInterfacesThatAreNotWithinNamespaces() |
|
| 163 | + { |
|
| 164 | + foreach ($this->interfaces as $token) { |
|
| 165 | + $package = $token->getPackage(); |
|
| 166 | + $this->assertSame('', $package['namespace']); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @covers PHP_Token_INTERFACE::getPackage |
|
| 172 | + */ |
|
| 173 | + public function testGetPackageNamespaceWhenExtentingFromNamespaceClass() |
|
| 174 | + { |
|
| 175 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classExtendsNamespacedClass.php'); |
|
| 176 | + $firstClassFound = false; |
|
| 177 | + foreach ($tokenStream as $token) { |
|
| 178 | + if ($firstClassFound === false && $token instanceof PHP_Token_INTERFACE) { |
|
| 179 | + $package = $token->getPackage(); |
|
| 180 | + $this->assertSame('Baz', $token->getName()); |
|
| 181 | + $this->assertSame('Foo\\Bar', $package['namespace']); |
|
| 182 | + $firstClassFound = true; |
|
| 183 | + continue; |
|
| 184 | + } |
|
| 185 | + if ($token instanceof PHP_Token_INTERFACE) { |
|
| 186 | + $package = $token->getPackage(); |
|
| 187 | + $this->assertSame('Extender', $token->getName()); |
|
| 188 | + $this->assertSame('Other\\Space', $package['namespace']); |
|
| 189 | + |
|
| 190 | + return; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + $this->fail('Searching for 2 classes failed'); |
|
| 194 | + } |
|
| 195 | 195 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | protected function setUp() |
| 26 | 26 | { |
| 27 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source4.php'); |
|
| 27 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'source4.php'); |
|
| 28 | 28 | $i = 0; |
| 29 | 29 | |
| 30 | 30 | foreach ($ts as $token) { |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function testGetPackageNamespace() |
| 115 | 115 | { |
| 116 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classInNamespace.php'); |
|
| 116 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classInNamespace.php'); |
|
| 117 | 117 | foreach ($tokenStream as $token) { |
| 118 | 118 | if ($token instanceof PHP_Token_INTERFACE) { |
| 119 | 119 | $package = $token->getPackage(); |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | public function provideFilesWithClassesWithinMultipleNamespaces() |
| 127 | 127 | { |
| 128 | 128 | return [ |
| 129 | - [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingBraces.php'], |
|
| 130 | - [TEST_FILES_PATH . 'multipleNamespacesWithOneClassUsingNonBraceSyntax.php'], |
|
| 129 | + [TEST_FILES_PATH.'multipleNamespacesWithOneClassUsingBraces.php'], |
|
| 130 | + [TEST_FILES_PATH.'multipleNamespacesWithOneClassUsingNonBraceSyntax.php'], |
|
| 131 | 131 | ]; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function testGetPackageNamespaceWhenExtentingFromNamespaceClass() |
| 174 | 174 | { |
| 175 | - $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH . 'classExtendsNamespacedClass.php'); |
|
| 175 | + $tokenStream = new PHP_Token_Stream(TEST_FILES_PATH.'classExtendsNamespacedClass.php'); |
|
| 176 | 176 | $firstClassFound = false; |
| 177 | 177 | foreach ($tokenStream as $token) { |
| 178 | 178 | if ($firstClassFound === false && $token instanceof PHP_Token_INTERFACE) { |
@@ -12,142 +12,142 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_ClassTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var PHP_Token_CLASS |
|
| 17 | - */ |
|
| 18 | - private $class; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var PHP_Token_FUNCTION |
|
| 22 | - */ |
|
| 23 | - private $function; |
|
| 24 | - |
|
| 25 | - protected function setUp() |
|
| 26 | - { |
|
| 27 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source2.php'); |
|
| 28 | - |
|
| 29 | - foreach ($ts as $token) { |
|
| 30 | - if ($token instanceof PHP_Token_CLASS) { |
|
| 31 | - $this->class = $token; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if ($token instanceof PHP_Token_FUNCTION) { |
|
| 35 | - $this->function = $token; |
|
| 36 | - break; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @covers PHP_Token_CLASS::getKeywords |
|
| 43 | - */ |
|
| 44 | - public function testGetClassKeywords() |
|
| 45 | - { |
|
| 46 | - $this->assertEquals('abstract', $this->class->getKeywords()); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @covers PHP_Token_FUNCTION::getKeywords |
|
| 51 | - */ |
|
| 52 | - public function testGetFunctionKeywords() |
|
| 53 | - { |
|
| 54 | - $this->assertEquals('abstract,static', $this->function->getKeywords()); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @covers PHP_Token_FUNCTION::getVisibility |
|
| 59 | - */ |
|
| 60 | - public function testGetFunctionVisibility() |
|
| 61 | - { |
|
| 62 | - $this->assertEquals('public', $this->function->getVisibility()); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function testIssue19() |
|
| 66 | - { |
|
| 67 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue19.php'); |
|
| 68 | - |
|
| 69 | - foreach ($ts as $token) { |
|
| 70 | - if ($token instanceof PHP_Token_CLASS) { |
|
| 71 | - $this->assertFalse($token->hasInterfaces()); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function testIssue30() |
|
| 77 | - { |
|
| 78 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue30.php'); |
|
| 79 | - $this->assertCount(1, $ts->getClasses()); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function testAnonymousClassesAreHandledCorrectly() |
|
| 83 | - { |
|
| 84 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class.php'); |
|
| 85 | - |
|
| 86 | - $classes = $ts->getClasses(); |
|
| 87 | - |
|
| 88 | - $this->assertEquals( |
|
| 89 | - [ |
|
| 90 | - 'class_with_method_that_declares_anonymous_class', |
|
| 91 | - 'AnonymousClass:9#31', |
|
| 92 | - 'AnonymousClass:10#55', |
|
| 93 | - 'AnonymousClass:11#75', |
|
| 94 | - 'AnonymousClass:12#91', |
|
| 95 | - 'AnonymousClass:13#107' |
|
| 96 | - ], |
|
| 97 | - array_keys($classes) |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @ticket https://github.com/sebastianbergmann/php-token-stream/issues/52 |
|
| 103 | - */ |
|
| 104 | - public function testAnonymousClassesAreHandledCorrectly2() |
|
| 105 | - { |
|
| 106 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class2.php'); |
|
| 107 | - |
|
| 108 | - $classes = $ts->getClasses(); |
|
| 109 | - |
|
| 110 | - $this->assertEquals(['Test', 'AnonymousClass:4#23'], array_keys($classes)); |
|
| 111 | - $this->assertEquals(['methodOne', 'methodTwo'], array_keys($classes['Test']['methods'])); |
|
| 112 | - |
|
| 113 | - $this->assertEmpty($ts->getFunctions()); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function testImportedFunctionsAreHandledCorrectly() |
|
| 117 | - { |
|
| 118 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'classUsesNamespacedFunction.php'); |
|
| 119 | - |
|
| 120 | - $this->assertEmpty($ts->getFunctions()); |
|
| 121 | - $this->assertCount(1, $ts->getClasses()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @ticket https://github.com/sebastianbergmann/php-code-coverage/issues/543 |
|
| 126 | - */ |
|
| 127 | - public function testClassWithMultipleAnonymousClassesAndFunctionsIsHandledCorrectly() |
|
| 128 | - { |
|
| 129 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_multiple_anonymous_classes_and_functions.php'); |
|
| 130 | - |
|
| 131 | - $classes = $ts->getClasses(); |
|
| 132 | - |
|
| 133 | - $this->assertArrayHasKey('class_with_multiple_anonymous_classes_and_functions', $classes); |
|
| 134 | - $this->assertArrayHasKey('AnonymousClass:6#23', $classes); |
|
| 135 | - $this->assertArrayHasKey('AnonymousClass:12#53', $classes); |
|
| 136 | - $this->assertArrayHasKey('m', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 137 | - $this->assertArrayHasKey('anonymousFunction:18#81', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 138 | - $this->assertArrayHasKey('anonymousFunction:22#108', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @ticket https://github.com/sebastianbergmann/php-token-stream/issues/68 |
|
| 143 | - */ |
|
| 144 | - public function testClassWithMethodNamedEmptyIsHandledCorrectly() |
|
| 145 | - { |
|
| 146 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_named_empty.php'); |
|
| 147 | - |
|
| 148 | - $classes = $ts->getClasses(); |
|
| 149 | - |
|
| 150 | - $this->assertArrayHasKey('class_with_method_named_empty', $classes); |
|
| 151 | - $this->assertArrayHasKey('empty', $classes['class_with_method_named_empty']['methods']); |
|
| 152 | - } |
|
| 15 | + /** |
|
| 16 | + * @var PHP_Token_CLASS |
|
| 17 | + */ |
|
| 18 | + private $class; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var PHP_Token_FUNCTION |
|
| 22 | + */ |
|
| 23 | + private $function; |
|
| 24 | + |
|
| 25 | + protected function setUp() |
|
| 26 | + { |
|
| 27 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source2.php'); |
|
| 28 | + |
|
| 29 | + foreach ($ts as $token) { |
|
| 30 | + if ($token instanceof PHP_Token_CLASS) { |
|
| 31 | + $this->class = $token; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if ($token instanceof PHP_Token_FUNCTION) { |
|
| 35 | + $this->function = $token; |
|
| 36 | + break; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @covers PHP_Token_CLASS::getKeywords |
|
| 43 | + */ |
|
| 44 | + public function testGetClassKeywords() |
|
| 45 | + { |
|
| 46 | + $this->assertEquals('abstract', $this->class->getKeywords()); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @covers PHP_Token_FUNCTION::getKeywords |
|
| 51 | + */ |
|
| 52 | + public function testGetFunctionKeywords() |
|
| 53 | + { |
|
| 54 | + $this->assertEquals('abstract,static', $this->function->getKeywords()); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @covers PHP_Token_FUNCTION::getVisibility |
|
| 59 | + */ |
|
| 60 | + public function testGetFunctionVisibility() |
|
| 61 | + { |
|
| 62 | + $this->assertEquals('public', $this->function->getVisibility()); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function testIssue19() |
|
| 66 | + { |
|
| 67 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue19.php'); |
|
| 68 | + |
|
| 69 | + foreach ($ts as $token) { |
|
| 70 | + if ($token instanceof PHP_Token_CLASS) { |
|
| 71 | + $this->assertFalse($token->hasInterfaces()); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function testIssue30() |
|
| 77 | + { |
|
| 78 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue30.php'); |
|
| 79 | + $this->assertCount(1, $ts->getClasses()); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testAnonymousClassesAreHandledCorrectly() |
|
| 83 | + { |
|
| 84 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class.php'); |
|
| 85 | + |
|
| 86 | + $classes = $ts->getClasses(); |
|
| 87 | + |
|
| 88 | + $this->assertEquals( |
|
| 89 | + [ |
|
| 90 | + 'class_with_method_that_declares_anonymous_class', |
|
| 91 | + 'AnonymousClass:9#31', |
|
| 92 | + 'AnonymousClass:10#55', |
|
| 93 | + 'AnonymousClass:11#75', |
|
| 94 | + 'AnonymousClass:12#91', |
|
| 95 | + 'AnonymousClass:13#107' |
|
| 96 | + ], |
|
| 97 | + array_keys($classes) |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @ticket https://github.com/sebastianbergmann/php-token-stream/issues/52 |
|
| 103 | + */ |
|
| 104 | + public function testAnonymousClassesAreHandledCorrectly2() |
|
| 105 | + { |
|
| 106 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class2.php'); |
|
| 107 | + |
|
| 108 | + $classes = $ts->getClasses(); |
|
| 109 | + |
|
| 110 | + $this->assertEquals(['Test', 'AnonymousClass:4#23'], array_keys($classes)); |
|
| 111 | + $this->assertEquals(['methodOne', 'methodTwo'], array_keys($classes['Test']['methods'])); |
|
| 112 | + |
|
| 113 | + $this->assertEmpty($ts->getFunctions()); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function testImportedFunctionsAreHandledCorrectly() |
|
| 117 | + { |
|
| 118 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'classUsesNamespacedFunction.php'); |
|
| 119 | + |
|
| 120 | + $this->assertEmpty($ts->getFunctions()); |
|
| 121 | + $this->assertCount(1, $ts->getClasses()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @ticket https://github.com/sebastianbergmann/php-code-coverage/issues/543 |
|
| 126 | + */ |
|
| 127 | + public function testClassWithMultipleAnonymousClassesAndFunctionsIsHandledCorrectly() |
|
| 128 | + { |
|
| 129 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_multiple_anonymous_classes_and_functions.php'); |
|
| 130 | + |
|
| 131 | + $classes = $ts->getClasses(); |
|
| 132 | + |
|
| 133 | + $this->assertArrayHasKey('class_with_multiple_anonymous_classes_and_functions', $classes); |
|
| 134 | + $this->assertArrayHasKey('AnonymousClass:6#23', $classes); |
|
| 135 | + $this->assertArrayHasKey('AnonymousClass:12#53', $classes); |
|
| 136 | + $this->assertArrayHasKey('m', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 137 | + $this->assertArrayHasKey('anonymousFunction:18#81', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 138 | + $this->assertArrayHasKey('anonymousFunction:22#108', $classes['class_with_multiple_anonymous_classes_and_functions']['methods']); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @ticket https://github.com/sebastianbergmann/php-token-stream/issues/68 |
|
| 143 | + */ |
|
| 144 | + public function testClassWithMethodNamedEmptyIsHandledCorrectly() |
|
| 145 | + { |
|
| 146 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_named_empty.php'); |
|
| 147 | + |
|
| 148 | + $classes = $ts->getClasses(); |
|
| 149 | + |
|
| 150 | + $this->assertArrayHasKey('class_with_method_named_empty', $classes); |
|
| 151 | + $this->assertArrayHasKey('empty', $classes['class_with_method_named_empty']['methods']); |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | protected function setUp() |
| 26 | 26 | { |
| 27 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source2.php'); |
|
| 27 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'source2.php'); |
|
| 28 | 28 | |
| 29 | 29 | foreach ($ts as $token) { |
| 30 | 30 | if ($token instanceof PHP_Token_CLASS) { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | public function testIssue19() |
| 66 | 66 | { |
| 67 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue19.php'); |
|
| 67 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'issue19.php'); |
|
| 68 | 68 | |
| 69 | 69 | foreach ($ts as $token) { |
| 70 | 70 | if ($token instanceof PHP_Token_CLASS) { |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function testIssue30() |
| 77 | 77 | { |
| 78 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'issue30.php'); |
|
| 78 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'issue30.php'); |
|
| 79 | 79 | $this->assertCount(1, $ts->getClasses()); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function testAnonymousClassesAreHandledCorrectly() |
| 83 | 83 | { |
| 84 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class.php'); |
|
| 84 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'class_with_method_that_declares_anonymous_class.php'); |
|
| 85 | 85 | |
| 86 | 86 | $classes = $ts->getClasses(); |
| 87 | 87 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function testAnonymousClassesAreHandledCorrectly2() |
| 105 | 105 | { |
| 106 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_that_declares_anonymous_class2.php'); |
|
| 106 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'class_with_method_that_declares_anonymous_class2.php'); |
|
| 107 | 107 | |
| 108 | 108 | $classes = $ts->getClasses(); |
| 109 | 109 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | public function testImportedFunctionsAreHandledCorrectly() |
| 117 | 117 | { |
| 118 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'classUsesNamespacedFunction.php'); |
|
| 118 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'classUsesNamespacedFunction.php'); |
|
| 119 | 119 | |
| 120 | 120 | $this->assertEmpty($ts->getFunctions()); |
| 121 | 121 | $this->assertCount(1, $ts->getClasses()); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function testClassWithMultipleAnonymousClassesAndFunctionsIsHandledCorrectly() |
| 128 | 128 | { |
| 129 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_multiple_anonymous_classes_and_functions.php'); |
|
| 129 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'class_with_multiple_anonymous_classes_and_functions.php'); |
|
| 130 | 130 | |
| 131 | 131 | $classes = $ts->getClasses(); |
| 132 | 132 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function testClassWithMethodNamedEmptyIsHandledCorrectly() |
| 145 | 145 | { |
| 146 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'class_with_method_named_empty.php'); |
|
| 146 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'class_with_method_named_empty.php'); |
|
| 147 | 147 | |
| 148 | 148 | $classes = $ts->getClasses(); |
| 149 | 149 | |
@@ -12,54 +12,54 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_IncludeTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var PHP_Token_Stream |
|
| 17 | - */ |
|
| 18 | - private $ts; |
|
| 15 | + /** |
|
| 16 | + * @var PHP_Token_Stream |
|
| 17 | + */ |
|
| 18 | + private $ts; |
|
| 19 | 19 | |
| 20 | - protected function setUp() |
|
| 21 | - { |
|
| 22 | - $this->ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source3.php'); |
|
| 23 | - } |
|
| 20 | + protected function setUp() |
|
| 21 | + { |
|
| 22 | + $this->ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source3.php'); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @covers PHP_Token_Includes::getName |
|
| 27 | - * @covers PHP_Token_Includes::getType |
|
| 28 | - */ |
|
| 29 | - public function testGetIncludes() |
|
| 30 | - { |
|
| 31 | - $this->assertSame( |
|
| 32 | - ['test4.php', 'test3.php', 'test2.php', 'test1.php'], |
|
| 33 | - $this->ts->getIncludes() |
|
| 34 | - ); |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * @covers PHP_Token_Includes::getName |
|
| 27 | + * @covers PHP_Token_Includes::getType |
|
| 28 | + */ |
|
| 29 | + public function testGetIncludes() |
|
| 30 | + { |
|
| 31 | + $this->assertSame( |
|
| 32 | + ['test4.php', 'test3.php', 'test2.php', 'test1.php'], |
|
| 33 | + $this->ts->getIncludes() |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @covers PHP_Token_Includes::getName |
|
| 39 | - * @covers PHP_Token_Includes::getType |
|
| 40 | - */ |
|
| 41 | - public function testGetIncludesCategorized() |
|
| 42 | - { |
|
| 43 | - $this->assertSame( |
|
| 44 | - [ |
|
| 45 | - 'require_once' => ['test4.php'], |
|
| 46 | - 'require' => ['test3.php'], |
|
| 47 | - 'include_once' => ['test2.php'], |
|
| 48 | - 'include' => ['test1.php'] |
|
| 49 | - ], |
|
| 50 | - $this->ts->getIncludes(true) |
|
| 51 | - ); |
|
| 52 | - } |
|
| 37 | + /** |
|
| 38 | + * @covers PHP_Token_Includes::getName |
|
| 39 | + * @covers PHP_Token_Includes::getType |
|
| 40 | + */ |
|
| 41 | + public function testGetIncludesCategorized() |
|
| 42 | + { |
|
| 43 | + $this->assertSame( |
|
| 44 | + [ |
|
| 45 | + 'require_once' => ['test4.php'], |
|
| 46 | + 'require' => ['test3.php'], |
|
| 47 | + 'include_once' => ['test2.php'], |
|
| 48 | + 'include' => ['test1.php'] |
|
| 49 | + ], |
|
| 50 | + $this->ts->getIncludes(true) |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @covers PHP_Token_Includes::getName |
|
| 56 | - * @covers PHP_Token_Includes::getType |
|
| 57 | - */ |
|
| 58 | - public function testGetIncludesCategory() |
|
| 59 | - { |
|
| 60 | - $this->assertSame( |
|
| 61 | - ['test4.php'], |
|
| 62 | - $this->ts->getIncludes(true, 'require_once') |
|
| 63 | - ); |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * @covers PHP_Token_Includes::getName |
|
| 56 | + * @covers PHP_Token_Includes::getType |
|
| 57 | + */ |
|
| 58 | + public function testGetIncludesCategory() |
|
| 59 | + { |
|
| 60 | + $this->assertSame( |
|
| 61 | + ['test4.php'], |
|
| 62 | + $this->ts->getIncludes(true, 'require_once') |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | |
| 20 | 20 | protected function setUp() |
| 21 | 21 | { |
| 22 | - $this->ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source3.php'); |
|
| 22 | + $this->ts = new PHP_Token_Stream(TEST_FILES_PATH.'source3.php'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -12,67 +12,67 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_ClosureTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var PHP_Token_FUNCTION[] |
|
| 17 | - */ |
|
| 18 | - private $functions; |
|
| 15 | + /** |
|
| 16 | + * @var PHP_Token_FUNCTION[] |
|
| 17 | + */ |
|
| 18 | + private $functions; |
|
| 19 | 19 | |
| 20 | - protected function setUp() |
|
| 21 | - { |
|
| 22 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php'); |
|
| 20 | + protected function setUp() |
|
| 21 | + { |
|
| 22 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php'); |
|
| 23 | 23 | |
| 24 | - foreach ($ts as $token) { |
|
| 25 | - if ($token instanceof PHP_Token_FUNCTION) { |
|
| 26 | - $this->functions[] = $token; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 24 | + foreach ($ts as $token) { |
|
| 25 | + if ($token instanceof PHP_Token_FUNCTION) { |
|
| 26 | + $this->functions[] = $token; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @covers PHP_Token_FUNCTION::getArguments |
|
| 33 | - */ |
|
| 34 | - public function testGetArguments() |
|
| 35 | - { |
|
| 36 | - $this->assertEquals(['$foo' => null, '$bar' => null], $this->functions[0]->getArguments()); |
|
| 37 | - $this->assertEquals(['$foo' => 'Foo', '$bar' => null], $this->functions[1]->getArguments()); |
|
| 38 | - $this->assertEquals(['$foo' => null, '$bar' => null, '$baz' => null], $this->functions[2]->getArguments()); |
|
| 39 | - $this->assertEquals(['$foo' => 'Foo', '$bar' => null, '$baz' => null], $this->functions[3]->getArguments()); |
|
| 40 | - $this->assertEquals([], $this->functions[4]->getArguments()); |
|
| 41 | - $this->assertEquals([], $this->functions[5]->getArguments()); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * @covers PHP_Token_FUNCTION::getArguments |
|
| 33 | + */ |
|
| 34 | + public function testGetArguments() |
|
| 35 | + { |
|
| 36 | + $this->assertEquals(['$foo' => null, '$bar' => null], $this->functions[0]->getArguments()); |
|
| 37 | + $this->assertEquals(['$foo' => 'Foo', '$bar' => null], $this->functions[1]->getArguments()); |
|
| 38 | + $this->assertEquals(['$foo' => null, '$bar' => null, '$baz' => null], $this->functions[2]->getArguments()); |
|
| 39 | + $this->assertEquals(['$foo' => 'Foo', '$bar' => null, '$baz' => null], $this->functions[3]->getArguments()); |
|
| 40 | + $this->assertEquals([], $this->functions[4]->getArguments()); |
|
| 41 | + $this->assertEquals([], $this->functions[5]->getArguments()); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @covers PHP_Token_FUNCTION::getName |
|
| 46 | - */ |
|
| 47 | - public function testGetName() |
|
| 48 | - { |
|
| 49 | - $this->assertEquals('anonymousFunction:2#5', $this->functions[0]->getName()); |
|
| 50 | - $this->assertEquals('anonymousFunction:3#27', $this->functions[1]->getName()); |
|
| 51 | - $this->assertEquals('anonymousFunction:4#51', $this->functions[2]->getName()); |
|
| 52 | - $this->assertEquals('anonymousFunction:5#71', $this->functions[3]->getName()); |
|
| 53 | - $this->assertEquals('anonymousFunction:6#93', $this->functions[4]->getName()); |
|
| 54 | - $this->assertEquals('anonymousFunction:7#106', $this->functions[5]->getName()); |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * @covers PHP_Token_FUNCTION::getName |
|
| 46 | + */ |
|
| 47 | + public function testGetName() |
|
| 48 | + { |
|
| 49 | + $this->assertEquals('anonymousFunction:2#5', $this->functions[0]->getName()); |
|
| 50 | + $this->assertEquals('anonymousFunction:3#27', $this->functions[1]->getName()); |
|
| 51 | + $this->assertEquals('anonymousFunction:4#51', $this->functions[2]->getName()); |
|
| 52 | + $this->assertEquals('anonymousFunction:5#71', $this->functions[3]->getName()); |
|
| 53 | + $this->assertEquals('anonymousFunction:6#93', $this->functions[4]->getName()); |
|
| 54 | + $this->assertEquals('anonymousFunction:7#106', $this->functions[5]->getName()); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @covers PHP_Token::getLine |
|
| 59 | - */ |
|
| 60 | - public function testGetLine() |
|
| 61 | - { |
|
| 62 | - $this->assertEquals(2, $this->functions[0]->getLine()); |
|
| 63 | - $this->assertEquals(3, $this->functions[1]->getLine()); |
|
| 64 | - $this->assertEquals(4, $this->functions[2]->getLine()); |
|
| 65 | - $this->assertEquals(5, $this->functions[3]->getLine()); |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * @covers PHP_Token::getLine |
|
| 59 | + */ |
|
| 60 | + public function testGetLine() |
|
| 61 | + { |
|
| 62 | + $this->assertEquals(2, $this->functions[0]->getLine()); |
|
| 63 | + $this->assertEquals(3, $this->functions[1]->getLine()); |
|
| 64 | + $this->assertEquals(4, $this->functions[2]->getLine()); |
|
| 65 | + $this->assertEquals(5, $this->functions[3]->getLine()); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @covers PHP_TokenWithScope::getEndLine |
|
| 70 | - */ |
|
| 71 | - public function testGetEndLine() |
|
| 72 | - { |
|
| 73 | - $this->assertEquals(2, $this->functions[0]->getLine()); |
|
| 74 | - $this->assertEquals(3, $this->functions[1]->getLine()); |
|
| 75 | - $this->assertEquals(4, $this->functions[2]->getLine()); |
|
| 76 | - $this->assertEquals(5, $this->functions[3]->getLine()); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * @covers PHP_TokenWithScope::getEndLine |
|
| 70 | + */ |
|
| 71 | + public function testGetEndLine() |
|
| 72 | + { |
|
| 73 | + $this->assertEquals(2, $this->functions[0]->getLine()); |
|
| 74 | + $this->assertEquals(3, $this->functions[1]->getLine()); |
|
| 75 | + $this->assertEquals(4, $this->functions[2]->getLine()); |
|
| 76 | + $this->assertEquals(5, $this->functions[3]->getLine()); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | |
| 20 | 20 | protected function setUp() |
| 21 | 21 | { |
| 22 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php'); |
|
| 22 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'closure.php'); |
|
| 23 | 23 | |
| 24 | 24 | foreach ($ts as $token) { |
| 25 | 25 | if ($token instanceof PHP_Token_FUNCTION) { |
@@ -12,128 +12,128 @@ |
||
| 12 | 12 | |
| 13 | 13 | class PHP_Token_FunctionTest extends TestCase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var PHP_Token_FUNCTION[] |
|
| 17 | - */ |
|
| 18 | - private $functions; |
|
| 19 | - |
|
| 20 | - protected function setUp() |
|
| 21 | - { |
|
| 22 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php'); |
|
| 23 | - |
|
| 24 | - foreach ($ts as $token) { |
|
| 25 | - if ($token instanceof PHP_Token_FUNCTION) { |
|
| 26 | - $this->functions[] = $token; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @covers PHP_Token_FUNCTION::getArguments |
|
| 33 | - */ |
|
| 34 | - public function testGetArguments() |
|
| 35 | - { |
|
| 36 | - $this->assertEquals([], $this->functions[0]->getArguments()); |
|
| 37 | - |
|
| 38 | - $this->assertEquals( |
|
| 39 | - ['$baz' => 'Baz'], $this->functions[1]->getArguments() |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - $this->assertEquals( |
|
| 43 | - ['$foobar' => 'Foobar'], $this->functions[2]->getArguments() |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - $this->assertEquals( |
|
| 47 | - ['$barfoo' => 'Barfoo'], $this->functions[3]->getArguments() |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - $this->assertEquals([], $this->functions[4]->getArguments()); |
|
| 51 | - |
|
| 52 | - $this->assertEquals(['$x' => null, '$y' => null], $this->functions[5]->getArguments()); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @covers PHP_Token_FUNCTION::getName |
|
| 57 | - */ |
|
| 58 | - public function testGetName() |
|
| 59 | - { |
|
| 60 | - $this->assertEquals('foo', $this->functions[0]->getName()); |
|
| 61 | - $this->assertEquals('bar', $this->functions[1]->getName()); |
|
| 62 | - $this->assertEquals('foobar', $this->functions[2]->getName()); |
|
| 63 | - $this->assertEquals('barfoo', $this->functions[3]->getName()); |
|
| 64 | - $this->assertEquals('baz', $this->functions[4]->getName()); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @covers PHP_Token::getLine |
|
| 69 | - */ |
|
| 70 | - public function testGetLine() |
|
| 71 | - { |
|
| 72 | - $this->assertEquals(5, $this->functions[0]->getLine()); |
|
| 73 | - $this->assertEquals(10, $this->functions[1]->getLine()); |
|
| 74 | - $this->assertEquals(17, $this->functions[2]->getLine()); |
|
| 75 | - $this->assertEquals(21, $this->functions[3]->getLine()); |
|
| 76 | - $this->assertEquals(29, $this->functions[4]->getLine()); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @covers PHP_TokenWithScope::getEndLine |
|
| 81 | - */ |
|
| 82 | - public function testGetEndLine() |
|
| 83 | - { |
|
| 84 | - $this->assertEquals(5, $this->functions[0]->getEndLine()); |
|
| 85 | - $this->assertEquals(12, $this->functions[1]->getEndLine()); |
|
| 86 | - $this->assertEquals(19, $this->functions[2]->getEndLine()); |
|
| 87 | - $this->assertEquals(23, $this->functions[3]->getEndLine()); |
|
| 88 | - $this->assertEquals(31, $this->functions[4]->getEndLine()); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @covers PHP_Token_FUNCTION::getDocblock |
|
| 93 | - */ |
|
| 94 | - public function testGetDocblock() |
|
| 95 | - { |
|
| 96 | - $this->assertNull($this->functions[0]->getDocblock()); |
|
| 97 | - |
|
| 98 | - $this->assertEquals( |
|
| 99 | - "/**\n * @param Baz \$baz\n */", |
|
| 100 | - $this->functions[1]->getDocblock() |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - $this->assertEquals( |
|
| 104 | - "/**\n * @param Foobar \$foobar\n */", |
|
| 105 | - $this->functions[2]->getDocblock() |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - $this->assertNull($this->functions[3]->getDocblock()); |
|
| 109 | - $this->assertNull($this->functions[4]->getDocblock()); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function testSignature() |
|
| 113 | - { |
|
| 114 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source5.php'); |
|
| 115 | - $f = $ts->getFunctions(); |
|
| 116 | - $c = $ts->getClasses(); |
|
| 117 | - $i = $ts->getInterfaces(); |
|
| 118 | - |
|
| 119 | - $this->assertEquals( |
|
| 120 | - 'foo($a, array $b, array $c = array())', |
|
| 121 | - $f['foo']['signature'] |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $this->assertEquals( |
|
| 125 | - 'm($a, array $b, array $c = array())', |
|
| 126 | - $c['c']['methods']['m']['signature'] |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - $this->assertEquals( |
|
| 130 | - 'm($a, array $b, array $c = array())', |
|
| 131 | - $c['a']['methods']['m']['signature'] |
|
| 132 | - ); |
|
| 133 | - |
|
| 134 | - $this->assertEquals( |
|
| 135 | - 'm($a, array $b, array $c = array())', |
|
| 136 | - $i['i']['methods']['m']['signature'] |
|
| 137 | - ); |
|
| 138 | - } |
|
| 15 | + /** |
|
| 16 | + * @var PHP_Token_FUNCTION[] |
|
| 17 | + */ |
|
| 18 | + private $functions; |
|
| 19 | + |
|
| 20 | + protected function setUp() |
|
| 21 | + { |
|
| 22 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php'); |
|
| 23 | + |
|
| 24 | + foreach ($ts as $token) { |
|
| 25 | + if ($token instanceof PHP_Token_FUNCTION) { |
|
| 26 | + $this->functions[] = $token; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @covers PHP_Token_FUNCTION::getArguments |
|
| 33 | + */ |
|
| 34 | + public function testGetArguments() |
|
| 35 | + { |
|
| 36 | + $this->assertEquals([], $this->functions[0]->getArguments()); |
|
| 37 | + |
|
| 38 | + $this->assertEquals( |
|
| 39 | + ['$baz' => 'Baz'], $this->functions[1]->getArguments() |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + $this->assertEquals( |
|
| 43 | + ['$foobar' => 'Foobar'], $this->functions[2]->getArguments() |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + $this->assertEquals( |
|
| 47 | + ['$barfoo' => 'Barfoo'], $this->functions[3]->getArguments() |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + $this->assertEquals([], $this->functions[4]->getArguments()); |
|
| 51 | + |
|
| 52 | + $this->assertEquals(['$x' => null, '$y' => null], $this->functions[5]->getArguments()); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @covers PHP_Token_FUNCTION::getName |
|
| 57 | + */ |
|
| 58 | + public function testGetName() |
|
| 59 | + { |
|
| 60 | + $this->assertEquals('foo', $this->functions[0]->getName()); |
|
| 61 | + $this->assertEquals('bar', $this->functions[1]->getName()); |
|
| 62 | + $this->assertEquals('foobar', $this->functions[2]->getName()); |
|
| 63 | + $this->assertEquals('barfoo', $this->functions[3]->getName()); |
|
| 64 | + $this->assertEquals('baz', $this->functions[4]->getName()); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @covers PHP_Token::getLine |
|
| 69 | + */ |
|
| 70 | + public function testGetLine() |
|
| 71 | + { |
|
| 72 | + $this->assertEquals(5, $this->functions[0]->getLine()); |
|
| 73 | + $this->assertEquals(10, $this->functions[1]->getLine()); |
|
| 74 | + $this->assertEquals(17, $this->functions[2]->getLine()); |
|
| 75 | + $this->assertEquals(21, $this->functions[3]->getLine()); |
|
| 76 | + $this->assertEquals(29, $this->functions[4]->getLine()); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @covers PHP_TokenWithScope::getEndLine |
|
| 81 | + */ |
|
| 82 | + public function testGetEndLine() |
|
| 83 | + { |
|
| 84 | + $this->assertEquals(5, $this->functions[0]->getEndLine()); |
|
| 85 | + $this->assertEquals(12, $this->functions[1]->getEndLine()); |
|
| 86 | + $this->assertEquals(19, $this->functions[2]->getEndLine()); |
|
| 87 | + $this->assertEquals(23, $this->functions[3]->getEndLine()); |
|
| 88 | + $this->assertEquals(31, $this->functions[4]->getEndLine()); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @covers PHP_Token_FUNCTION::getDocblock |
|
| 93 | + */ |
|
| 94 | + public function testGetDocblock() |
|
| 95 | + { |
|
| 96 | + $this->assertNull($this->functions[0]->getDocblock()); |
|
| 97 | + |
|
| 98 | + $this->assertEquals( |
|
| 99 | + "/**\n * @param Baz \$baz\n */", |
|
| 100 | + $this->functions[1]->getDocblock() |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + $this->assertEquals( |
|
| 104 | + "/**\n * @param Foobar \$foobar\n */", |
|
| 105 | + $this->functions[2]->getDocblock() |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + $this->assertNull($this->functions[3]->getDocblock()); |
|
| 109 | + $this->assertNull($this->functions[4]->getDocblock()); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function testSignature() |
|
| 113 | + { |
|
| 114 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source5.php'); |
|
| 115 | + $f = $ts->getFunctions(); |
|
| 116 | + $c = $ts->getClasses(); |
|
| 117 | + $i = $ts->getInterfaces(); |
|
| 118 | + |
|
| 119 | + $this->assertEquals( |
|
| 120 | + 'foo($a, array $b, array $c = array())', |
|
| 121 | + $f['foo']['signature'] |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $this->assertEquals( |
|
| 125 | + 'm($a, array $b, array $c = array())', |
|
| 126 | + $c['c']['methods']['m']['signature'] |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + $this->assertEquals( |
|
| 130 | + 'm($a, array $b, array $c = array())', |
|
| 131 | + $c['a']['methods']['m']['signature'] |
|
| 132 | + ); |
|
| 133 | + |
|
| 134 | + $this->assertEquals( |
|
| 135 | + 'm($a, array $b, array $c = array())', |
|
| 136 | + $i['i']['methods']['m']['signature'] |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | protected function setUp() |
| 21 | 21 | { |
| 22 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source.php'); |
|
| 22 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'source.php'); |
|
| 23 | 23 | |
| 24 | 24 | foreach ($ts as $token) { |
| 25 | 25 | if ($token instanceof PHP_Token_FUNCTION) { |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | public function testSignature() |
| 113 | 113 | { |
| 114 | - $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'source5.php'); |
|
| 114 | + $ts = new PHP_Token_Stream(TEST_FILES_PATH.'source5.php'); |
|
| 115 | 115 | $f = $ts->getFunctions(); |
| 116 | 116 | $c = $ts->getClasses(); |
| 117 | 117 | $i = $ts->getInterfaces(); |
@@ -13,609 +13,609 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class PHP_Token |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $text; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var int |
|
| 23 | - */ |
|
| 24 | - protected $line; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var PHP_Token_Stream |
|
| 28 | - */ |
|
| 29 | - protected $tokenStream; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - protected $id; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param string $text |
|
| 38 | - * @param int $line |
|
| 39 | - * @param PHP_Token_Stream $tokenStream |
|
| 40 | - * @param int $id |
|
| 41 | - */ |
|
| 42 | - public function __construct($text, $line, PHP_Token_Stream $tokenStream, $id) |
|
| 43 | - { |
|
| 44 | - $this->text = $text; |
|
| 45 | - $this->line = $line; |
|
| 46 | - $this->tokenStream = $tokenStream; |
|
| 47 | - $this->id = $id; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function __toString() |
|
| 54 | - { |
|
| 55 | - return $this->text; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return int |
|
| 60 | - */ |
|
| 61 | - public function getLine() |
|
| 62 | - { |
|
| 63 | - return $this->line; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return int |
|
| 68 | - */ |
|
| 69 | - public function getId() |
|
| 70 | - { |
|
| 71 | - return $this->id; |
|
| 72 | - } |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $text; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var int |
|
| 23 | + */ |
|
| 24 | + protected $line; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var PHP_Token_Stream |
|
| 28 | + */ |
|
| 29 | + protected $tokenStream; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + protected $id; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param string $text |
|
| 38 | + * @param int $line |
|
| 39 | + * @param PHP_Token_Stream $tokenStream |
|
| 40 | + * @param int $id |
|
| 41 | + */ |
|
| 42 | + public function __construct($text, $line, PHP_Token_Stream $tokenStream, $id) |
|
| 43 | + { |
|
| 44 | + $this->text = $text; |
|
| 45 | + $this->line = $line; |
|
| 46 | + $this->tokenStream = $tokenStream; |
|
| 47 | + $this->id = $id; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function __toString() |
|
| 54 | + { |
|
| 55 | + return $this->text; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return int |
|
| 60 | + */ |
|
| 61 | + public function getLine() |
|
| 62 | + { |
|
| 63 | + return $this->line; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + public function getId() |
|
| 70 | + { |
|
| 71 | + return $this->id; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | abstract class PHP_TokenWithScope extends PHP_Token |
| 76 | 76 | { |
| 77 | - /** |
|
| 78 | - * @var int |
|
| 79 | - */ |
|
| 80 | - protected $endTokenId; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Get the docblock for this token |
|
| 84 | - * |
|
| 85 | - * This method will fetch the docblock belonging to the current token. The |
|
| 86 | - * docblock must be placed on the line directly above the token to be |
|
| 87 | - * recognized. |
|
| 88 | - * |
|
| 89 | - * @return string|null Returns the docblock as a string if found |
|
| 90 | - */ |
|
| 91 | - public function getDocblock() |
|
| 92 | - { |
|
| 93 | - $tokens = $this->tokenStream->tokens(); |
|
| 94 | - $currentLineNumber = $tokens[$this->id]->getLine(); |
|
| 95 | - $prevLineNumber = $currentLineNumber - 1; |
|
| 96 | - |
|
| 97 | - for ($i = $this->id - 1; $i; $i--) { |
|
| 98 | - if (!isset($tokens[$i])) { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($tokens[$i] instanceof PHP_Token_FUNCTION || |
|
| 103 | - $tokens[$i] instanceof PHP_Token_CLASS || |
|
| 104 | - $tokens[$i] instanceof PHP_Token_TRAIT) { |
|
| 105 | - // Some other trait, class or function, no docblock can be |
|
| 106 | - // used for the current token |
|
| 107 | - break; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $line = $tokens[$i]->getLine(); |
|
| 111 | - |
|
| 112 | - if ($line == $currentLineNumber || |
|
| 113 | - ($line == $prevLineNumber && |
|
| 114 | - $tokens[$i] instanceof PHP_Token_WHITESPACE)) { |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - if ($line < $currentLineNumber && |
|
| 119 | - !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) { |
|
| 120 | - break; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return (string) $tokens[$i]; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return int |
|
| 129 | - */ |
|
| 130 | - public function getEndTokenId() |
|
| 131 | - { |
|
| 132 | - $block = 0; |
|
| 133 | - $i = $this->id; |
|
| 134 | - $tokens = $this->tokenStream->tokens(); |
|
| 135 | - |
|
| 136 | - while ($this->endTokenId === null && isset($tokens[$i])) { |
|
| 137 | - if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY || |
|
| 138 | - $tokens[$i] instanceof PHP_Token_CURLY_OPEN) { |
|
| 139 | - $block++; |
|
| 140 | - } elseif ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) { |
|
| 141 | - $block--; |
|
| 142 | - |
|
| 143 | - if ($block === 0) { |
|
| 144 | - $this->endTokenId = $i; |
|
| 145 | - } |
|
| 146 | - } elseif (($this instanceof PHP_Token_FUNCTION || |
|
| 147 | - $this instanceof PHP_Token_NAMESPACE) && |
|
| 148 | - $tokens[$i] instanceof PHP_Token_SEMICOLON) { |
|
| 149 | - if ($block === 0) { |
|
| 150 | - $this->endTokenId = $i; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $i++; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if ($this->endTokenId === null) { |
|
| 158 | - $this->endTokenId = $this->id; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $this->endTokenId; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @return int |
|
| 166 | - */ |
|
| 167 | - public function getEndLine() |
|
| 168 | - { |
|
| 169 | - return $this->tokenStream[$this->getEndTokenId()]->getLine(); |
|
| 170 | - } |
|
| 77 | + /** |
|
| 78 | + * @var int |
|
| 79 | + */ |
|
| 80 | + protected $endTokenId; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Get the docblock for this token |
|
| 84 | + * |
|
| 85 | + * This method will fetch the docblock belonging to the current token. The |
|
| 86 | + * docblock must be placed on the line directly above the token to be |
|
| 87 | + * recognized. |
|
| 88 | + * |
|
| 89 | + * @return string|null Returns the docblock as a string if found |
|
| 90 | + */ |
|
| 91 | + public function getDocblock() |
|
| 92 | + { |
|
| 93 | + $tokens = $this->tokenStream->tokens(); |
|
| 94 | + $currentLineNumber = $tokens[$this->id]->getLine(); |
|
| 95 | + $prevLineNumber = $currentLineNumber - 1; |
|
| 96 | + |
|
| 97 | + for ($i = $this->id - 1; $i; $i--) { |
|
| 98 | + if (!isset($tokens[$i])) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($tokens[$i] instanceof PHP_Token_FUNCTION || |
|
| 103 | + $tokens[$i] instanceof PHP_Token_CLASS || |
|
| 104 | + $tokens[$i] instanceof PHP_Token_TRAIT) { |
|
| 105 | + // Some other trait, class or function, no docblock can be |
|
| 106 | + // used for the current token |
|
| 107 | + break; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $line = $tokens[$i]->getLine(); |
|
| 111 | + |
|
| 112 | + if ($line == $currentLineNumber || |
|
| 113 | + ($line == $prevLineNumber && |
|
| 114 | + $tokens[$i] instanceof PHP_Token_WHITESPACE)) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + if ($line < $currentLineNumber && |
|
| 119 | + !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) { |
|
| 120 | + break; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return (string) $tokens[$i]; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return int |
|
| 129 | + */ |
|
| 130 | + public function getEndTokenId() |
|
| 131 | + { |
|
| 132 | + $block = 0; |
|
| 133 | + $i = $this->id; |
|
| 134 | + $tokens = $this->tokenStream->tokens(); |
|
| 135 | + |
|
| 136 | + while ($this->endTokenId === null && isset($tokens[$i])) { |
|
| 137 | + if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY || |
|
| 138 | + $tokens[$i] instanceof PHP_Token_CURLY_OPEN) { |
|
| 139 | + $block++; |
|
| 140 | + } elseif ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) { |
|
| 141 | + $block--; |
|
| 142 | + |
|
| 143 | + if ($block === 0) { |
|
| 144 | + $this->endTokenId = $i; |
|
| 145 | + } |
|
| 146 | + } elseif (($this instanceof PHP_Token_FUNCTION || |
|
| 147 | + $this instanceof PHP_Token_NAMESPACE) && |
|
| 148 | + $tokens[$i] instanceof PHP_Token_SEMICOLON) { |
|
| 149 | + if ($block === 0) { |
|
| 150 | + $this->endTokenId = $i; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $i++; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if ($this->endTokenId === null) { |
|
| 158 | + $this->endTokenId = $this->id; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $this->endTokenId; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @return int |
|
| 166 | + */ |
|
| 167 | + public function getEndLine() |
|
| 168 | + { |
|
| 169 | + return $this->tokenStream[$this->getEndTokenId()]->getLine(); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | abstract class PHP_TokenWithScopeAndVisibility extends PHP_TokenWithScope |
| 174 | 174 | { |
| 175 | - /** |
|
| 176 | - * @return string |
|
| 177 | - */ |
|
| 178 | - public function getVisibility() |
|
| 179 | - { |
|
| 180 | - $tokens = $this->tokenStream->tokens(); |
|
| 181 | - |
|
| 182 | - for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { |
|
| 183 | - if (isset($tokens[$i]) && |
|
| 184 | - ($tokens[$i] instanceof PHP_Token_PRIVATE || |
|
| 185 | - $tokens[$i] instanceof PHP_Token_PROTECTED || |
|
| 186 | - $tokens[$i] instanceof PHP_Token_PUBLIC)) { |
|
| 187 | - return strtolower( |
|
| 188 | - str_replace('PHP_Token_', '', get_class($tokens[$i])) |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - if (isset($tokens[$i]) && |
|
| 192 | - !($tokens[$i] instanceof PHP_Token_STATIC || |
|
| 193 | - $tokens[$i] instanceof PHP_Token_FINAL || |
|
| 194 | - $tokens[$i] instanceof PHP_Token_ABSTRACT)) { |
|
| 195 | - // no keywords; stop visibility search |
|
| 196 | - break; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @return string |
|
| 203 | - */ |
|
| 204 | - public function getKeywords() |
|
| 205 | - { |
|
| 206 | - $keywords = []; |
|
| 207 | - $tokens = $this->tokenStream->tokens(); |
|
| 208 | - |
|
| 209 | - for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { |
|
| 210 | - if (isset($tokens[$i]) && |
|
| 211 | - ($tokens[$i] instanceof PHP_Token_PRIVATE || |
|
| 212 | - $tokens[$i] instanceof PHP_Token_PROTECTED || |
|
| 213 | - $tokens[$i] instanceof PHP_Token_PUBLIC)) { |
|
| 214 | - continue; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - if (isset($tokens[$i]) && |
|
| 218 | - ($tokens[$i] instanceof PHP_Token_STATIC || |
|
| 219 | - $tokens[$i] instanceof PHP_Token_FINAL || |
|
| 220 | - $tokens[$i] instanceof PHP_Token_ABSTRACT)) { |
|
| 221 | - $keywords[] = strtolower( |
|
| 222 | - str_replace('PHP_Token_', '', get_class($tokens[$i])) |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return implode(',', $keywords); |
|
| 228 | - } |
|
| 175 | + /** |
|
| 176 | + * @return string |
|
| 177 | + */ |
|
| 178 | + public function getVisibility() |
|
| 179 | + { |
|
| 180 | + $tokens = $this->tokenStream->tokens(); |
|
| 181 | + |
|
| 182 | + for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { |
|
| 183 | + if (isset($tokens[$i]) && |
|
| 184 | + ($tokens[$i] instanceof PHP_Token_PRIVATE || |
|
| 185 | + $tokens[$i] instanceof PHP_Token_PROTECTED || |
|
| 186 | + $tokens[$i] instanceof PHP_Token_PUBLIC)) { |
|
| 187 | + return strtolower( |
|
| 188 | + str_replace('PHP_Token_', '', get_class($tokens[$i])) |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + if (isset($tokens[$i]) && |
|
| 192 | + !($tokens[$i] instanceof PHP_Token_STATIC || |
|
| 193 | + $tokens[$i] instanceof PHP_Token_FINAL || |
|
| 194 | + $tokens[$i] instanceof PHP_Token_ABSTRACT)) { |
|
| 195 | + // no keywords; stop visibility search |
|
| 196 | + break; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @return string |
|
| 203 | + */ |
|
| 204 | + public function getKeywords() |
|
| 205 | + { |
|
| 206 | + $keywords = []; |
|
| 207 | + $tokens = $this->tokenStream->tokens(); |
|
| 208 | + |
|
| 209 | + for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { |
|
| 210 | + if (isset($tokens[$i]) && |
|
| 211 | + ($tokens[$i] instanceof PHP_Token_PRIVATE || |
|
| 212 | + $tokens[$i] instanceof PHP_Token_PROTECTED || |
|
| 213 | + $tokens[$i] instanceof PHP_Token_PUBLIC)) { |
|
| 214 | + continue; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + if (isset($tokens[$i]) && |
|
| 218 | + ($tokens[$i] instanceof PHP_Token_STATIC || |
|
| 219 | + $tokens[$i] instanceof PHP_Token_FINAL || |
|
| 220 | + $tokens[$i] instanceof PHP_Token_ABSTRACT)) { |
|
| 221 | + $keywords[] = strtolower( |
|
| 222 | + str_replace('PHP_Token_', '', get_class($tokens[$i])) |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return implode(',', $keywords); |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | abstract class PHP_Token_Includes extends PHP_Token |
| 232 | 232 | { |
| 233 | - /** |
|
| 234 | - * @var string |
|
| 235 | - */ |
|
| 236 | - protected $name; |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @var string |
|
| 240 | - */ |
|
| 241 | - protected $type; |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function getName() |
|
| 247 | - { |
|
| 248 | - if ($this->name === null) { |
|
| 249 | - $this->process(); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $this->name; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function getType() |
|
| 259 | - { |
|
| 260 | - if ($this->type === null) { |
|
| 261 | - $this->process(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $this->type; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - private function process() |
|
| 268 | - { |
|
| 269 | - $tokens = $this->tokenStream->tokens(); |
|
| 270 | - |
|
| 271 | - if ($tokens[$this->id + 2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) { |
|
| 272 | - $this->name = trim($tokens[$this->id + 2], "'\""); |
|
| 273 | - $this->type = strtolower( |
|
| 274 | - str_replace('PHP_Token_', '', get_class($tokens[$this->id])) |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - } |
|
| 233 | + /** |
|
| 234 | + * @var string |
|
| 235 | + */ |
|
| 236 | + protected $name; |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @var string |
|
| 240 | + */ |
|
| 241 | + protected $type; |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function getName() |
|
| 247 | + { |
|
| 248 | + if ($this->name === null) { |
|
| 249 | + $this->process(); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $this->name; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function getType() |
|
| 259 | + { |
|
| 260 | + if ($this->type === null) { |
|
| 261 | + $this->process(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $this->type; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + private function process() |
|
| 268 | + { |
|
| 269 | + $tokens = $this->tokenStream->tokens(); |
|
| 270 | + |
|
| 271 | + if ($tokens[$this->id + 2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) { |
|
| 272 | + $this->name = trim($tokens[$this->id + 2], "'\""); |
|
| 273 | + $this->type = strtolower( |
|
| 274 | + str_replace('PHP_Token_', '', get_class($tokens[$this->id])) |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility |
| 281 | 281 | { |
| 282 | - /** |
|
| 283 | - * @var array |
|
| 284 | - */ |
|
| 285 | - protected $arguments; |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @var int |
|
| 289 | - */ |
|
| 290 | - protected $ccn; |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @var string |
|
| 294 | - */ |
|
| 295 | - protected $name; |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @var string |
|
| 299 | - */ |
|
| 300 | - protected $signature; |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @var bool |
|
| 304 | - */ |
|
| 305 | - private $anonymous = false; |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @return array |
|
| 309 | - */ |
|
| 310 | - public function getArguments() |
|
| 311 | - { |
|
| 312 | - if ($this->arguments !== null) { |
|
| 313 | - return $this->arguments; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $this->arguments = []; |
|
| 317 | - $tokens = $this->tokenStream->tokens(); |
|
| 318 | - $typeDeclaration = null; |
|
| 319 | - |
|
| 320 | - // Search for first token inside brackets |
|
| 321 | - $i = $this->id + 2; |
|
| 322 | - |
|
| 323 | - while (!$tokens[$i - 1] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 324 | - $i++; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) { |
|
| 328 | - if ($tokens[$i] instanceof PHP_Token_STRING) { |
|
| 329 | - $typeDeclaration = (string) $tokens[$i]; |
|
| 330 | - } elseif ($tokens[$i] instanceof PHP_Token_VARIABLE) { |
|
| 331 | - $this->arguments[(string) $tokens[$i]] = $typeDeclaration; |
|
| 332 | - $typeDeclaration = null; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - $i++; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - return $this->arguments; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @return string |
|
| 343 | - */ |
|
| 344 | - public function getName() |
|
| 345 | - { |
|
| 346 | - if ($this->name !== null) { |
|
| 347 | - return $this->name; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - $tokens = $this->tokenStream->tokens(); |
|
| 351 | - |
|
| 352 | - $i = $this->id + 1; |
|
| 353 | - |
|
| 354 | - if ($tokens[$i] instanceof PHP_Token_WHITESPACE) { |
|
| 355 | - $i++; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if ($tokens[$i] instanceof PHP_Token_AMPERSAND) { |
|
| 359 | - $i++; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if ($tokens[$i + 1] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 363 | - $this->name = (string) $tokens[$i]; |
|
| 364 | - } elseif ($tokens[$i + 1] instanceof PHP_Token_WHITESPACE && $tokens[$i + 2] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 365 | - $this->name = (string) $tokens[$i]; |
|
| 366 | - } else { |
|
| 367 | - $this->anonymous = true; |
|
| 368 | - |
|
| 369 | - $this->name = sprintf( |
|
| 370 | - 'anonymousFunction:%s#%s', |
|
| 371 | - $this->getLine(), |
|
| 372 | - $this->getId() |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if (!$this->isAnonymous()) { |
|
| 377 | - for ($i = $this->id; $i; --$i) { |
|
| 378 | - if ($tokens[$i] instanceof PHP_Token_NAMESPACE) { |
|
| 379 | - $this->name = $tokens[$i]->getName() . '\\' . $this->name; |
|
| 380 | - |
|
| 381 | - break; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ($tokens[$i] instanceof PHP_Token_INTERFACE) { |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - return $this->name; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 396 | - public function getCCN() |
|
| 397 | - { |
|
| 398 | - if ($this->ccn !== null) { |
|
| 399 | - return $this->ccn; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - $this->ccn = 1; |
|
| 403 | - $end = $this->getEndTokenId(); |
|
| 404 | - $tokens = $this->tokenStream->tokens(); |
|
| 405 | - |
|
| 406 | - for ($i = $this->id; $i <= $end; $i++) { |
|
| 407 | - switch (get_class($tokens[$i])) { |
|
| 408 | - case 'PHP_Token_IF': |
|
| 409 | - case 'PHP_Token_ELSEIF': |
|
| 410 | - case 'PHP_Token_FOR': |
|
| 411 | - case 'PHP_Token_FOREACH': |
|
| 412 | - case 'PHP_Token_WHILE': |
|
| 413 | - case 'PHP_Token_CASE': |
|
| 414 | - case 'PHP_Token_CATCH': |
|
| 415 | - case 'PHP_Token_BOOLEAN_AND': |
|
| 416 | - case 'PHP_Token_LOGICAL_AND': |
|
| 417 | - case 'PHP_Token_BOOLEAN_OR': |
|
| 418 | - case 'PHP_Token_LOGICAL_OR': |
|
| 419 | - case 'PHP_Token_QUESTION_MARK': |
|
| 420 | - $this->ccn++; |
|
| 421 | - break; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return $this->ccn; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @return string |
|
| 430 | - */ |
|
| 431 | - public function getSignature() |
|
| 432 | - { |
|
| 433 | - if ($this->signature !== null) { |
|
| 434 | - return $this->signature; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($this->isAnonymous()) { |
|
| 438 | - $this->signature = 'anonymousFunction'; |
|
| 439 | - $i = $this->id + 1; |
|
| 440 | - } else { |
|
| 441 | - $this->signature = ''; |
|
| 442 | - $i = $this->id + 2; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - $tokens = $this->tokenStream->tokens(); |
|
| 446 | - |
|
| 447 | - while (isset($tokens[$i]) && |
|
| 448 | - !$tokens[$i] instanceof PHP_Token_OPEN_CURLY && |
|
| 449 | - !$tokens[$i] instanceof PHP_Token_SEMICOLON) { |
|
| 450 | - $this->signature .= $tokens[$i++]; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - $this->signature = trim($this->signature); |
|
| 454 | - |
|
| 455 | - return $this->signature; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @return bool |
|
| 460 | - */ |
|
| 461 | - public function isAnonymous() |
|
| 462 | - { |
|
| 463 | - return $this->anonymous; |
|
| 464 | - } |
|
| 282 | + /** |
|
| 283 | + * @var array |
|
| 284 | + */ |
|
| 285 | + protected $arguments; |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @var int |
|
| 289 | + */ |
|
| 290 | + protected $ccn; |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @var string |
|
| 294 | + */ |
|
| 295 | + protected $name; |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @var string |
|
| 299 | + */ |
|
| 300 | + protected $signature; |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @var bool |
|
| 304 | + */ |
|
| 305 | + private $anonymous = false; |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @return array |
|
| 309 | + */ |
|
| 310 | + public function getArguments() |
|
| 311 | + { |
|
| 312 | + if ($this->arguments !== null) { |
|
| 313 | + return $this->arguments; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $this->arguments = []; |
|
| 317 | + $tokens = $this->tokenStream->tokens(); |
|
| 318 | + $typeDeclaration = null; |
|
| 319 | + |
|
| 320 | + // Search for first token inside brackets |
|
| 321 | + $i = $this->id + 2; |
|
| 322 | + |
|
| 323 | + while (!$tokens[$i - 1] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 324 | + $i++; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) { |
|
| 328 | + if ($tokens[$i] instanceof PHP_Token_STRING) { |
|
| 329 | + $typeDeclaration = (string) $tokens[$i]; |
|
| 330 | + } elseif ($tokens[$i] instanceof PHP_Token_VARIABLE) { |
|
| 331 | + $this->arguments[(string) $tokens[$i]] = $typeDeclaration; |
|
| 332 | + $typeDeclaration = null; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + $i++; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + return $this->arguments; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @return string |
|
| 343 | + */ |
|
| 344 | + public function getName() |
|
| 345 | + { |
|
| 346 | + if ($this->name !== null) { |
|
| 347 | + return $this->name; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + $tokens = $this->tokenStream->tokens(); |
|
| 351 | + |
|
| 352 | + $i = $this->id + 1; |
|
| 353 | + |
|
| 354 | + if ($tokens[$i] instanceof PHP_Token_WHITESPACE) { |
|
| 355 | + $i++; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if ($tokens[$i] instanceof PHP_Token_AMPERSAND) { |
|
| 359 | + $i++; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if ($tokens[$i + 1] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 363 | + $this->name = (string) $tokens[$i]; |
|
| 364 | + } elseif ($tokens[$i + 1] instanceof PHP_Token_WHITESPACE && $tokens[$i + 2] instanceof PHP_Token_OPEN_BRACKET) { |
|
| 365 | + $this->name = (string) $tokens[$i]; |
|
| 366 | + } else { |
|
| 367 | + $this->anonymous = true; |
|
| 368 | + |
|
| 369 | + $this->name = sprintf( |
|
| 370 | + 'anonymousFunction:%s#%s', |
|
| 371 | + $this->getLine(), |
|
| 372 | + $this->getId() |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if (!$this->isAnonymous()) { |
|
| 377 | + for ($i = $this->id; $i; --$i) { |
|
| 378 | + if ($tokens[$i] instanceof PHP_Token_NAMESPACE) { |
|
| 379 | + $this->name = $tokens[$i]->getName() . '\\' . $this->name; |
|
| 380 | + |
|
| 381 | + break; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ($tokens[$i] instanceof PHP_Token_INTERFACE) { |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + return $this->name; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | + public function getCCN() |
|
| 397 | + { |
|
| 398 | + if ($this->ccn !== null) { |
|
| 399 | + return $this->ccn; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + $this->ccn = 1; |
|
| 403 | + $end = $this->getEndTokenId(); |
|
| 404 | + $tokens = $this->tokenStream->tokens(); |
|
| 405 | + |
|
| 406 | + for ($i = $this->id; $i <= $end; $i++) { |
|
| 407 | + switch (get_class($tokens[$i])) { |
|
| 408 | + case 'PHP_Token_IF': |
|
| 409 | + case 'PHP_Token_ELSEIF': |
|
| 410 | + case 'PHP_Token_FOR': |
|
| 411 | + case 'PHP_Token_FOREACH': |
|
| 412 | + case 'PHP_Token_WHILE': |
|
| 413 | + case 'PHP_Token_CASE': |
|
| 414 | + case 'PHP_Token_CATCH': |
|
| 415 | + case 'PHP_Token_BOOLEAN_AND': |
|
| 416 | + case 'PHP_Token_LOGICAL_AND': |
|
| 417 | + case 'PHP_Token_BOOLEAN_OR': |
|
| 418 | + case 'PHP_Token_LOGICAL_OR': |
|
| 419 | + case 'PHP_Token_QUESTION_MARK': |
|
| 420 | + $this->ccn++; |
|
| 421 | + break; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return $this->ccn; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @return string |
|
| 430 | + */ |
|
| 431 | + public function getSignature() |
|
| 432 | + { |
|
| 433 | + if ($this->signature !== null) { |
|
| 434 | + return $this->signature; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($this->isAnonymous()) { |
|
| 438 | + $this->signature = 'anonymousFunction'; |
|
| 439 | + $i = $this->id + 1; |
|
| 440 | + } else { |
|
| 441 | + $this->signature = ''; |
|
| 442 | + $i = $this->id + 2; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + $tokens = $this->tokenStream->tokens(); |
|
| 446 | + |
|
| 447 | + while (isset($tokens[$i]) && |
|
| 448 | + !$tokens[$i] instanceof PHP_Token_OPEN_CURLY && |
|
| 449 | + !$tokens[$i] instanceof PHP_Token_SEMICOLON) { |
|
| 450 | + $this->signature .= $tokens[$i++]; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + $this->signature = trim($this->signature); |
|
| 454 | + |
|
| 455 | + return $this->signature; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @return bool |
|
| 460 | + */ |
|
| 461 | + public function isAnonymous() |
|
| 462 | + { |
|
| 463 | + return $this->anonymous; |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility |
| 468 | 468 | { |
| 469 | - /** |
|
| 470 | - * @var array |
|
| 471 | - */ |
|
| 472 | - protected $interfaces; |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * @return string |
|
| 476 | - */ |
|
| 477 | - public function getName() |
|
| 478 | - { |
|
| 479 | - return (string) $this->tokenStream[$this->id + 2]; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @return bool |
|
| 484 | - */ |
|
| 485 | - public function hasParent() |
|
| 486 | - { |
|
| 487 | - return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @return array |
|
| 492 | - */ |
|
| 493 | - public function getPackage() |
|
| 494 | - { |
|
| 495 | - $className = $this->getName(); |
|
| 496 | - $docComment = $this->getDocblock(); |
|
| 497 | - |
|
| 498 | - $result = [ |
|
| 499 | - 'namespace' => '', |
|
| 500 | - 'fullPackage' => '', |
|
| 501 | - 'category' => '', |
|
| 502 | - 'package' => '', |
|
| 503 | - 'subpackage' => '' |
|
| 504 | - ]; |
|
| 505 | - |
|
| 506 | - for ($i = $this->id; $i; --$i) { |
|
| 507 | - if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) { |
|
| 508 | - $result['namespace'] = $this->tokenStream[$i]->getName(); |
|
| 509 | - break; |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 514 | - $result['category'] = $matches[1]; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 518 | - $result['package'] = $matches[1]; |
|
| 519 | - $result['fullPackage'] = $matches[1]; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 523 | - $result['subpackage'] = $matches[1]; |
|
| 524 | - $result['fullPackage'] .= '.' . $matches[1]; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - if (empty($result['fullPackage'])) { |
|
| 528 | - $result['fullPackage'] = $this->arrayToName( |
|
| 529 | - explode('_', str_replace('\\', '_', $className)), |
|
| 530 | - '.' |
|
| 531 | - ); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - return $result; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * @param array $parts |
|
| 539 | - * @param string $join |
|
| 540 | - * |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - protected function arrayToName(array $parts, $join = '\\') |
|
| 544 | - { |
|
| 545 | - $result = ''; |
|
| 546 | - |
|
| 547 | - if (count($parts) > 1) { |
|
| 548 | - array_pop($parts); |
|
| 549 | - |
|
| 550 | - $result = implode($join, $parts); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - return $result; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @return bool|string |
|
| 558 | - */ |
|
| 559 | - public function getParent() |
|
| 560 | - { |
|
| 561 | - if (!$this->hasParent()) { |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - $i = $this->id + 6; |
|
| 566 | - $tokens = $this->tokenStream->tokens(); |
|
| 567 | - $className = (string) $tokens[$i]; |
|
| 568 | - |
|
| 569 | - while (isset($tokens[$i + 1]) && |
|
| 570 | - !$tokens[$i + 1] instanceof PHP_Token_WHITESPACE) { |
|
| 571 | - $className .= (string) $tokens[++$i]; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - return $className; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @return bool |
|
| 579 | - */ |
|
| 580 | - public function hasInterfaces() |
|
| 581 | - { |
|
| 582 | - return (isset($this->tokenStream[$this->id + 4]) && |
|
| 583 | - $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) || |
|
| 584 | - (isset($this->tokenStream[$this->id + 8]) && |
|
| 585 | - $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @return array|bool |
|
| 590 | - */ |
|
| 591 | - public function getInterfaces() |
|
| 592 | - { |
|
| 593 | - if ($this->interfaces !== null) { |
|
| 594 | - return $this->interfaces; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if (!$this->hasInterfaces()) { |
|
| 598 | - return ($this->interfaces = false); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) { |
|
| 602 | - $i = $this->id + 3; |
|
| 603 | - } else { |
|
| 604 | - $i = $this->id + 7; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $tokens = $this->tokenStream->tokens(); |
|
| 608 | - |
|
| 609 | - while (!$tokens[$i + 1] instanceof PHP_Token_OPEN_CURLY) { |
|
| 610 | - $i++; |
|
| 611 | - |
|
| 612 | - if ($tokens[$i] instanceof PHP_Token_STRING) { |
|
| 613 | - $this->interfaces[] = (string) $tokens[$i]; |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $this->interfaces; |
|
| 618 | - } |
|
| 469 | + /** |
|
| 470 | + * @var array |
|
| 471 | + */ |
|
| 472 | + protected $interfaces; |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @return string |
|
| 476 | + */ |
|
| 477 | + public function getName() |
|
| 478 | + { |
|
| 479 | + return (string) $this->tokenStream[$this->id + 2]; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @return bool |
|
| 484 | + */ |
|
| 485 | + public function hasParent() |
|
| 486 | + { |
|
| 487 | + return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @return array |
|
| 492 | + */ |
|
| 493 | + public function getPackage() |
|
| 494 | + { |
|
| 495 | + $className = $this->getName(); |
|
| 496 | + $docComment = $this->getDocblock(); |
|
| 497 | + |
|
| 498 | + $result = [ |
|
| 499 | + 'namespace' => '', |
|
| 500 | + 'fullPackage' => '', |
|
| 501 | + 'category' => '', |
|
| 502 | + 'package' => '', |
|
| 503 | + 'subpackage' => '' |
|
| 504 | + ]; |
|
| 505 | + |
|
| 506 | + for ($i = $this->id; $i; --$i) { |
|
| 507 | + if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) { |
|
| 508 | + $result['namespace'] = $this->tokenStream[$i]->getName(); |
|
| 509 | + break; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 514 | + $result['category'] = $matches[1]; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 518 | + $result['package'] = $matches[1]; |
|
| 519 | + $result['fullPackage'] = $matches[1]; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { |
|
| 523 | + $result['subpackage'] = $matches[1]; |
|
| 524 | + $result['fullPackage'] .= '.' . $matches[1]; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + if (empty($result['fullPackage'])) { |
|
| 528 | + $result['fullPackage'] = $this->arrayToName( |
|
| 529 | + explode('_', str_replace('\\', '_', $className)), |
|
| 530 | + '.' |
|
| 531 | + ); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + return $result; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * @param array $parts |
|
| 539 | + * @param string $join |
|
| 540 | + * |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + protected function arrayToName(array $parts, $join = '\\') |
|
| 544 | + { |
|
| 545 | + $result = ''; |
|
| 546 | + |
|
| 547 | + if (count($parts) > 1) { |
|
| 548 | + array_pop($parts); |
|
| 549 | + |
|
| 550 | + $result = implode($join, $parts); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + return $result; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @return bool|string |
|
| 558 | + */ |
|
| 559 | + public function getParent() |
|
| 560 | + { |
|
| 561 | + if (!$this->hasParent()) { |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + $i = $this->id + 6; |
|
| 566 | + $tokens = $this->tokenStream->tokens(); |
|
| 567 | + $className = (string) $tokens[$i]; |
|
| 568 | + |
|
| 569 | + while (isset($tokens[$i + 1]) && |
|
| 570 | + !$tokens[$i + 1] instanceof PHP_Token_WHITESPACE) { |
|
| 571 | + $className .= (string) $tokens[++$i]; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + return $className; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @return bool |
|
| 579 | + */ |
|
| 580 | + public function hasInterfaces() |
|
| 581 | + { |
|
| 582 | + return (isset($this->tokenStream[$this->id + 4]) && |
|
| 583 | + $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) || |
|
| 584 | + (isset($this->tokenStream[$this->id + 8]) && |
|
| 585 | + $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @return array|bool |
|
| 590 | + */ |
|
| 591 | + public function getInterfaces() |
|
| 592 | + { |
|
| 593 | + if ($this->interfaces !== null) { |
|
| 594 | + return $this->interfaces; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if (!$this->hasInterfaces()) { |
|
| 598 | + return ($this->interfaces = false); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) { |
|
| 602 | + $i = $this->id + 3; |
|
| 603 | + } else { |
|
| 604 | + $i = $this->id + 7; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $tokens = $this->tokenStream->tokens(); |
|
| 608 | + |
|
| 609 | + while (!$tokens[$i + 1] instanceof PHP_Token_OPEN_CURLY) { |
|
| 610 | + $i++; |
|
| 611 | + |
|
| 612 | + if ($tokens[$i] instanceof PHP_Token_STRING) { |
|
| 613 | + $this->interfaces[] = (string) $tokens[$i]; |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $this->interfaces; |
|
| 618 | + } |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | class PHP_Token_ABSTRACT extends PHP_Token |
@@ -688,57 +688,57 @@ discard block |
||
| 688 | 688 | |
| 689 | 689 | class PHP_Token_CLASS extends PHP_Token_INTERFACE |
| 690 | 690 | { |
| 691 | - /** |
|
| 692 | - * @var bool |
|
| 693 | - */ |
|
| 694 | - private $anonymous = false; |
|
| 691 | + /** |
|
| 692 | + * @var bool |
|
| 693 | + */ |
|
| 694 | + private $anonymous = false; |
|
| 695 | 695 | |
| 696 | - /** |
|
| 697 | - * @var string |
|
| 698 | - */ |
|
| 699 | - private $name; |
|
| 696 | + /** |
|
| 697 | + * @var string |
|
| 698 | + */ |
|
| 699 | + private $name; |
|
| 700 | 700 | |
| 701 | - /** |
|
| 702 | - * @return string |
|
| 703 | - */ |
|
| 704 | - public function getName() |
|
| 705 | - { |
|
| 706 | - if ($this->name !== null) { |
|
| 707 | - return $this->name; |
|
| 708 | - } |
|
| 701 | + /** |
|
| 702 | + * @return string |
|
| 703 | + */ |
|
| 704 | + public function getName() |
|
| 705 | + { |
|
| 706 | + if ($this->name !== null) { |
|
| 707 | + return $this->name; |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - $next = $this->tokenStream[$this->id + 1]; |
|
| 710 | + $next = $this->tokenStream[$this->id + 1]; |
|
| 711 | 711 | |
| 712 | - if ($next instanceof PHP_Token_WHITESPACE) { |
|
| 713 | - $next = $this->tokenStream[$this->id + 2]; |
|
| 714 | - } |
|
| 712 | + if ($next instanceof PHP_Token_WHITESPACE) { |
|
| 713 | + $next = $this->tokenStream[$this->id + 2]; |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - if ($next instanceof PHP_Token_STRING) { |
|
| 717 | - $this->name =(string) $next; |
|
| 716 | + if ($next instanceof PHP_Token_STRING) { |
|
| 717 | + $this->name =(string) $next; |
|
| 718 | 718 | |
| 719 | - return $this->name; |
|
| 720 | - } |
|
| 719 | + return $this->name; |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - if ($next instanceof PHP_Token_OPEN_CURLY || |
|
| 723 | - $next instanceof PHP_Token_EXTENDS || |
|
| 724 | - $next instanceof PHP_Token_IMPLEMENTS) { |
|
| 722 | + if ($next instanceof PHP_Token_OPEN_CURLY || |
|
| 723 | + $next instanceof PHP_Token_EXTENDS || |
|
| 724 | + $next instanceof PHP_Token_IMPLEMENTS) { |
|
| 725 | 725 | |
| 726 | - $this->name = sprintf( |
|
| 727 | - 'AnonymousClass:%s#%s', |
|
| 728 | - $this->getLine(), |
|
| 729 | - $this->getId() |
|
| 730 | - ); |
|
| 726 | + $this->name = sprintf( |
|
| 727 | + 'AnonymousClass:%s#%s', |
|
| 728 | + $this->getLine(), |
|
| 729 | + $this->getId() |
|
| 730 | + ); |
|
| 731 | 731 | |
| 732 | - $this->anonymous = true; |
|
| 732 | + $this->anonymous = true; |
|
| 733 | 733 | |
| 734 | - return $this->name; |
|
| 735 | - } |
|
| 736 | - } |
|
| 734 | + return $this->name; |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - public function isAnonymous() |
|
| 739 | - { |
|
| 740 | - return $this->anonymous; |
|
| 741 | - } |
|
| 738 | + public function isAnonymous() |
|
| 739 | + { |
|
| 740 | + return $this->anonymous; |
|
| 741 | + } |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | class PHP_Token_CLASS_C extends PHP_Token |
@@ -1269,25 +1269,25 @@ discard block |
||
| 1269 | 1269 | |
| 1270 | 1270 | class PHP_Token_NAMESPACE extends PHP_TokenWithScope |
| 1271 | 1271 | { |
| 1272 | - /** |
|
| 1273 | - * @return string |
|
| 1274 | - */ |
|
| 1275 | - public function getName() |
|
| 1276 | - { |
|
| 1277 | - $tokens = $this->tokenStream->tokens(); |
|
| 1278 | - $namespace = (string) $tokens[$this->id + 2]; |
|
| 1279 | - |
|
| 1280 | - for ($i = $this->id + 3;; $i += 2) { |
|
| 1281 | - if (isset($tokens[$i]) && |
|
| 1282 | - $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) { |
|
| 1283 | - $namespace .= '\\' . $tokens[$i + 1]; |
|
| 1284 | - } else { |
|
| 1285 | - break; |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - return $namespace; |
|
| 1290 | - } |
|
| 1272 | + /** |
|
| 1273 | + * @return string |
|
| 1274 | + */ |
|
| 1275 | + public function getName() |
|
| 1276 | + { |
|
| 1277 | + $tokens = $this->tokenStream->tokens(); |
|
| 1278 | + $namespace = (string) $tokens[$this->id + 2]; |
|
| 1279 | + |
|
| 1280 | + for ($i = $this->id + 3;; $i += 2) { |
|
| 1281 | + if (isset($tokens[$i]) && |
|
| 1282 | + $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) { |
|
| 1283 | + $namespace .= '\\' . $tokens[$i + 1]; |
|
| 1284 | + } else { |
|
| 1285 | + break; |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + return $namespace; |
|
| 1290 | + } |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | class PHP_Token_NS_C extends PHP_Token |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | if (!$this->isAnonymous()) { |
| 377 | 377 | for ($i = $this->id; $i; --$i) { |
| 378 | 378 | if ($tokens[$i] instanceof PHP_Token_NAMESPACE) { |
| 379 | - $this->name = $tokens[$i]->getName() . '\\' . $this->name; |
|
| 379 | + $this->name = $tokens[$i]->getName().'\\'.$this->name; |
|
| 380 | 380 | |
| 381 | 381 | break; |
| 382 | 382 | } |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | |
| 522 | 522 | if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { |
| 523 | 523 | $result['subpackage'] = $matches[1]; |
| 524 | - $result['fullPackage'] .= '.' . $matches[1]; |
|
| 524 | + $result['fullPackage'] .= '.'.$matches[1]; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | if (empty($result['fullPackage'])) { |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | if ($next instanceof PHP_Token_STRING) { |
| 717 | - $this->name =(string) $next; |
|
| 717 | + $this->name = (string) $next; |
|
| 718 | 718 | |
| 719 | 719 | return $this->name; |
| 720 | 720 | } |
@@ -1277,10 +1277,10 @@ discard block |
||
| 1277 | 1277 | $tokens = $this->tokenStream->tokens(); |
| 1278 | 1278 | $namespace = (string) $tokens[$this->id + 2]; |
| 1279 | 1279 | |
| 1280 | - for ($i = $this->id + 3;; $i += 2) { |
|
| 1280 | + for ($i = $this->id + 3; ; $i += 2) { |
|
| 1281 | 1281 | if (isset($tokens[$i]) && |
| 1282 | 1282 | $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) { |
| 1283 | - $namespace .= '\\' . $tokens[$i + 1]; |
|
| 1283 | + $namespace .= '\\'.$tokens[$i + 1]; |
|
| 1284 | 1284 | } else { |
| 1285 | 1285 | break; |
| 1286 | 1286 | } |