|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration; |
4 | 3 | use staabm\PHPStanDba\QueryReflection\MysqliQueryReflector; |
5 | 4 | use staabm\PHPStanDba\QueryReflection\QueryReflection; |
6 | 5 | use staabm\PHPStanDba\QueryReflection\RecordingQueryReflector; |
7 | | -use staabm\PHPStanDba\QueryReflection\ReplayQueryReflector; |
8 | 6 | use staabm\PHPStanDba\QueryReflection\ReflectionCache; |
| 7 | +use staabm\PHPStanDba\QueryReflection\ReplayQueryReflector; |
| 8 | +use staabm\PHPStanDba\QueryReflection\RuntimeConfiguration; |
9 | 9 |
|
10 | | -require_once __DIR__ . '/vendor/autoload.php'; |
| 10 | +require_once __DIR__.'/vendor/autoload.php'; |
11 | 11 |
|
12 | 12 | // we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs. |
13 | 13 | // in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file. |
|
18 | 18 | } |
19 | 19 |
|
20 | 20 | 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 | + } |
26 | 26 |
|
27 | | - $reflector = new MysqliQueryReflector($mysqli); |
| 27 | + $reflector = new MysqliQueryReflector($mysqli); |
28 | 28 | $reflector = new RecordingQueryReflector( |
29 | 29 | ReflectionCache::create( |
30 | 30 | $cacheFile |
31 | 31 | ), |
32 | 32 | $reflector |
33 | 33 | ); |
34 | | - |
35 | 34 | } 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 | + ); |
48 | 47 | } |
49 | 48 |
|
50 | 49 | QueryReflection::setupReflector( |
51 | | - $reflector, |
52 | | - RuntimeConfiguration::create()->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION) |
| 50 | + $reflector, |
| 51 | + RuntimeConfiguration::create()->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION) |
53 | 52 | ); |
0 commit comments