Skip to content

Commit 2ce3dde

Browse files
committed
Add PHPStan at level 2
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent fa8b1dd commit 2ce3dde

File tree

10 files changed

+34
-5
lines changed

10 files changed

+34
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ coverage.xml
1010
phpunit.xml
1111
phpcs.xml
1212
/.phpunit.result.cache
13+
phpstan.neon

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"require-dev": {
2323
"phpmyadmin/coding-standard": "^1.0",
2424
"phpmyadmin/motranslator": "^4.0",
25+
"phpstan/extension-installer": "^1.0",
26+
"phpstan/phpstan": "^0.12.3",
27+
"phpstan/phpstan-phpunit": "^0.12.1",
2528
"phpunit/php-code-coverage": "*",
2629
"phpunit/phpunit": "^7.4 || ^8"
2730
},

phpstan.neon.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: 2
3+
paths:
4+
- src
5+
- tests
6+
- bin
7+
reportUnmatchedIgnoredErrors: true
8+
inferPrivatePropertyTypeFromConstructor: true
9+
ignoreErrors:
10+
- '#Unsafe usage of new static\(\)\.#'

src/Components/GroupKeyword.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
class GroupKeyword extends Component
1818
{
19+
public $type;
20+
1921
/**
2022
* The expression that is used for grouping.
2123
*

src/Components/IndexHint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class IndexHint extends Component
4848
* @param string $type the type of hint (USE/FORCE/IGNORE)
4949
* @param string $indexOrKey What the hint is for (INDEX/KEY)
5050
* @param string $for the clause for which this hint is (JOIN/ORDER BY/GROUP BY)
51-
* @param string $indexes List of indexes in this hint
51+
* @param array $indexes List of indexes in this hint
5252
*/
5353
public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = [])
5454
{
@@ -168,8 +168,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
168168
}
169169

170170
/**
171-
* @param ArrayObj|ArrayObj[] $component the component to be built
172-
* @param array $options parameters for building
171+
* @param IndexHint|IndexHint[] $component the component to be built
172+
* @param array $options parameters for building
173173
*
174174
* @return string
175175
*/

src/Components/LockExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class LockExpression extends Component
3535
* @param TokensList $list the list of tokens that are being parsed
3636
* @param array $options parameters for parsing
3737
*
38-
* @return CaseExpression
38+
* @return LockExpression
3939
*/
4040
public static function parse(Parser $parser, TokensList $list, array $options = [])
4141
{

src/Utils/Error.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace PhpMyAdmin\SqlParser\Utils;
88

9+
use PhpMyAdmin\SqlParser\Exceptions\LexerException;
10+
use PhpMyAdmin\SqlParser\Exceptions\ParserException;
911
use PhpMyAdmin\SqlParser\Lexer;
1012
use PhpMyAdmin\SqlParser\Parser;
1113

@@ -32,6 +34,7 @@ public static function get($objs)
3234

3335
foreach ($objs as $obj) {
3436
if ($obj instanceof Lexer) {
37+
/** @var LexerException $err */
3538
foreach ($obj->errors as $err) {
3639
$ret[] = [
3740
$err->getMessage(),
@@ -41,6 +44,7 @@ public static function get($objs)
4144
];
4245
}
4346
} elseif ($obj instanceof Parser) {
47+
/** @var ParserException $err */
4448
foreach ($obj->errors as $err) {
4549
$ret[] = [
4650
$err->getMessage(),

tests/Components/ArrayObjTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace PhpMyAdmin\SqlParser\Tests\Components;
55

66
use PhpMyAdmin\SqlParser\Components\ArrayObj;
7+
use PhpMyAdmin\SqlParser\Components\Expression;
78
use PhpMyAdmin\SqlParser\Parser;
89
use PhpMyAdmin\SqlParser\Tests\TestCase;
910

@@ -27,12 +28,14 @@ public function testParseType()
2728
new Parser(),
2829
$this->getTokensList('(1 + 2, 3 + 4)'),
2930
[
30-
'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression',
31+
'type' => Expression::class,
3132
'typeOptions' => [
3233
'breakOnParentheses' => true,
3334
],
3435
]
3536
);
37+
$this->assertInstanceOf(Expression::class, $components[0]);
38+
$this->assertInstanceOf(Expression::class, $components[1]);
3639
$this->assertEquals($components[0]->expr, '1 + 2');
3740
$this->assertEquals($components[1]->expr, '3 + 4');
3841
}

tests/Components/CreateDefinitionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use PhpMyAdmin\SqlParser\Components\CreateDefinition;
77
use PhpMyAdmin\SqlParser\Parser;
8+
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
89
use PhpMyAdmin\SqlParser\Tests\TestCase;
910

1011
class CreateDefinitionTest extends TestCase
@@ -59,6 +60,7 @@ public function testBuild()
5960
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
6061
') ENGINE=InnoDB"'
6162
);
63+
$this->assertInstanceOf(CreateStatement::class, $parser->statements[0]);
6264
$this->assertEquals(
6365
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
6466
CreateDefinition::build($parser->statements[0]->fields[1])
@@ -75,6 +77,7 @@ public function testBuild2()
7577
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
7678
') ENGINE=InnoDB"'
7779
);
80+
$this->assertInstanceOf(CreateStatement::class, $parser->statements[0]);
7881
$this->assertEquals(
7982
'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
8083
CreateDefinition::build($parser->statements[0]->fields[2])

tests/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace PhpMyAdmin\SqlParser\Tests;
88

9+
use PhpMyAdmin\SqlParser\Exceptions\LexerException;
10+
use PhpMyAdmin\SqlParser\Exceptions\ParserException;
911
use PhpMyAdmin\SqlParser\Lexer;
1012
use PhpMyAdmin\SqlParser\Parser;
1113
use PhpMyAdmin\SqlParser\TokensList;
@@ -42,6 +44,7 @@ public function getTokensList($query)
4244
public function getErrorsAsArray($obj)
4345
{
4446
$ret = [];
47+
/** @var LexerException|ParserException $err */
4548
foreach ($obj->errors as $err) {
4649
$ret[] = $obj instanceof Lexer
4750
? [

0 commit comments

Comments
 (0)