Skip to content

Commit 7ef0641

Browse files
committed
Fetch comments from ignored elements
To detect file level docblocks get the comments from the ignored tags as well. refs phpDocumentor/phpDocumentor#3190
1 parent b7be0e9 commit 7ef0641

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/phpDocumentor/Reflection/Php/Factory/File.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
use PhpParser\Node\Stmt\Interface_ as InterfaceNode;
3434
use PhpParser\Node\Stmt\Trait_ as TraitNode;
3535

36+
use function array_merge;
3637
use function get_class;
3738
use function in_array;
38-
use function is_array;
3939

4040
/**
4141
* Strategy to create File element from the provided filename.
@@ -144,19 +144,22 @@ protected function createFileDocBlock(
144144
array $nodes = []
145145
): ?DocBlockInstance {
146146
$node = null;
147+
$comments = [];
147148
foreach ($nodes as $n) {
148149
if (!in_array(get_class($n), self::SKIPPED_NODE_TYPES)) {
149150
$node = $n;
150151
break;
151152
}
153+
154+
$comments = array_merge($comments, $n->getAttribute('comments', []));
152155
}
153156

154157
if (!$node instanceof Node) {
155158
return null;
156159
}
157160

158-
$comments = $node->getAttribute('comments');
159-
if (!is_array($comments) || empty($comments)) {
161+
$comments = array_merge($comments, $node->getAttribute('comments', []));
162+
if (empty($comments)) {
160163
return null;
161164
}
162165

tests/integration/FileDocblockTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function fileProvider() : array
4343
[ __DIR__ . '/data/GlobalFiles/empty.php' ],
4444
[ __DIR__ . '/data/GlobalFiles/empty_with_declare.php' ],
4545
[ __DIR__ . '/data/GlobalFiles/empty_shebang.php' ],
46+
[ __DIR__ . '/data/GlobalFiles/psr12.php' ],
47+
[ __DIR__ . '/data/GlobalFiles/docblock_followed_by_html.php' ],
4648
];
4749
}
4850

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2015-2018 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
?>
13+
<h1>Test</h1>
14+
<?php
15+
16+
require 'Pizza.php';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2015-2018 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
require 'Pizza.php';

0 commit comments

Comments
 (0)