Skip to content

Commit 6399c4e

Browse files
committed
use php-cs-fixer
1 parent 84c51df commit 6399c4e

File tree

74 files changed

+484
-660
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+484
-660
lines changed

.github/workflows/static.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ jobs:
4040
uses: docker://oskarstark/phpstan-ga:1.8.0
4141
with:
4242
args: analyze --no-progress -c phpstan.tests.neon.dist
43+
44+
php-cs-fixer:
45+
name: PHP-CS-Fixer
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v3
51+
52+
- name: PHP-CS-Fixer
53+
uses: docker://oskarstark/php-cs-fixer-ga
54+
with:
55+
args: --dry-run --diff

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cli-config.php
2-
2+
.php-cs-fixer.cache
33
vendor/
44
composer.phar
5-
composer.lock
5+
composer.lock

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
->in(__DIR__.'/tests')
6+
->name('*.php')
7+
;
8+
9+
$config = new PhpCsFixer\Config();
10+
11+
return $config
12+
->setRiskyAllowed(true)
13+
->setRules([
14+
'@Symfony' => true,
15+
'single_line_throw' => false,
16+
])
17+
->setFinder($finder)
18+
;

.styleci.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"require-dev": {
3535
"ramsey/uuid": "^3.5",
3636
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
37-
"phpstan/phpstan": "^1.9"
37+
"phpstan/phpstan": "^1.9",
38+
"friendsofphp/php-cs-fixer": "^3.40"
3839
},
3940
"suggest": {
4041
"ramsey/uuid": "A library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."

src/PHPCR/Util/CND/Exception/ParserException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(TokenQueue $queue, $msg)
1919

2020
// construct a lookup of the next tokens
2121
$lookup = '';
22-
for ($i = 1; $i <= 5; $i++) {
22+
for ($i = 1; $i <= 5; ++$i) {
2323
if ($queue->isEof()) {
2424
break;
2525
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AbstractParser
3434
* Return false otherwise.
3535
*
3636
* @param int $type The expected token type
37-
* @param null|string $data The expected data or null
37+
* @param string|null $data The expected data or null
3838
* @param bool $ignoreCase whether to do string comparisons case insensitive or sensitive
3939
*
4040
* @return bool
@@ -65,8 +65,7 @@ protected function checkToken($type, $data = null, $ignoreCase = false)
6565
/**
6666
* Check if the token data is one of the elements of the data array.
6767
*
68-
* @param int $type
69-
* @param array $data
68+
* @param int $type
7069
*
7170
* @return bool
7271
*/
@@ -86,11 +85,11 @@ protected function checkTokenIn($type, array $data, $ignoreCase = false)
8685
* otherwise throw an exception.
8786
*
8887
* @param int $type The expected token type
89-
* @param null|string $data The expected token data or null
90-
*
91-
* @throws ParserException
88+
* @param string|null $data The expected token data or null
9289
*
9390
* @return Token
91+
*
92+
* @throws ParserException
9493
*/
9594
protected function expectToken($type, $data = null)
9695
{
@@ -110,7 +109,7 @@ protected function expectToken($type, $data = null)
110109
* return false.
111110
*
112111
* @param int $type The expected token type
113-
* @param null|string $data The expected token data or null
112+
* @param string|null $data The expected token data or null
114113
*
115114
* @return bool|Token
116115
*/

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@
3535
class CndParser extends AbstractParser
3636
{
3737
// node type attributes
38-
private $ORDERABLE = ['o', 'ord', 'orderable']; //, 'variant' => true);
39-
private $MIXIN = ['m', 'mix', 'mixin']; //, 'variant' => true);
40-
private $ABSTRACT = ['a', 'abs', 'abstract']; //, 'variant' => true);
41-
private $NOQUERY = ['noquery', 'nq']; //, 'variant' => false);
42-
private $QUERY = ['query', 'q']; //, 'variant' => false);
43-
private $PRIMARYITEM = ['primaryitem', '!']; //, 'variant' => false);
38+
private $ORDERABLE = ['o', 'ord', 'orderable']; // , 'variant' => true);
39+
private $MIXIN = ['m', 'mix', 'mixin']; // , 'variant' => true);
40+
private $ABSTRACT = ['a', 'abs', 'abstract']; // , 'variant' => true);
41+
private $NOQUERY = ['noquery', 'nq']; // , 'variant' => false);
42+
private $QUERY = ['query', 'q']; // , 'variant' => false);
43+
private $PRIMARYITEM = ['primaryitem', '!']; // , 'variant' => false);
4444

4545
// common for properties and child definitions
46-
private $PRIMARY = ['!', 'pri', 'primary']; //, 'variant' => true),
47-
private $AUTOCREATED = ['a', 'aut', 'autocreated']; //, 'variant' => true),
48-
private $MANDATORY = ['m', 'man', 'mandatory']; //, 'variant' => true),
49-
private $PROTECTED = ['p', 'pro', 'protected']; //, 'variant' => true),
46+
private $PRIMARY = ['!', 'pri', 'primary']; // , 'variant' => true),
47+
private $AUTOCREATED = ['a', 'aut', 'autocreated']; // , 'variant' => true),
48+
private $MANDATORY = ['m', 'man', 'mandatory']; // , 'variant' => true),
49+
private $PROTECTED = ['p', 'pro', 'protected']; // , 'variant' => true),
5050
private $OPV = ['COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'];
5151

5252
// property type attributes
53-
private $MULTIPLE = ['*', 'mul', 'multiple']; //, 'variant' => true),
54-
private $QUERYOPS = ['qop', 'queryops']; //, 'variant' => true), // Needs special handling !
55-
private $NOFULLTEXT = ['nof', 'nofulltext']; //, 'variant' => true),
56-
private $NOQUERYORDER = ['nqord', 'noqueryorder']; //, 'variant' => true),
53+
private $MULTIPLE = ['*', 'mul', 'multiple']; // , 'variant' => true),
54+
private $QUERYOPS = ['qop', 'queryops']; // , 'variant' => true), // Needs special handling !
55+
private $NOFULLTEXT = ['nof', 'nofulltext']; // , 'variant' => true),
56+
private $NOQUERYORDER = ['nqord', 'noqueryorder']; // , 'variant' => true),
5757

5858
// child node attributes
5959
// multiple is actually a jackrabbit specific synonym for sns
6060
// http://www.mail-archive.com/users@jackrabbit.apache.org/msg19268.html
61-
private $SNS = ['*', 'sns', 'multiple']; //, 'variant' => true),
61+
private $SNS = ['*', 'sns', 'multiple']; // , 'variant' => true),
6262

6363
/**
6464
* @var NodeTypeManagerInterface
@@ -75,9 +75,6 @@ class CndParser extends AbstractParser
7575
*/
7676
protected $nodeTypes = [];
7777

78-
/**
79-
* @param NodeTypeManagerInterface $ntm
80-
*/
8178
public function __construct(NodeTypeManagerInterface $ntm)
8279
{
8380
$this->ntm = $ntm;
@@ -130,7 +127,7 @@ private function parse(ReaderInterface $reader)
130127

131128
return [
132129
'namespaces' => $this->namespaces,
133-
'nodeTypes' => $this->nodeTypes,
130+
'nodeTypes' => $this->nodeTypes,
134131
];
135132
}
136133

@@ -350,7 +347,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType)
350347
// Next token is '<' and two token later it's not '=', i.e. not '<ident='
351348
$next1 = $this->tokenQueue->peek();
352349
$next2 = $this->tokenQueue->peek(2);
353-
if ($next1 && $next1->getData() === '<' && (!$next2 || $next2->getData() !== '=')) {
350+
if ($next1 && '<' === $next1->getData() && (!$next2 || '=' !== $next2->getData())) {
354351
$this->parseValueConstraints($property);
355352
}
356353
}
@@ -678,21 +675,21 @@ protected function parseCndString()
678675
$type = $token->getType();
679676
$data = $token->getData();
680677

681-
if ($type === Token::TK_STRING) {
678+
if (Token::TK_STRING === $type) {
682679
$string = substr($data, 1, -1);
683680
$this->tokenQueue->next();
684681

685682
return $string;
686683
}
687684

688685
// If it's not an identifier or a symbol allowed in a string, break
689-
if ($type !== Token::TK_IDENTIFIER && $type !== Token::TK_SYMBOL
690-
|| ($type === Token::TK_SYMBOL && $data !== '_' && $data !== ':')) {
686+
if (Token::TK_IDENTIFIER !== $type && Token::TK_SYMBOL !== $type
687+
|| (Token::TK_SYMBOL === $type && '_' !== $data && ':' !== $data)) {
691688
break;
692689
}
693690

694691
// Detect spaces (an identifier cannot be followed by an identifier as it would have been read as a single token)
695-
if ($type === Token::TK_IDENTIFIER && $lastType === Token::TK_IDENTIFIER) {
692+
if (Token::TK_IDENTIFIER === $type && Token::TK_IDENTIFIER === $lastType) {
696693
break;
697694
}
698695

@@ -702,7 +699,7 @@ protected function parseCndString()
702699
$lastType = $type;
703700
}
704701

705-
if ($string === '') {
702+
if ('' === $string) {
706703
throw new ParserException($this->tokenQueue, sprintf("Expected CND string, found '%s': ", $this->tokenQueue->peek()->getData()));
707704
}
708705

@@ -752,10 +749,10 @@ protected function parseQueryOperator()
752749

753750
switch ($data) {
754751
case '<':
755-
$op = ($nextData === '>' ? '>=' : ($nextData === '=' ? '<=' : '<'));
752+
$op = ('>' === $nextData ? '>=' : ('=' === $nextData ? '<=' : '<'));
756753
break;
757754
case '>':
758-
$op = ($nextData === '=' ? '>=' : '>');
755+
$op = ('=' === $nextData ? '>=' : '>');
759756
break;
760757
case '=':
761758
$op = '=';
@@ -766,9 +763,9 @@ protected function parseQueryOperator()
766763
}
767764

768765
// Consume the correct number of tokens
769-
if ($op === 'LIKE' || strlen($op) === 1) {
766+
if ('LIKE' === $op || 1 === strlen($op)) {
770767
$this->tokenQueue->next();
771-
} elseif (strlen($op) === 2) {
768+
} elseif (2 === strlen($op)) {
772769
$this->tokenQueue->next();
773770
$this->tokenQueue->next();
774771
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function currentChar()
115115
public function isEof()
116116
{
117117
$currentChar = $this->currentChar();
118+
118119
// substr after end of string returned false in PHP 5 and returns '' since PHP 7
119120
return in_array($currentChar, [$this->getEofMarker(), false, ''], true)
120121
|| $this->startPos > strlen($this->buffer)
@@ -129,12 +130,12 @@ public function isEof()
129130
public function forward()
130131
{
131132
if ($this->forwardPos < strlen($this->buffer)) {
132-
$this->forwardPos++;
133-
$this->nextCurCol++;
133+
++$this->forwardPos;
134+
++$this->nextCurCol;
134135
}
135136

136-
if ($this->current() === "\n") {
137-
$this->nextCurLine++;
137+
if ("\n" === $this->current()) {
138+
++$this->nextCurLine;
138139
$this->nextCurCol = 1;
139140
}
140141

src/PHPCR/Util/CND/Scanner/AbstractScanner.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public function resetQueue()
3030
}
3131

3232
/**
33-
* @param Token $token
34-
*
3533
* @return Token|void
3634
*/
3735
public function applyFilters(Token $token)

src/PHPCR/Util/CND/Scanner/Context/ScannerContext.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ public function getWhitespaces()
143143
return $this->whitespaces;
144144
}
145145

146-
/**
147-
* @param TokenFilterInterface $filter
148-
*/
149146
public function addTokenFilter(TokenFilterInterface $filter)
150147
{
151148
$this->tokenFilters[] = $filter;

0 commit comments

Comments
 (0)