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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 42 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 6 deletions
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

Lines changed: 22 additions & 10 deletions
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
}

0 commit comments

Comments
 (0)