Skip to content

validate with phpstan #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gitattributes export-ignore
/.github/ export-ignore
.gitignore export-ignore
/.php_cs.dist export-ignore
/phpstan.neon.dist export-ignore
/phpstan.tests.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/stubs/ export-ignore
/tests/ export-ignore
42 changes: 42 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Static analysis

on:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.x'
pull_request:

jobs:
phpstan-src:
name: PHPStan src
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyze --no-progress

phpstan-tests:
name: PHPStan tests
runs-on: ubuntu-latest
env:
REQUIRE_DEV: "true"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: |
composer update --no-progress

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyze --no-progress -c phpstan.tests.neon.dist
4 changes: 2 additions & 2 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '7.1'
dependencies: 'lowest'
- php-version: '7.2'
dependencies: 'lowest'
- php-version: '7.3'
- php-version: '7.4'
- php-version: '8.0'
- php-version: '8.0'
dev-dependencies: true
- php-version: '8.1'
- php-version: '8.2'

steps:
- name: Checkout project
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.2 || ^8.0",
"phpcr/phpcr": "~2.1.0",
"symfony/console": "^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
},
"require-dev": {
"ramsey/uuid": "^3.5",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0"
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
"phpstan/phpstan": "^1.9"
},
"suggest": {
"ramsey/uuid": "A library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
level: 2
paths:
- src
ignoreErrors:
-
message: "#Symfony\\\\Component\\\\Console\\\\Helper\\\\DialogHelper#"
count: 3
path: src/PHPCR/Util/Console/Command/BaseCommand.php
4 changes: 4 additions & 0 deletions phpstan.tests.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 1
paths:
- tests
5 changes: 0 additions & 5 deletions src/PHPCR/Util/CND/Parser/CndParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,6 @@ protected function parseQueryOpsAttribute()
$ops[] = $op;
} while ($op && $this->checkAndExpectToken(Token::TK_SYMBOL, ','));

if (empty($ops)) {
// There must be at least an operator if this attribute is not variant
throw new ParserException($this->tokenQueue, 'Operator expected');
}

return $ops;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/CND/Reader/FileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileReader extends BufferReader
/**
* @var string
*/
protected $filePath;
protected $path;

/**
* @param string $path
Expand Down
16 changes: 10 additions & 6 deletions src/PHPCR/Util/CND/Writer/CndWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPCR\NamespaceRegistryInterface;
use PHPCR\NodeType\NodeDefinitionInterface;
use PHPCR\NodeType\NodeTypeDefinitionInterface;
use PHPCR\NodeType\NodeTypeManagerInterface;
use PHPCR\NodeType\NodeTypeTemplateInterface;
use PHPCR\NodeType\PropertyDefinitionInterface;
use PHPCR\PropertyType;
Expand Down Expand Up @@ -34,9 +33,6 @@ class CndWriter
/** @var array hashmap of prefix => namespace uri */
private $namespaces = [];

/**
* @param NodeTypeManagerInterface $ntm
*/
public function __construct(NamespaceRegistryInterface $ns)
{
$this->ns = $ns;
Expand Down Expand Up @@ -135,6 +131,11 @@ protected function writeNodeType(NodeTypeDefinitionInterface $nodeType)
return $s;
}

/**
* @param PropertyDefinitionInterface[] $properties
*
* @return string
*/
private function writeProperties($properties)
{
if (null === $properties) {
Expand All @@ -145,7 +146,6 @@ private function writeProperties($properties)

$s = '';

/** @var $property PropertyDefinitionInterface */
foreach ($properties as $property) {
$this->checkNamespace($property->getName());
$s .= '- '.$property->getName();
Expand Down Expand Up @@ -196,6 +196,11 @@ private function writeProperties($properties)
return $s;
}

/**
* @param NodeDefinitionInterface[] $children
*
* @return string
*/
private function writeChildren($children)
{
if (null === $children) {
Expand All @@ -206,7 +211,6 @@ private function writeChildren($children)

$s = '';

/** @var $child NodeDefinitionInterface */
foreach ($children as $child) {
$this->checkNamespace($child->getName());
$s .= '+ '.$child->getName();
Expand Down
32 changes: 22 additions & 10 deletions src/PHPCR/Util/Console/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
use PHPCR\Util\Console\Helper\PhpcrHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
Expand Down Expand Up @@ -51,40 +53,50 @@ protected function getPhpcrConsoleDumperHelper()
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $question
* @param string $questionText
* @param string $default
*
* @return string
*/
protected function ask(InputInterface $input, OutputInterface $output, $question, $default = null)
protected function ask(InputInterface $input, OutputInterface $output, $questionText, $default = null)
{
if ($this->getHelperSet()->has('question')) {
$question = new Question($question, $default);
$question = new Question($questionText, $default);

return $this->getHelper('question')->ask($input, $output, $question);
return $this->getQuestionHelper()->ask($input, $output, $question);
}

return $this->getHelper('dialog')->ask($output, $question, $default);
return $this->getDialogHelper()->ask($output, $questionText, $default);
}

/**
* Ask for confirmation with the question helper or the dialog helper for symfony < 2.5 compatibility.
*
* @param InputInterface $input
* @param OutputInterface $output
* @param string $question
* @param string $questionText
* @param bool $default
*
* @return string
*/
protected function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = true)
protected function askConfirmation(InputInterface $input, OutputInterface $output, $questionText, $default = true)
{
if ($this->getHelperSet()->has('question')) {
$question = new ConfirmationQuestion($question, $default);
$question = new ConfirmationQuestion($questionText, $default);

return $this->getHelper('question')->ask($input, $output, $question);
return $this->getQuestionHelper()->ask($input, $output, $question);
}

return $this->getHelper('dialog')->askConfirmation($output, $question, $default);
return $this->getDialogHelper()->askConfirmation($output, $questionText, $default);
}

private function getQuestionHelper(): QuestionHelper
{
return $this->getHelper('question');
}

private function getDialogHelper(): DialogHelper
{
return $this->getHelper('dialog');
}
}
2 changes: 1 addition & 1 deletion src/PHPCR/Util/Console/Command/NodeRemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($onlyChildren) {
$baseNode = $session->getNode($path, 0);

/** @var $childNode NodeInterface */
/** @var NodeInterface $childNode */
foreach ($baseNode->getNodes() as $childNode) {
$childNodePath = $childNode->getPath();
$childNode->remove();
Expand Down
4 changes: 2 additions & 2 deletions src/PHPCR/Util/Console/Command/NodesUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$persistIn = $persistCounter;

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

if ($response === 'L') {
/** @var $row RowInterface */
/** @var RowInterface $row */
foreach ($result as $i => $row) {
$output->writeln(sprintf(' - [%d] %s', $i, $row->getPath()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/Console/Helper/PhpcrHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function processNode(OutputInterface $output, NodeInterface $node, array

if ($operations['dump']) {
$output->writeln('<info>Node dump: </info>');
/** @var $property PropertyInterface */
/** @var PropertyInterface $property */
foreach ($node->getProperties() as $property) {
$value = $property->getValue();
if (!is_string($value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setShowFullPath($showFullPath)
public function visit(ItemInterface $item)
{
if (!$item instanceof NodeInterface) {
throw new Exception("Internal error: did not expect to visit a non-node object: $item");
throw new Exception('Internal error: did not expect to visit a non-node object: '.get_class($item));
}

if ($item->getDepth() === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor
*/
protected $expandReferences;

/**
* @var string
*/
private $refFormat;

/**
* Instantiate property visitor.
*
Expand Down
4 changes: 2 additions & 2 deletions src/PHPCR/Util/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ public static function purgeWorkspace(SessionInterface $session)
{
$root = $session->getRootNode();

/** @var $property PropertyInterface */
/** @var PropertyInterface $property */
foreach ($root->getProperties() as $property) {
if (!self::isSystemItem($property)) {
$property->remove();
}
}

/** @var $node NodeInterface */
/** @var NodeInterface $node */
foreach ($root->getNodes() as $node) {
if (!self::isSystemItem($node)) {
$node->remove();
Expand Down
2 changes: 0 additions & 2 deletions src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ protected function convertPropertyValue(QOM\PropertyValueInterface $value)
protected function convertOrderings(array $orderings)
{
$list = [];
/** @var $ordering QOM\OrderingInterface */
foreach ($orderings as $ordering) {
$order = $this->generator->evalOrder($ordering->getOrder());
$operand = $this->convertDynamicOperand($ordering->getOperand());
Expand Down Expand Up @@ -314,7 +313,6 @@ protected function convertColumns(array $columns)
{
$list = [];

/** @var $column QOM\ColumnInterface */
foreach ($columns as $column) {
$selector = $column->getSelectorName();
$property = $column->getPropertyName();
Expand Down
Loading