Skip to content

Commit 6eb0c38

Browse files
committed
Update compatibility up to PHP 8.4
1 parent c1985ee commit 6eb0c38

File tree

12 files changed

+38
-46
lines changed

12 files changed

+38
-46
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ on:
66

77
jobs:
88
tests:
9-
runs-on: ubuntu-22.04
9+
runs-on: ubuntu-24.04
1010
strategy:
1111
matrix:
12-
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
12+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1313
name: PHP ${{ matrix.php }}
1414
steps:
15-
- uses: actions/checkout@v3
16-
# required for "git tag" presence for MonorepoBuilder split and ChangelogLinker git tags resolver; default is 1
17-
- run: git fetch --depth=100000 origin
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 5
1818
# see https://github.com/shivammathur/setup-php
1919
- uses: shivammathur/setup-php@v2
2020
with:
@@ -25,10 +25,11 @@ jobs:
2525
- run: composer phpunit
2626

2727
tests_lowest_dependencies:
28-
runs-on: ubuntu-22.04
28+
runs-on: ubuntu-24.04
2929
steps:
30-
- uses: actions/checkout@v3
31-
- run: git fetch --depth=100000 origin
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 5
3233
# see https://github.com/shivammathur/setup-php
3334
- uses: shivammathur/setup-php@v2
3435
with:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"require-dev": {
3030
"friendsofphp/php-cs-fixer": "^3.0",
31-
"phpstan/phpstan": "^1.0",
31+
"phpstan/phpstan": "^1.4",
3232
"phpstan/phpstan-phpunit": "^1.0",
3333
"phpstan/phpstan-strict-rules": "^1.0",
3434
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"

lib/MC/Google/Visualization.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
use MC\Parser\Token;
1515
use PDO;
1616
use PDOException;
17+
use Tests\VisualizationTest;
1718

1819
/**
1920
* Provide a working implementation of the Google Visualization Query data source that works with a database
2021
* (or any other custom backend). The documentation for the query language itself and how to use it with Google
2122
* Visualizations can be found here: http://code.google.com/apis/visualization/documentation/querylanguage.html.
2223
*
23-
* @see \Tests\VisualizationTest
24+
* @see VisualizationTest
2425
*
2526
* @phpstan-type FieldSpec array{
2627
* type: string,
@@ -106,10 +107,8 @@ class Visualization
106107
* Create a new instance. This must be done before the library can be used. Pass in a PDO connection and
107108
* dialect if MC_Google_Visualization will handle the entire request cycle.
108109
*
109-
* @param null|PDO $db the database connection to use
110-
* @param string $dialect the SQL dialect to use - one of "mysql", "postgres", or "sqlite"
111-
*
112-
* @phpstan-param 'mysql'|'postgres'|'sqlite' $dialect
110+
* @param null|PDO $db the database connection to use
111+
* @param 'mysql'|'postgres'|'sqlite' $dialect the SQL dialect to use
113112
*
114113
* @throws Visualization_Error
115114
*/
@@ -140,9 +139,7 @@ public function setDB(?PDO $db = null): void
140139
/**
141140
* Set the dialect to use when generating SQL statements.
142141
*
143-
* @param string $dialect one of "mysql", "postgres", or "sqlite"
144-
*
145-
* @phpstan-param 'mysql'|'postgres'|'sqlite' $dialect
142+
* @param 'mysql'|'postgres'|'sqlite' $dialect the SQL dialect to use
146143
*
147144
* @throws Visualization_Error
148145
*/
@@ -158,11 +155,8 @@ public function setSqlDialect(string $dialect): void
158155
/**
159156
* Change the default format string to use for a particular data type.
160157
*
161-
* @param string $type the data type to change - one of "date", "datetime", "time", "boolean", or "number"
162-
*
163-
* @phpstan-param 'date'|'datetime'|'time'|'boolean'|'number' $type
164-
*
165-
* @param string $format the format string to use for the data type
158+
* @param string $format the format string to use for the data type
159+
* @param 'boolean'|'date'|'datetime'|'number'|'time' $type the data type to change
166160
*
167161
* @throws Visualization_Error
168162
*/
@@ -582,7 +576,7 @@ public function getRowValues(array $row, array $meta): string
582576
$time = strtotime($year.'0104 +'.$week.' weeks');
583577
assert(false !== $time);
584578
$monday = strtotime('-'.((int) date('w', $time) - 1).' days', $time);
585-
assert(false !== $monday); // @phpstan-ignore-line ; PHP < 8.0
579+
assert(false !== $monday);
586580
[$year, $month, $day] = explode('-', date('Y-m-d', $monday));
587581
$formatted = date($format, $monday);
588582
} else {
@@ -737,7 +731,7 @@ public function getGrammar(): Def
737731
*
738732
* @throws ParseError
739733
* @throws Visualization_QueryError
740-
* @throws Parser\DefError
734+
* @throws DefError
741735
*/
742736
public function parseQuery(string $str): array
743737
{
@@ -887,7 +881,7 @@ public function parseQuery(string $str): array
887881
*
888882
* @return string the string to output that will cause the visualization client to detect an error
889883
*/
890-
protected function handleError(int $reqid, string $detailMsg, string $handler = 'google.visualization.Query.setResponse', string $code = 'error', string $summaryMsg = null): string
884+
protected function handleError(int $reqid, string $detailMsg, string $handler = 'google.visualization.Query.setResponse', string $code = 'error', ?string $summaryMsg = null): string
891885
{
892886
if (null === $summaryMsg) {
893887
$summaryMsg = $detailMsg;
@@ -1013,7 +1007,7 @@ protected function generateSQL(array &$meta): string
10131007
$stmt = $this->db->query($pivotSql);
10141008
assert(false !== $stmt);
10151009
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
1016-
assert(false !== $rows); // @phpstan-ignore-line ; PHP < 8.0
1010+
assert(false !== $rows);
10171011
foreach ($rows as $row) {
10181012
// Create a version of all function-ed fields for each unique combination of pivot values
10191013
foreach ($funcFields as $field) {
@@ -1292,7 +1286,7 @@ protected function getFieldQuote(): string
12921286
*
12931287
* @return string the SQL string for this field, with an op
12941288
*/
1295-
protected function getFieldSQL(string $name, array $spec, bool $alias = false, string $func = null, array $pivot = null, array $pivotFields = null): string
1289+
protected function getFieldSQL(string $name, array $spec, bool $alias = false, ?string $func = null, ?array $pivot = null, ?array $pivotFields = null): string
12961290
{
12971291
$sql = $spec['field'];
12981292
$q = $this->getFieldQuote();
@@ -1360,7 +1354,7 @@ protected function addDependantCallbackFields(array $fieldSpec, array $entity, a
13601354
* @param Token $token the token or token group to recursively parse
13611355
* @param null|array $fields the collector array reference to receive the flattened select field values
13621356
*/
1363-
protected function parseFieldTokens(Token $token, array &$fields = null): void
1357+
protected function parseFieldTokens(Token $token, ?array &$fields = null): void
13641358
{
13651359
if ('*' === $token->value) {
13661360
return;
@@ -1392,7 +1386,7 @@ protected function parseFieldTokens(Token $token, array &$fields = null): void
13921386
* @param Token $token the token or token group to parse
13931387
* @param null|array<array{type: string, value: string}> $where the collector array of tokens that make up the where clause
13941388
*/
1395-
protected function parseWhereTokens(Token $token, array &$where = null): void
1389+
protected function parseWhereTokens(Token $token, ?array &$where = null): void
13961390
{
13971391
if (!is_array($where)) {
13981392
$where = [];

lib/MC/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
use MC\Parser\Def\Set;
1515
use MC\Parser\Def\Word;
1616
use MC\Parser\DefError;
17+
use Tests\ParserTest;
1718

1819
/**
1920
* Parser-generator class with an easy PHP-based API, similar to the pyparsing module in philosophy.
2021
*
21-
* @see \Tests\ParserTest
22+
* @see ParserTest
2223
*/
2324
class Parser
2425
{
@@ -48,7 +49,7 @@ public function oneOf(Def ...$args): OneOf
4849
/**
4950
* Return a Word that matches a set of possible characters not separated by whitespace.
5051
*/
51-
public function word(string $firstChars, string $restChars = null): Word
52+
public function word(string $firstChars, ?string $restChars = null): Word
5253
{
5354
return new Word($firstChars, $restChars);
5455
}

lib/MC/Parser/Def.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ public function parsePart(string $str, int $loc): array
4646
{
4747
[$loc, $tok] = $this->_parse($str, $loc);
4848

49-
$char = @$str[$loc++];
50-
while (('' !== $char) && Parser::isWhitespace($char)) {
51-
$char = @$str[$loc++];
52-
}
53-
--$loc;
49+
for (; ($loc < strlen($str)) && Parser::isWhitespace($str[$loc]); ++$loc);
5450

5551
return [$loc, $tok];
5652
}

lib/MC/Parser/Def/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Regex extends Def
2929
/** @var int */
3030
public $retgroup = 0;
3131

32-
public function __construct(string $regex = null, string $flags = null, string $errstr = null)
32+
public function __construct(?string $regex = null, ?string $flags = null, ?string $errstr = null)
3333
{
3434
if (null !== $regex) {
3535
$this->regex = $regex;

lib/MC/Parser/Def/Word.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Word extends Regex
1313
* @param string $firstChars the characters allowed as the first character in the word
1414
* @param null|string $restChars the characters allowed as the rest of the word - defaults to same as $first_chars
1515
*/
16-
public function __construct(string $firstChars, string $restChars = null)
16+
public function __construct(string $firstChars, ?string $restChars = null)
1717
{
1818
parent::__construct();
1919

lib/MC/Parser/DefError.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace MC\Parser;
66

7-
class DefError extends Error
8-
{
9-
}
7+
class DefError extends Error {}

lib/MC/Parser/Error.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use Exception;
88

9-
class Error extends Exception
10-
{
11-
}
9+
class Error extends Exception {}

phpstan.neon

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

0 commit comments

Comments
 (0)