Skip to content

Commit 02f1a73

Browse files
authored
chore: add phpstan static analysis (googleapis#5931)
1 parent b5e09c2 commit 02f1a73

27 files changed

Lines changed: 124 additions & 36 deletions

‎.github/workflows/lint.yaml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ jobs:
1717
uses: shivammathur/setup-php@v2
1818
with:
1919
php-version: '8.0'
20-
- name: "Install dependencies"
20+
- name: Install Dependencies
2121
run: composer global require "squizlabs/php_codesniffer:3.*"
2222
- name: Run PHPCS Code Style Checker
2323
run: ~/.composer/vendor/bin/phpcs --standard=phpcs-ruleset.xml -p
24+
staticanalysis:
25+
runs-on: ubuntu-latest
26+
name: PHPStan Static Analysis
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: Install PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: '8.1'
33+
- name: "Install dependencies"
34+
run: |
35+
composer --no-interaction --no-ansi --no-progress update
36+
composer --no-interaction --no-ansi --no-progress update -d dev
37+
- name: Run Static Analysis
38+
run: |
39+
dev/sh/static-analysis

‎.github/workflows/tests.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
vendor/bin/phpunit -c phpunit-snippets.xml.dist --verbose
6969
70-
test_package:
70+
test_packages:
7171
name: Package Tests
7272
runs-on: ubuntu-latest
7373
steps:

‎BigQueryStorage/metadata/descriptor_fix.php‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,38 @@
2424
* This file can be removed once a fix is implemented in the protobuf library
2525
* @see https://github.com/protocolbuffers/protobuf/issues/11649
2626
*/
27-
namespace GPBMetadata\Google\Protobuf;
27+
namespace GPBMetadata\Google\Protobuf {
2828

29-
class DescriptorFix
30-
{
31-
public static $is_initialized = false;
29+
class DescriptorFix
30+
{
31+
public static $is_initialized = false;
3232

33-
public static function initOnce() {
34-
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
33+
public static function initOnce() {
34+
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
3535

36-
if (static::$is_initialized == true) {
37-
return;
38-
}
36+
if (static::$is_initialized == true) {
37+
return;
38+
}
3939

40-
if ($pool instanceof \Google\Protobuf\Internal\DescriptorPool) {
41-
// add a no-op reference for "google.protobuf.DescriptorProto"
42-
$pool->addMessage('google.protobuf.DescriptorProto', \Google\Protobuf\Internal\Message::class)->finalizeToPool();
40+
if ($pool instanceof \Google\Protobuf\Internal\DescriptorPool) {
41+
// add a no-op reference for "google.protobuf.DescriptorProto"
42+
$pool->addMessage('google.protobuf.DescriptorProto', \Google\Protobuf\DescriptorProto::class)->finalizeToPool();
43+
}
44+
static::$is_initialized = true;
4345
}
44-
static::$is_initialized = true;
4546
}
47+
48+
DescriptorFix::initOnce();
4649
}
4750

48-
DescriptorFix::initOnce();
51+
namespace Google\Protobuf {
52+
53+
class DescriptorProto
54+
{
55+
public function __construct()
56+
{
57+
throw new \LogicException('Proto2 classes are not supported');
58+
}
59+
}
60+
}
4961

‎Core/src/ClientTrait.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ private function detectProjectId(array $config)
233233
'and we were unable to detect a default project ID.'
234234
);
235235
}
236+
237+
return '';
236238
}
237239

238240
/**

‎Core/src/GrpcTrait.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ private function formatValueForApi($value)
238238

239239
return ['list_value' => $this->formatListForApi($value)];
240240
}
241+
242+
return [];
241243
}
242244

243245
/**

‎Core/src/Lock/SymfonyLockAdapter.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/**
2323
* Symfony lock component adapter.
24+
* @deprecated
2425
*/
2526
class SymfonyLockAdapter implements LockInterface
2627
{

‎Deploy/owlbot.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
'')
4949

5050

51-
52-
5351
### [START] protoc backwards compatibility fixes
5452

5553
# roll back to private properties.

‎Firestore/src/DocumentReference.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ function ($collectionId) {
415415
*/
416416
protected function batchFactory()
417417
{
418-
return new WriteBatch(
418+
if (!class_exists(WriteBatch::class)) {
419+
class_alias(BulkWriter::class, WriteBatch::class);
420+
}
421+
return new BulkWriter(
419422
$this->connection,
420423
$this->valueMapper,
421424
$this->databaseFromName($this->name)

‎Firestore/src/FirestoreClient.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ public function __construct(array $config = [])
175175
*/
176176
public function batch()
177177
{
178-
return new WriteBatch(
178+
if (!class_exists(WriteBatch::class)) {
179+
class_alias(BulkWriter::class, WriteBatch::class);
180+
}
181+
return new BulkWriter(
179182
$this->connection,
180183
$this->valueMapper,
181184
$this->databaseName(

‎Scheduler/owlbot.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
# Fix missing formatting method
4343
s.replace(
4444
'src/V1/Gapic/CloudSchedulerGapicClient.php',
45-
r"private static \$jobNameTemplate;\n\s{4}private static \$locationNameTemplate;",
45+
r"private static \$jobNameTemplate;\n\n\s{4}private static \$locationNameTemplate;",
4646
"""private static $jobNameTemplate;
4747
private static $locationNameTemplate;
48+
4849
private static $projectNameTemplate;"""
4950
)
5051
s.replace(

0 commit comments

Comments
 (0)