Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"require": {
"php": "^7.1 || 8.0.*",
"php": "^7.1 || ^8.0",
"ext-json": "*",
"ext-pdo": "*"
},
Expand Down
26 changes: 13 additions & 13 deletions lib/MC/Google/Visualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function handleQuery(string $query, array $params): string

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

if (!isset($query['select'])) {
//By default, return all fields defined for an entity
// By default, return all fields defined for an entity
$query['select'] = array_keys($entity['fields']);
}

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

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

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

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

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

$meta['query_fields'][] = $field;
}
}

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

Expand All @@ -996,7 +996,7 @@ protected function generateSQL(array &$meta): string
if (isset($meta['where'])) {
$where = [];
foreach ($meta['where'] as &$wherePart) {
//Replace field references with their SQL forms
// Replace field references with their SQL forms
switch ($wherePart['type']) {
case 'where_field':
$wherePart['value'] = $this->getFieldSQL($wherePart['value'], $meta['field_spec'][$wherePart['value']]);
Expand Down Expand Up @@ -1058,7 +1058,7 @@ protected function generateSQL(array &$meta): string
$first = true;
foreach ($meta['orderby'] as $field => $dir) {
if (isset($meta['field_spec'][$field]['sort_field'])) {
//An entity field can delegate sorting to another field by using the "sort_field" key
// An entity field can delegate sorting to another field by using the "sort_field" key
$field = $meta['field_spec'][$field]['sort_field'];
}
$spec = $meta['field_spec'][$field];
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/Parser/Def/NOrMore.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function _parse(string $str, int $loc): array
}

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

Expand Down
2 changes: 1 addition & 1 deletion lib/MC/Parser/Def/OneOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function _parse(string $str, int $loc): array
$res = $toks;
}
} catch (ParseError $parseError) {
//Ignore any non-matching conditions
// Ignore any non-matching conditions
}
}

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
8 changes: 4 additions & 4 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testQueryComplete(): void

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

//file_put_contents(__DIR__.'/result1.js', $output);
// file_put_contents(__DIR__.'/result1.js', $output);
self::assertStringEqualsFile(__DIR__.'/result1.js', $output);
}

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

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

//file_put_contents(__DIR__.'/result2.js', $output);
// file_put_contents(__DIR__.'/result2.js', $output);
self::assertStringEqualsFile(__DIR__.'/result2.js', $output);
}

Expand Down Expand Up @@ -111,13 +111,13 @@ public function testQueryJoins(): void
]);

$parameters = [
'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"',
'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"',
'tqx' => 'reqId:3',
];

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

//file_put_contents(__DIR__.'/result3.js', $output);
// file_put_contents(__DIR__.'/result3.js', $output);
self::assertStringEqualsFile(__DIR__.'/result3.js', $output);
}
}
2 changes: 1 addition & 1 deletion tests/result3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.