Skip to content

Commit 8fc2887

Browse files
committed
Adds/test compatibility with PHP 8.1.
1 parent bb09bdd commit 8fc2887

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
14+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
1515
name: PHP ${{ matrix.php }} tests
1616
steps:
1717
- uses: actions/checkout@v2

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"require": {
25-
"php": "^7.1 || 8.0.*",
25+
"php": "^7.1 || ^8.0",
2626
"ext-json": "*",
2727
"ext-pdo": "*"
2828
},

lib/MC/Google/Visualization.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function handleQuery(string $query, array $params): string
214214

215215
$stmt = $this->db->query($sql);
216216
assert(false !== $stmt);
217-
//If we got here, there's no errors
217+
// If we got here, there's no errors
218218
$response .= $this->getSuccessInit($meta);
219219
$first = true;
220220
foreach ($stmt as $row) {
@@ -272,11 +272,11 @@ public function generateMetadata(array $query): array
272272
}
273273

274274
if (!isset($query['select'])) {
275-
//By default, return all fields defined for an entity
275+
// By default, return all fields defined for an entity
276276
$query['select'] = array_keys($entity['fields']);
277277
}
278278

279-
//The query fields might be different from the "select" fields (callback dependant fields will not be returned)
279+
// The query fields might be different from the "select" fields (callback dependant fields will not be returned)
280280
$meta['query_fields'] = [];
281281
$meta['joins'] = [];
282282
$meta['field_spec'] = [];
@@ -313,7 +313,7 @@ public function generateMetadata(array $query): array
313313
$meta['select'] = $query['select'];
314314

315315
if (isset($query['where'])) {
316-
//Parse the where clauses and error out on non-existant and callback fields and add joins
316+
// Parse the where clauses and error out on non-existant and callback fields and add joins
317317
foreach ($query['where'] as $whereToken) {
318318
if ('where_field' === $whereToken['type']) {
319319
$field = $whereToken['value'];
@@ -334,7 +334,7 @@ public function generateMetadata(array $query): array
334334
}
335335
}
336336

337-
//Also add the joins & field spec information for the orderby, groupby, and pivot clauses
337+
// Also add the joins & field spec information for the orderby, groupby, and pivot clauses
338338
if (isset($query['pivot'])) {
339339
foreach ($query['pivot'] as $field) {
340340
if (!isset($entity['fields'][$field])) {
@@ -393,7 +393,7 @@ public function generateMetadata(array $query): array
393393
}
394394
}
395395

396-
//Some of the query information we just copy into the metadata array
396+
// Some of the query information we just copy into the metadata array
397397
$copyKeys = ['where', 'orderby', 'groupby', 'pivot', 'limit', 'offset', 'labels', 'formats', 'options'];
398398
foreach ($copyKeys as $copyKey) {
399399
if (isset($query[$copyKey])) {
@@ -544,7 +544,7 @@ public function getRowValues(array $row, array $meta): string
544544
$time = strtotime($year.'0104 +'.$week.' weeks');
545545
assert(false !== $time);
546546
$monday = strtotime('-'.((int) date('w', $time) - 1).' days', $time);
547-
assert(false !== $monday);
547+
assert(false !== $monday); // @phpstan-ignore-line ; PHP < 8.0
548548
[$year, $month, $day] = explode('-', date('Y-m-d', $monday));
549549
$formatted = date($format, $monday);
550550
} else {
@@ -927,7 +927,7 @@ protected function generateSQL(array &$meta): string
927927
}
928928

929929
if (isset($meta['pivot'])) {
930-
//Pivot queries are special - they require an entity to be passed and modify the query directly
930+
// Pivot queries are special - they require an entity to be passed and modify the query directly
931931
$entity = $meta['entity'];
932932
$pivotFields = [];
933933
$pivotJoins = [];
@@ -965,17 +965,17 @@ protected function generateSQL(array &$meta): string
965965
$stmt = $this->db->query($pivotSql);
966966
assert(false !== $stmt);
967967
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
968-
assert(is_array($rows));
968+
assert(false !== $rows); // @phpstan-ignore-line ; PHP < 8.0
969969
foreach ($rows as $row) {
970-
//Create a version of all function-ed fields for each unique combination of pivot values
970+
// Create a version of all function-ed fields for each unique combination of pivot values
971971
foreach ($funcFields as $field) {
972972
$field[2] = $row;
973973

974974
$meta['query_fields'][] = $field;
975975
}
976976
}
977977

978-
//For pivot queries, the fields we return and the fields we query against are always the same
978+
// For pivot queries, the fields we return and the fields we query against are always the same
979979
$meta['select'] = $meta['query_fields'];
980980
}
981981

@@ -996,7 +996,7 @@ protected function generateSQL(array &$meta): string
996996
if (isset($meta['where'])) {
997997
$where = [];
998998
foreach ($meta['where'] as &$wherePart) {
999-
//Replace field references with their SQL forms
999+
// Replace field references with their SQL forms
10001000
switch ($wherePart['type']) {
10011001
case 'where_field':
10021002
$wherePart['value'] = $this->getFieldSQL($wherePart['value'], $meta['field_spec'][$wherePart['value']]);
@@ -1058,7 +1058,7 @@ protected function generateSQL(array &$meta): string
10581058
$first = true;
10591059
foreach ($meta['orderby'] as $field => $dir) {
10601060
if (isset($meta['field_spec'][$field]['sort_field'])) {
1061-
//An entity field can delegate sorting to another field by using the "sort_field" key
1061+
// An entity field can delegate sorting to another field by using the "sort_field" key
10621062
$field = $meta['field_spec'][$field]['sort_field'];
10631063
}
10641064
$spec = $meta['field_spec'][$field];

lib/MC/Parser/Def/NOrMore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function _parse(string $str, int $loc): array
4343
}
4444

4545
if (0 === $toks->count()) {
46-
//If this token is empty, remove it from the result group
46+
// If this token is empty, remove it from the result group
4747
$toks = null;
4848
}
4949

lib/MC/Parser/Def/OneOf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function _parse(string $str, int $loc): array
3838
$res = $toks;
3939
}
4040
} catch (ParseError $parseError) {
41-
//Ignore any non-matching conditions
41+
// Ignore any non-matching conditions
4242
}
4343
}
4444

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ includes:
44
- vendor/phpstan/phpstan-strict-rules/rules.neon
55
parameters:
66
checkMissingIterableValueType: false
7+
reportUnmatchedIgnoredErrors: false

tests/ExampleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testQueryComplete(): void
5757

5858
$output = $vis->handleRequest(false, $parameters);
5959

60-
//file_put_contents(__DIR__.'/result1.js', $output);
60+
// file_put_contents(__DIR__.'/result1.js', $output);
6161
self::assertStringEqualsFile(__DIR__.'/result1.js', $output);
6262
}
6363

@@ -82,7 +82,7 @@ public function testQuerySimple(): void
8282

8383
$output = $vis->handleRequest(false, $parameters);
8484

85-
//file_put_contents(__DIR__.'/result2.js', $output);
85+
// file_put_contents(__DIR__.'/result2.js', $output);
8686
self::assertStringEqualsFile(__DIR__.'/result2.js', $output);
8787
}
8888

@@ -111,13 +111,13 @@ public function testQueryJoins(): void
111111
]);
112112

113113
$parameters = [
114-
'tq' => 'select avg(life_male), avg(life_female), avg(life_both) from countries label life_male "Life Expectancy (Male)", life_female "Life Expectancy (Female)", life_both "Life Expectancy (Combined)" format life_male "%.2f years", life_female "%.2f years", life_both "%.2f years"',
114+
'tq' => 'select max(life_male), avg(life_female), min(life_both) from countries label life_male "Life Expectancy (Male)", life_female "Life Expectancy (Female)", life_both "Life Expectancy (Combined)" format life_male "%.2f years", life_female "%.2f years", life_both "%.2f years"',
115115
'tqx' => 'reqId:3',
116116
];
117117

118118
$output = $vis->handleRequest(false, $parameters);
119119

120-
//file_put_contents(__DIR__.'/result3.js', $output);
120+
// file_put_contents(__DIR__.'/result3.js', $output);
121121
self::assertStringEqualsFile(__DIR__.'/result3.js', $output);
122122
}
123123
}

tests/result3.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)