Skip to content

Commit

Permalink
Allow PHP 7.2 (#511)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Staab <markus.staab@redaxo.de>
  • Loading branch information
TomasVotruba and staabm authored Feb 16, 2023
1 parent ff4eac0 commit 0b6d95e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 41 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/php-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PHP Linter

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
php-linter:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- uses: actions/checkout@v2
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none # disable xdebug, pcov

- name: Composer install
uses: ramsey/composer-install@v2
with:
composer-options: --ansi --prefer-dist

- name: Lint PHP
run: vendor/bin/parallel-lint src tests config
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"keywords": ["dev", "phpstan", "phpstan-extension", "static analysis", "database access layer", "code quality"],
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.2 || ^8.0",
"composer-runtime-api": "^2.0",
"composer/semver": "^3.2",
"phpstan/phpstan": "^1.5.6"
Expand All @@ -13,14 +13,14 @@
"ext-mysqli": "*",
"ext-pdo": "*",
"dibi/dibi": "^4.2",
"doctrine/dbal": "^3.2",
"doctrine/dbal": "^2.13|^3.0",
"friendsofphp/php-cs-fixer": "3.4.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^8.5|^9.5",
"tomasvotruba/unused-public": "^0.0.34",
"vlucas/phpdotenv": "^5.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/MysqliQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function inferResultType(Expr $queryExpr, Scope $scope): ?Type
if (!QueryReflection::getRuntimeConfiguration()->throwsMysqliExceptions($this->phpVersion)) {
return TypeCombinator::union(
$resultType,
new ConstantBooleanType(false),
new ConstantBooleanType(false)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/PdoQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
$defaultReturn = ParametersAcceptorSelector::selectFromArgs(
$scope,
$methodCall->getArgs(),
$methodReflection->getVariants(),
$methodReflection->getVariants()
)->getReturnType();

if (QueryReflection::getRuntimeConfiguration()->throwsPdoExceptions($this->phpVersion)) {
Expand Down
4 changes: 2 additions & 2 deletions src/QueryReflection/PdoPgSqlQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ protected function checkInformationSchema(string $tableName): Iterator
{
if (null === $this->stmt) {
$this->stmt = $this->pdo->prepare(
<<<'PSQL'
<<<'PSQL'
SELECT column_name, column_default, is_nullable
FROM information_schema.columns
WHERE table_name = ?
PSQL
PSQL
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function create(string $cacheDir): QueryReflector
$cacheFile = sprintf(
'%s/.phpunit-phpstan-dba-%s.cache',
$cacheDir,
$reflector,
$reflector
);
if (\defined('__PHPSTAN_RUNNING__')) {
$cacheFile = $cacheDir.'/.phpstan-dba-'.$reflector.'.cache';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,28 @@ public function getExpectedErrors(): array
return [
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "with"
LINE 1: SELECT with syntax error GROUPY by x LIMIT 0
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "with"
LINE 1: SELECT with syntax error GROUPY by x LIMIT 0
^ (42601).
TEXT,
12,
],
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT,
<<<'TEXT'
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT
,
18,
],
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "FROM"
LINE 3: FROM ada LIMIT 0
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "FROM"
LINE 3: FROM ada LIMIT 0
^ (42601).
TEXT
,
20,
],
];
Expand Down
27 changes: 15 additions & 12 deletions tests/rules/SyntaxErrorInQueryFunctionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,29 @@ public function getExpectedErrors(): array
return [
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT
,
9,
],
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT
,
19,
],
[
<<<TEXT
Query error: SQLSTATE[42703]: Undefined column: 7 ERROR: column "asdsa" does not exist
LINE 1: ...mail, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=1 LI...
^ (42703).
TEXT,
Query error: SQLSTATE[42703]: Undefined column: 7 ERROR: column "asdsa" does not exist
LINE 1: ...mail, adaid, gesperrt, freigabe1u1 FROM ada WHERE asdsa=1 LI...
^ (42703).
TEXT
,
39,
],
];
Expand Down
18 changes: 10 additions & 8 deletions tests/rules/SyntaxErrorInQueryMethodSubclassedRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ public function getExpectedErrors(): array
return [
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "with"
LINE 1: SELECT with syntax error GROUPY by x LIMIT 0
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "with"
LINE 1: SELECT with syntax error GROUPY by x LIMIT 0
^ (42601).
TEXT
,
12,
],
[
<<<TEXT
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT,
Query error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "freigabe1u1"
LINE 1: SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada LIMIT...
^ (42601).
TEXT
,
18,
],
];
Expand Down

0 comments on commit 0b6d95e

Please sign in to comment.