Skip to content

Commit d027eed

Browse files
staabmclxmstaab
andauthored
fix cs (#83)
Co-authored-by: Markus Staab <[email protected]>
1 parent 384cb77 commit d027eed

7 files changed

+30
-37
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
])
88
->append([
99
__FILE__,
10+
__DIR__.'/bootstrap.php',
1011
])
1112
;
1213

bootstrap.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
43
use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector;
54
use staabm\PHPStanDba\QueryReflection\QueryReflection;
65
use staabm\PHPStanDba\QueryReflection\RecordingQueryReflector;
7-
use staabm\PHPStanDba\QueryReflection\ReplayQueryReflector;
86
use staabm\PHPStanDba\QueryReflection\ReflectionCache;
7+
use staabm\PHPStanDba\QueryReflection\ReplayQueryReflector;
8+
use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration;
99

10-
require_once __DIR__ . '/vendor/autoload.php';
10+
require_once __DIR__.'/vendor/autoload.php';
1111

1212
// we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs.
1313
// in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file.
@@ -18,36 +18,35 @@
1818
}
1919

2020
try {
21-
if (false !== getenv('GITHUB_ACTION')) {
22-
$mysqli = @new mysqli('127.0.0.1', 'root', 'root', 'phpstan_dba');
23-
} else {
24-
$mysqli = new mysqli('mysql80.ab', 'testuser', 'test', 'phpstan_dba');
25-
}
21+
if (false !== getenv('GITHUB_ACTION')) {
22+
$mysqli = @new mysqli('127.0.0.1', 'root', 'root', 'phpstan_dba');
23+
} else {
24+
$mysqli = new mysqli('mysql80.ab', 'testuser', 'test', 'phpstan_dba');
25+
}
2626

27-
$reflector = new MysqliQueryReflector($mysqli);
27+
$reflector = new MysqliQueryReflector($mysqli);
2828
$reflector = new RecordingQueryReflector(
2929
ReflectionCache::create(
3030
$cacheFile
3131
),
3232
$reflector
3333
);
34-
3534
} catch (mysqli_sql_exception $e) {
36-
if ($e->getCode() !== MysqliQueryReflector::MYSQL_HOST_NOT_FOUND) {
37-
throw $e;
38-
}
39-
40-
echo "\nWARN: Could not connect to MySQL.\nUsing cached reflection.\n";
41-
42-
// when we can't connect to the database, we rely on replaying pre-recorded db-reflection information
43-
$reflector = new ReplayQueryReflector(
44-
ReflectionCache::load(
45-
$cacheFile
46-
)
47-
);
35+
if (MysqliQueryReflector::MYSQL_HOST_NOT_FOUND !== $e->getCode()) {
36+
throw $e;
37+
}
38+
39+
echo "\nWARN: Could not connect to MySQL.\nUsing cached reflection.\n";
40+
41+
// when we can't connect to the database, we rely on replaying pre-recorded db-reflection information
42+
$reflector = new ReplayQueryReflector(
43+
ReflectionCache::load(
44+
$cacheFile
45+
)
46+
);
4847
}
4948

5049
QueryReflection::setupReflector(
51-
$reflector,
52-
RuntimeConfiguration::create()->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION)
50+
$reflector,
51+
RuntimeConfiguration::create()->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION)
5352
);

src/PdoReflection/PdoStatementReflection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
final class PdoStatementReflection
1818
{
1919
/**
20-
* Do not change, part of internal PHPStan naming
20+
* Do not change, part of internal PHPStan naming.
2121
*
2222
* @var string
2323
*/
2424
private const PREVIOUS = 'previous';
2525

2626
/**
27-
* Convention key name in php-parser and PHPStan for parent node
27+
* Convention key name in php-parser and PHPStan for parent node.
2828
*
2929
* @var string
3030
*/
3131
private const PARENT = 'parent';
3232

33-
3433
private NodeFinder $nodeFinder;
3534

3635
public function __construct()

src/Rules/SyntaxErrorInPreparedStatementMethodRule.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
namespace staabm\PHPStanDba\Rules;
66

7-
use PDOStatement;
87
use PhpParser\Node;
98
use PhpParser\Node\Expr\MethodCall;
109
use PHPStan\Analyser\Scope;
11-
use PHPStan\Reflection\MethodReflection;
1210
use PHPStan\Rules\Rule;
1311
use PHPStan\Rules\RuleError;
1412
use PHPStan\Rules\RuleErrorBuilder;
15-
use PHPStan\ShouldNotHappenException;
16-
use staabm\PHPStanDba\PdoReflection\PdoStatementReflection;
1713
use staabm\PHPStanDba\QueryReflection\QueryReflection;
1814

1915
/**
@@ -76,7 +72,7 @@ private function checkErrors(MethodCall $methodCall, Scope $scope): array
7672
{
7773
$args = $methodCall->getArgs();
7874

79-
if (count($args) < 2) {
75+
if (\count($args) < 2) {
8076
return [];
8177
}
8278

@@ -92,7 +88,7 @@ private function checkErrors(MethodCall $methodCall, Scope $scope): array
9288
$error = $queryReflection->validateQueryString($queryString);
9389
if (null !== $error) {
9490
return [
95-
RuleErrorBuilder::message('Query error: ' . $error->getMessage() . ' (' . $error->getCode() . ').')->line($methodCall->getLine())->build()
91+
RuleErrorBuilder::message('Query error: '.$error->getMessage().' ('.$error->getCode().').')->line($methodCall->getLine())->build(),
9692
];
9793
}
9894

src/Rules/SyntaxErrorInQueryFunctionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function processNode(Node $node, Scope $scope): array
8181
$error = $queryReflection->validateQueryString($queryString);
8282
if (null !== $error) {
8383
return [
84-
RuleErrorBuilder::message('Query error: '.$error->getMessage().' ('.$error->getCode().').')->line($node->getLine())->build()
84+
RuleErrorBuilder::message('Query error: '.$error->getMessage().' ('.$error->getCode().').')->line($node->getLine())->build(),
8585
];
8686
}
8787

src/Rules/SyntaxErrorInQueryMethodRule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ public function processNode(Node $node, Scope $scope): array
7373
$error = $queryReflection->validateQueryString($queryString);
7474
if (null !== $error) {
7575
return [
76-
RuleErrorBuilder::message('Query error: '.$error->getMessage().' ('.$error->getCode().').')->line($node->getLine())->build()
76+
RuleErrorBuilder::message('Query error: '.$error->getMessage().' ('.$error->getCode().').')->line($node->getLine())->build(),
7777
];
78-
7978
}
8079

8180
return [];

tests/SyntaxErrorInPreparedStatementMethodRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Rules\Rule;
66
use staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule;
7-
use staabm\PHPStanDba\Rules\SyntaxErrorInQueryFunctionRule;
87
use Symplify\PHPStanExtensions\Testing\AbstractServiceAwareRuleTestCase;
98

109
/**

0 commit comments

Comments
 (0)