Skip to content

Commit 8402c36

Browse files
committed
Add ignored nodes to file
1 parent 7bdb6d1 commit 8402c36

File tree

10 files changed

+152
-22
lines changed

10 files changed

+152
-22
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ jobs:
146146
all-build-${{ hashFiles('**/composer.lock') }}
147147
all-build-
148148
- name: PHPStan
149-
uses: phpDocumentor/phpstan-ga@0.12.3
149+
uses: phpDocumentor/phpstan-ga@master
150150
env:
151151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152152
with:
153-
args: analyse src --level max --configuration phpstan.neon
153+
args: analyse src --configuration phpstan.neon
154154

155155
# psalm:
156156
# runs-on: ubuntu-latest

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ setup: install-phive
1515
phpcs:
1616
docker run -it --rm -v${CURDIR}:/opt/project -w /opt/project phpdoc/phpcs-ga:v1.0.0 -s
1717

18+
.PHONY: phpcbf
19+
phpcbf:
20+
docker run -it --rm -v${CURDIR}:/opt/project -w /opt/project phpdoc/phpcs-ga:v1.0.0 phpcbf
21+
1822
.PHONY: phpstan
1923
phpstan:
2024
docker run -it --rm -v${CURDIR}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --level max --configuration phpstan.neon

phpstan.neon

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
includes:
2+
- /composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon
3+
- /composer/vendor/phpstan/phpstan-php-parser/extension.neon
4+
15
parameters:
26
checkGenericClassInNonGenericObjectType: false
7+
level: max
38
ignoreErrors:
49

510
- '#Method phpDocumentor\\Reflection\\File\\LocalFile::\md5\(\) should return string but returns string\|false\.#'
@@ -16,9 +21,6 @@ parameters:
1621
- '#Access to an undefined property PhpParser\\Node\\Const_::\$fqsen\.#'
1722
- '#Access to an undefined property PhpParser\\Node\\Stmt\\PropertyProperty::\$fqsen\.#'
1823
#
19-
# src/phpDocumentor/Reflection/Php/Factory/Argument.php
20-
- '#Access to an undefined property PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable::\$name\.#'
21-
#
2224
# src/phpDocumentor/Reflection/Php/Factory/Class_.php
2325
- '#Access to an undefined property PhpParser\\Node\\Stmt\\Class_::\$fqsen\.#'
2426
#
@@ -27,7 +29,7 @@ parameters:
2729
#
2830
#
2931
# this is a mismatch inside php-parser, not reflection
30-
- '#Parameter \#1 \$nodes of method PhpParser\\NodeTraverser::traverse\(\) expects array\<PhpParser\\Node>, array\<PhpParser\\Node\\Stmt\>|null given\.#'
32+
- '#Parameter \#1 \$nodes of method PhpParser\\NodeTraverser::traverse\(\) expects array\<PhpParser\\Node>, array\<PhpParser\\Node\\Stmt\>\|null given\.#'
3133
#
3234
#
3335
# there is one test case that prevents changing PropertyIterator::getDefault() to just return Expr (this is set in PhpParser)
@@ -40,3 +42,33 @@ parameters:
4042
# until I can make $object arg ?$object...
4143
# src/phpDocumentor/Reflection/Php/Factory/DocBlock.php
4244
- '#Strict comparison using === between PhpParser\\Comment\\Doc and null will always evaluate to false\.#'
45+
46+
-
47+
message: "#^Parameter \\#1 \\$constant of method phpDocumentor\\\\Reflection\\\\Php\\\\File\\:\\:addConstant\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Constant, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
48+
count: 2
49+
path: src/phpDocumentor/Reflection/Php/Factory/File.php
50+
51+
-
52+
message: "#^Parameter \\#1 \\$class of method phpDocumentor\\\\Reflection\\\\Php\\\\File\\:\\:addClass\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Class_, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
53+
count: 1
54+
path: src/phpDocumentor/Reflection/Php/Factory/File.php
55+
56+
-
57+
message: "#^Parameter \\#1 \\$function of method phpDocumentor\\\\Reflection\\\\Php\\\\File\\:\\:addFunction\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Function_, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
58+
count: 1
59+
path: src/phpDocumentor/Reflection/Php/Factory/File.php
60+
61+
-
62+
message: "#^Parameter \\#1 \\$interface of method phpDocumentor\\\\Reflection\\\\Php\\\\File\\:\\:addInterface\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Interface_, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
63+
count: 1
64+
path: src/phpDocumentor/Reflection/Php/Factory/File.php
65+
66+
-
67+
message: "#^Parameter \\#1 \\$trait of method phpDocumentor\\\\Reflection\\\\Php\\\\File\\:\\:addTrait\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Trait_, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
68+
count: 1
69+
path: src/phpDocumentor/Reflection/Php/Factory/File.php
70+
71+
-
72+
message: "#^Parameter \\#1 \\$argument of method phpDocumentor\\\\Reflection\\\\Php\\\\Function_\\:\\:addArgument\\(\\) expects phpDocumentor\\\\Reflection\\\\Php\\\\Argument, phpDocumentor\\\\Reflection\\\\DocBlock\\|phpDocumentor\\\\Reflection\\\\Element\\|phpDocumentor\\\\Reflection\\\\Php\\\\Argument\\|phpDocumentor\\\\Reflection\\\\Php\\\\File\\|null given\\.$#"
73+
count: 1
74+
path: src/phpDocumentor/Reflection/Php/Factory/Function_.php

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
use PhpParser\Node;
3030
use PhpParser\Node\Stmt\Class_ as ClassNode;
3131
use PhpParser\Node\Stmt\Const_ as ConstantNode;
32+
use PhpParser\Node\Stmt\Declare_ as DeclareNode;
3233
use PhpParser\Node\Stmt\Function_ as FunctionNode;
34+
use PhpParser\Node\Stmt\InlineHTML;
3335
use PhpParser\Node\Stmt\Interface_ as InterfaceNode;
3436
use PhpParser\Node\Stmt\Namespace_ as NamespaceNode;
3537
use PhpParser\Node\Stmt\Trait_ as TraitNode;
36-
use function current;
3738
use function get_class;
39+
use function in_array;
3840
use function is_array;
3941

4042
/**
@@ -43,6 +45,11 @@
4345
*/
4446
final class File extends AbstractFactory
4547
{
48+
private const SKIPPED_NODE_TYPES = [
49+
DeclareNode::class,
50+
InlineHTML::class,
51+
];
52+
4653
/** @var NodesFactory */
4754
private $nodesFactory;
4855

@@ -178,7 +185,14 @@ protected function createFileDocBlock(
178185
?Context $context = null,
179186
array $nodes = []
180187
) : ?DocBlockInstance {
181-
$node = current($nodes);
188+
$node = null;
189+
foreach ($nodes as $n) {
190+
if (!in_array(get_class($n), self::SKIPPED_NODE_TYPES)) {
191+
$node = $n;
192+
break;
193+
}
194+
}
195+
182196
if (!$node instanceof Node) {
183197
return null;
184198
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace integration;
6+
7+
use phpDocumentor\Reflection\File\LocalFile;
8+
use phpDocumentor\Reflection\Php\ProjectFactory;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Integration tests to check the correct working of processing a namespace into a project.
13+
*
14+
* @coversNothing
15+
*/
16+
final class FileDocblockTest extends TestCase
17+
{
18+
/** @var ProjectFactory */
19+
private $fixture;
20+
21+
protected function setUp() : void
22+
{
23+
$this->fixture = ProjectFactory::createInstance();
24+
}
25+
26+
/**
27+
* @dataProvider fileProvider
28+
*/
29+
public function testFileDocblock(string $fileName) : void
30+
{
31+
$project = $this->fixture->create(
32+
'MyProject',
33+
[new LocalFile($fileName)]
34+
);
35+
36+
$this->assertEquals(
37+
'This file is part of phpDocumentor.',
38+
$project->getFiles()[$fileName]->getDocBlock()->getSummary()
39+
);
40+
}
41+
42+
43+
public function fileProvider(string $file)
44+
{
45+
return [
46+
[ __DIR__ . '/data/GlobalFiles/empty.php' ],
47+
[ __DIR__ . '/data/GlobalFiles/empty_with_declare.php' ],
48+
[ __DIR__ . '/data/GlobalFiles/empty_shebang.php' ],
49+
];
50+
}
51+
}

tests/integration/ProjectCreationTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,4 @@ public function testMethodReturnType() : void
234234

235235
$this->assertEquals(new String_(), $interface->getMethods()['\Packing::getName()']->getReturnType());
236236
}
237-
238-
public function testFileDocblock() : void
239-
{
240-
$fileName = __DIR__ . '/data/empty.php';
241-
$project = $this->fixture->create(
242-
'MyProject',
243-
[new LocalFile($fileName)]
244-
);
245-
246-
$this->assertEquals(
247-
'This file is part of phpDocumentor.',
248-
$project->getFiles()[$fileName]->getDocBlock()->getSummary()
249-
);
250-
}
251237
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/php
2+
<?php
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of phpDocumentor.
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @copyright 2015-2018 Mike van Riel<[email protected]>
11+
* @license http://www.opensource.org/licenses/mit-license.php MIT
12+
* @link http://phpdoc.org
13+
*/
14+
15+
require 'Pizza.php';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* This file is part of phpDocumentor.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @copyright 2015-2018 Mike van Riel<[email protected]>
10+
* @license http://www.opensource.org/licenses/mit-license.php MIT
11+
* @link http://phpdoc.org
12+
*/
13+
14+
require 'Pizza.php';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Test</h1>
2+
<?php
3+
/**
4+
* This file is part of phpDocumentor.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @copyright 2015-2018 Mike van Riel<[email protected]>
10+
* @license http://www.opensource.org/licenses/mit-license.php MIT
11+
* @link http://phpdoc.org
12+
*/
13+
14+
require 'Pizza.php';

0 commit comments

Comments
 (0)