Skip to content

Commit 5c70008

Browse files
authored
Merge pull request #209 from phpcr/phpstan
validate with phpstan
2 parents 71d5083 + 54fb032 commit 5c70008

27 files changed

+307
-84
lines changed

.gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.gitattributes export-ignore
2+
/.github/ export-ignore
3+
.gitignore export-ignore
4+
/.php_cs.dist export-ignore
5+
/phpstan.neon.dist export-ignore
6+
/phpstan.tests.neon.dist export-ignore
7+
/phpunit.xml.dist export-ignore
8+
/stubs/ export-ignore
9+
/tests/ export-ignore

.github/workflows/static.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Static analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- '[0-9]+.x'
7+
- '[0-9]+.[0-9]+'
8+
- '[0-9]+.[0-9]+.x'
9+
pull_request:
10+
11+
jobs:
12+
phpstan-src:
13+
name: PHPStan src
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: PHPStan
21+
uses: docker://oskarstark/phpstan-ga
22+
with:
23+
args: analyze --no-progress
24+
25+
phpstan-tests:
26+
name: PHPStan tests
27+
runs-on: ubuntu-latest
28+
env:
29+
REQUIRE_DEV: "true"
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v2
34+
35+
- name: Install dependencies
36+
run: |
37+
composer update --no-progress
38+
39+
- name: PHPStan
40+
uses: docker://oskarstark/phpstan-ga
41+
with:
42+
args: analyze --no-progress -c phpstan.tests.neon.dist

.github/workflows/test-application.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- php-version: '7.1'
22-
dependencies: 'lowest'
2321
- php-version: '7.2'
22+
dependencies: 'lowest'
2423
- php-version: '7.3'
2524
- php-version: '7.4'
2625
- php-version: '8.0'
2726
- php-version: '8.0'
2827
dev-dependencies: true
2928
- php-version: '8.1'
29+
- php-version: '8.2'
3030

3131
steps:
3232
- name: Checkout project

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
}
2828
],
2929
"require": {
30-
"php": "^7.1 || ^8.0",
30+
"php": "^7.2 || ^8.0",
3131
"phpcr/phpcr": "~2.1.0",
3232
"symfony/console": "^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
3333
},
3434
"require-dev": {
3535
"ramsey/uuid": "^3.5",
36-
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0"
36+
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
37+
"phpstan/phpstan": "^1.9"
3738
},
3839
"suggest": {
3940
"ramsey/uuid": "A library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."

phpstan.neon.dist

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 2
3+
paths:
4+
- src
5+
ignoreErrors:
6+
-
7+
message: "#Symfony\\\\Component\\\\Console\\\\Helper\\\\DialogHelper#"
8+
count: 3
9+
path: src/PHPCR/Util/Console/Command/BaseCommand.php

phpstan.tests.neon.dist

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 1
3+
paths:
4+
- tests

src/PHPCR/Util/CND/Parser/CndParser.php

-5
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,6 @@ protected function parseQueryOpsAttribute()
733733
$ops[] = $op;
734734
} while ($op && $this->checkAndExpectToken(Token::TK_SYMBOL, ','));
735735

736-
if (empty($ops)) {
737-
// There must be at least an operator if this attribute is not variant
738-
throw new ParserException($this->tokenQueue, 'Operator expected');
739-
}
740-
741736
return $ops;
742737
}
743738

src/PHPCR/Util/CND/Reader/FileReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FileReader extends BufferReader
1313
/**
1414
* @var string
1515
*/
16-
protected $filePath;
16+
protected $path;
1717

1818
/**
1919
* @param string $path

src/PHPCR/Util/CND/Writer/CndWriter.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPCR\NamespaceRegistryInterface;
66
use PHPCR\NodeType\NodeDefinitionInterface;
77
use PHPCR\NodeType\NodeTypeDefinitionInterface;
8-
use PHPCR\NodeType\NodeTypeManagerInterface;
98
use PHPCR\NodeType\NodeTypeTemplateInterface;
109
use PHPCR\NodeType\PropertyDefinitionInterface;
1110
use PHPCR\PropertyType;
@@ -34,9 +33,6 @@ class CndWriter
3433
/** @var array hashmap of prefix => namespace uri */
3534
private $namespaces = [];
3635

37-
/**
38-
* @param NodeTypeManagerInterface $ntm
39-
*/
4036
public function __construct(NamespaceRegistryInterface $ns)
4137
{
4238
$this->ns = $ns;
@@ -135,6 +131,11 @@ protected function writeNodeType(NodeTypeDefinitionInterface $nodeType)
135131
return $s;
136132
}
137133

134+
/**
135+
* @param PropertyDefinitionInterface[] $properties
136+
*
137+
* @return string
138+
*/
138139
private function writeProperties($properties)
139140
{
140141
if (null === $properties) {
@@ -145,7 +146,6 @@ private function writeProperties($properties)
145146

146147
$s = '';
147148

148-
/** @var $property PropertyDefinitionInterface */
149149
foreach ($properties as $property) {
150150
$this->checkNamespace($property->getName());
151151
$s .= '- '.$property->getName();
@@ -196,6 +196,11 @@ private function writeProperties($properties)
196196
return $s;
197197
}
198198

199+
/**
200+
* @param NodeDefinitionInterface[] $children
201+
*
202+
* @return string
203+
*/
199204
private function writeChildren($children)
200205
{
201206
if (null === $children) {
@@ -206,7 +211,6 @@ private function writeChildren($children)
206211

207212
$s = '';
208213

209-
/** @var $child NodeDefinitionInterface */
210214
foreach ($children as $child) {
211215
$this->checkNamespace($child->getName());
212216
$s .= '+ '.$child->getName();

src/PHPCR/Util/Console/Command/BaseCommand.php

+22-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
77
use PHPCR\Util\Console\Helper\PhpcrHelper;
88
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Helper\DialogHelper;
10+
use Symfony\Component\Console\Helper\QuestionHelper;
911
use Symfony\Component\Console\Input\InputInterface;
1012
use Symfony\Component\Console\Output\OutputInterface;
1113
use Symfony\Component\Console\Question\ConfirmationQuestion;
@@ -51,40 +53,50 @@ protected function getPhpcrConsoleDumperHelper()
5153
*
5254
* @param InputInterface $input
5355
* @param OutputInterface $output
54-
* @param string $question
56+
* @param string $questionText
5557
* @param string $default
5658
*
5759
* @return string
5860
*/
59-
protected function ask(InputInterface $input, OutputInterface $output, $question, $default = null)
61+
protected function ask(InputInterface $input, OutputInterface $output, $questionText, $default = null)
6062
{
6163
if ($this->getHelperSet()->has('question')) {
62-
$question = new Question($question, $default);
64+
$question = new Question($questionText, $default);
6365

64-
return $this->getHelper('question')->ask($input, $output, $question);
66+
return $this->getQuestionHelper()->ask($input, $output, $question);
6567
}
6668

67-
return $this->getHelper('dialog')->ask($output, $question, $default);
69+
return $this->getDialogHelper()->ask($output, $questionText, $default);
6870
}
6971

7072
/**
7173
* Ask for confirmation with the question helper or the dialog helper for symfony < 2.5 compatibility.
7274
*
7375
* @param InputInterface $input
7476
* @param OutputInterface $output
75-
* @param string $question
77+
* @param string $questionText
7678
* @param bool $default
7779
*
7880
* @return string
7981
*/
80-
protected function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = true)
82+
protected function askConfirmation(InputInterface $input, OutputInterface $output, $questionText, $default = true)
8183
{
8284
if ($this->getHelperSet()->has('question')) {
83-
$question = new ConfirmationQuestion($question, $default);
85+
$question = new ConfirmationQuestion($questionText, $default);
8486

85-
return $this->getHelper('question')->ask($input, $output, $question);
87+
return $this->getQuestionHelper()->ask($input, $output, $question);
8688
}
8789

88-
return $this->getHelper('dialog')->askConfirmation($output, $question, $default);
90+
return $this->getDialogHelper()->askConfirmation($output, $questionText, $default);
91+
}
92+
93+
private function getQuestionHelper(): QuestionHelper
94+
{
95+
return $this->getHelper('question');
96+
}
97+
98+
private function getDialogHelper(): DialogHelper
99+
{
100+
return $this->getHelper('dialog');
89101
}
90102
}

src/PHPCR/Util/Console/Command/NodeRemoveCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
107107
if ($onlyChildren) {
108108
$baseNode = $session->getNode($path, 0);
109109

110-
/** @var $childNode NodeInterface */
110+
/** @var NodeInterface $childNode */
111111
foreach ($baseNode->getNodes() as $childNode) {
112112
$childNodePath = $childNode->getPath();
113113
$childNode->remove();

src/PHPCR/Util/Console/Command/NodesUpdateCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
125125

126126
$persistIn = $persistCounter;
127127

128-
/** @var $row RowInterface */
128+
/** @var RowInterface $row */
129129
foreach ($result as $i => $row) {
130130
$output->writeln(sprintf(
131131
'<info>Updating node:</info> [%d] %s.',
@@ -169,7 +169,7 @@ private function shouldExecute(InputInterface $input, OutputInterface $output, Q
169169
)));
170170

171171
if ($response === 'L') {
172-
/** @var $row RowInterface */
172+
/** @var RowInterface $row */
173173
foreach ($result as $i => $row) {
174174
$output->writeln(sprintf(' - [%d] %s', $i, $row->getPath()));
175175
}

src/PHPCR/Util/Console/Helper/PhpcrHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function processNode(OutputInterface $output, NodeInterface $node, array
129129

130130
if ($operations['dump']) {
131131
$output->writeln('<info>Node dump: </info>');
132-
/** @var $property PropertyInterface */
132+
/** @var PropertyInterface $property */
133133
foreach ($node->getProperties() as $property) {
134134
$value = $property->getValue();
135135
if (!is_string($value)) {

src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function setShowFullPath($showFullPath)
5858
public function visit(ItemInterface $item)
5959
{
6060
if (!$item instanceof NodeInterface) {
61-
throw new Exception("Internal error: did not expect to visit a non-node object: $item");
61+
throw new Exception('Internal error: did not expect to visit a non-node object: '.get_class($item));
6262
}
6363

6464
if ($item->getDepth() === 0) {

src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor
2727
*/
2828
protected $expandReferences;
2929

30+
/**
31+
* @var string
32+
*/
33+
private $refFormat;
34+
3035
/**
3136
* Instantiate property visitor.
3237
*

src/PHPCR/Util/NodeHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ public static function purgeWorkspace(SessionInterface $session)
8686
{
8787
$root = $session->getRootNode();
8888

89-
/** @var $property PropertyInterface */
89+
/** @var PropertyInterface $property */
9090
foreach ($root->getProperties() as $property) {
9191
if (!self::isSystemItem($property)) {
9292
$property->remove();
9393
}
9494
}
9595

96-
/** @var $node NodeInterface */
96+
/** @var NodeInterface $node */
9797
foreach ($root->getNodes() as $node) {
9898
if (!self::isSystemItem($node)) {
9999
$node->remove();

src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php

-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ protected function convertPropertyValue(QOM\PropertyValueInterface $value)
248248
protected function convertOrderings(array $orderings)
249249
{
250250
$list = [];
251-
/** @var $ordering QOM\OrderingInterface */
252251
foreach ($orderings as $ordering) {
253252
$order = $this->generator->evalOrder($ordering->getOrder());
254253
$operand = $this->convertDynamicOperand($ordering->getOperand());
@@ -314,7 +313,6 @@ protected function convertColumns(array $columns)
314313
{
315314
$list = [];
316315

317-
/** @var $column QOM\ColumnInterface */
318316
foreach ($columns as $column) {
319317
$selector = $column->getSelectorName();
320318
$property = $column->getPropertyName();

0 commit comments

Comments
 (0)