Skip to content

Commit 2759f08

Browse files
authored
Merge pull request #92 from sasezaki/sfp-phpstan-psr-log-bigquery-schema-convert
Rename phpstan-type-mapping-from-bigquery to `sfp-phpstan-psr-log-bigquery-schema-convert`
2 parents 9b9a8cd + 99d8ef9 commit 2759f08

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

.laminas-ci.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
"php": "@latest",
2121
"command": "composer install -d example; diff <(./vendor/bin/phpstan analyse -c ./example/phpstan.enableContextTypeRule.neon --no-progress --error-format=junit | xmllint --format -) ./test/example.enableContextTypeRule.output"
2222
}
23+
},
24+
{
25+
"name": "sfp-phpstan-psr-log-bigquery-schema-convert",
26+
"job": {
27+
"php": "@latest",
28+
"command": "diff <(cat test/TypeProvider/data/bigQuerySchema.json | ./bin/sfp-phpstan-psr-log-bigquery-schema-convert) <(echo -n 'array{first_name?: string, product?: array{id?: string}, cancellation_reason?: (float | int | numeric-string), cancellation_date?: \\DateTimeInterface, exception?: \\Throwable}')"
29+
}
2330
}
2431
],
2532
"ignore_php_platform_requirements": {

bin/phpstan-type-mapping-from-bigquery renamed to bin/sfp-phpstan-psr-log-bigquery-schema-convert

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@ use Sfp\PHPStan\Psr\Log\TypeMapping\BigQuery\GenericTableFieldSchemaJsonPayloadT
88
use Sfp\PHPStan\Psr\Log\TypeProvider\BigQueryContextTypeProvider;
99

1010
/**
11-
* borrowed from doctrine/sql-formatter 's sql-formatter
11+
* This script provides converting BigQuery Schema Json to array shape type
12+
*
13+
* Usage Example:
14+
* `cat test/TypeProvider/data/bigQuerySchema.json | ./bin/sfp-phpstan-psr-log-bigquery-schema-convert`
15+
* will show
16+
* `array{first_name?: string, product?: array{id?: string}, cancellation_reason?: (float | int | numeric-string), cancellation_date?: \DateTimeInterface, exception?: \Throwable}`
17+
*
18+
* This part of the code is borrowed from doctrine/sql-formatter 's sql-formatter
1219
*/
1320

14-
if ('cli' !== php_sapi_name()) {
21+
if ('cli' !== PHP_SAPI) {
1522
echo "<p>Run this PHP script from the command line to see mapping BigQuery schema to PHPStan Type. It supports Unix pipes or command line argument style.</p>";
1623
exit;
1724
}
1825

1926
if (isset($argv[1])) {
2027
$schema = $argv[1];
2128
} else {
22-
$schema = stream_get_contents(fopen('php://stdin', 'r'));
29+
$stdin = fopen('php://stdin', 'r');
30+
assert(is_resource($stdin));
31+
$schema = stream_get_contents($stdin);
2332
}
2433

2534
$autoloadFiles = [
@@ -30,11 +39,12 @@ $autoloadFiles = [
3039
$rootDir = false;
3140
foreach ($autoloadFiles as $deps => $autoloadFile) {
3241
if (file_exists($autoloadFile)) {
33-
$rootDir = dirname($autoloadFile, $deps);
42+
$rootDir = dirname($autoloadFile, $deps);
3443
require_once $autoloadFile;
3544
break;
3645
}
3746
}
47+
assert(is_string($rootDir));
3848

3949
// bootstrap ReflectionProvider
4050
$containerFactory = new ContainerFactory($rootDir);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"dealerdirect/phpcodesniffer-composer-installer": true
4343
}
4444
},
45-
"bin": ["bin/phpstan-type-mapping-from-bigquery"],
45+
"bin": ["bin/sfp-phpstan-psr-log-bigquery-schema-convert"],
4646
"extra": {
4747
"phpstan": {
4848
"includes": [

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
55
>
66
<testsuites>
77
<testsuite name="sfp-phpstan-psr-log Test Suite">
88
<directory>./test/</directory>
99
</testsuite>
1010
</testsuites>
1111

12-
</phpunit>
12+
</phpunit>

0 commit comments

Comments
 (0)