Skip to content

Commit 7275cb3

Browse files
authored
Merge pull request #120 from jaapio/feature/file-docblock
Fixes none element docblock handling
2 parents 3659ab8 + fac1df9 commit 7275cb3

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private function createElements(Fqsen $namespace, $nodes, FileElement $file, Str
164164
* @param StrategyContainer $strategies
165165
* @param Context $context
166166
* @param Node[] $nodes
167-
* @return null|\phpDocumentor\Reflection\Element
167+
* @return null|\phpDocumentor\Reflection\DocBlock
168168
*/
169169
protected function createFileDocBlock(
170170
Doc $docBlock = null,
@@ -174,12 +174,12 @@ protected function createFileDocBlock(
174174
) {
175175
$node = current($nodes);
176176
if (!$node instanceof Node) {
177-
return $docBlock;
177+
return null;
178178
}
179179

180180
$comments = $node->getAttribute('comments');
181181
if (!is_array($comments) || empty($comments)) {
182-
return $docBlock;
182+
return null;
183183
}
184184

185185
$found = 0;
@@ -189,7 +189,13 @@ protected function createFileDocBlock(
189189
continue;
190190
}
191191

192-
if ($node instanceof NamespaceNode) {
192+
//If current node cannot have a docblock return the first comment as docblock for the file.
193+
if (!(
194+
$node instanceof ClassNode ||
195+
$node instanceof FunctionNode ||
196+
$node instanceof InterfaceNode ||
197+
$node instanceof TraitNode
198+
)) {
193199
return $this->createDocBlock($strategies, $comment, $context);
194200
}
195201

@@ -205,6 +211,6 @@ protected function createFileDocBlock(
205211
return $this->createDocBlock($strategies, $firstDocBlock, $context);
206212
}
207213

208-
return $docBlock;
214+
return null;
209215
}
210216
}

tests/component/ProjectCreationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,15 @@ public function testMethodReturnType()
194194

195195
$this->assertEquals(new String_(), $interface->getMethods()['\Packing::getName()']->getReturnType());
196196
}
197+
198+
public function testFileDocblock()
199+
{
200+
$fileName = __DIR__ . '/project/empty.php';
201+
$project = $this->fixture->create('MyProject', [
202+
new LocalFile($fileName)
203+
]);
204+
205+
$this->assertEquals("This file is part of phpDocumentor.", $project->getFiles()[$fileName]->getDocBlock()->getSummary());
206+
207+
}
197208
}

tests/component/project/empty.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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-2015 Mike van Riel<mike@phpdoc.org>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
require "Pizza.php";

0 commit comments

Comments
 (0)