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
13 changes: 5 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.4"

services:
mysql:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
run: "composer update --no-interaction --no-progress --no-suggest --prefer-lowest"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c phpunit.mysql8.xml --coverage-clover=coverage.xml"
run: "vendor/bin/phpunit --no-coverage"

phpunit-code-coverage:
name: "PHPUnit with Code Coverage"
Expand All @@ -90,7 +90,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.4"

services:
mysql:
Expand Down Expand Up @@ -137,9 +137,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.1"
- "7.3"
- "7.4"
- "8.0"

services:
mysql:
Expand All @@ -161,7 +159,6 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
extensions: ""
coverage: "pcov"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
Expand All @@ -174,4 +171,4 @@ jobs:
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit"
run: "vendor/bin/phpunit --no-coverage"
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
}
],
"require": {
"php": ">=7.1.0",
"php": ">=7.4.0 || ^8.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is >=7.4.0, it is obviously compatible with ^8 :)

"mouf/utils.common.conditioninterface": "~2.0",
"mouf/utils.value.value-interface": "~1.0",
"mouf/utils.common.paginable-interface": "~1.0",
"mouf/utils.common.sortable-interface": "~1.0",
"mouf/schema-analyzer": "~1.0",
"twig/twig": "^2.11 || ^3",
"greenlion/php-sql-parser": "^4.1.2",
"greenlion/php-sql-parser": "^4.3",
"doctrine/cache": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "^7.5.10",
"phpunit/phpunit": "^9.5",
"satooshi/php-coveralls": "~1.0",
"doctrine/dbal": "~2.5",
"phpstan/phpstan": "^0.11.7"
"phpstan/phpstan": "^0.12.82"
},
"suggest": {
"doctrine/dbal": "To support more databases than just MySQL and to use MagicJoin feature",
Expand Down Expand Up @@ -67,6 +67,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon src"
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon"
}
}
197 changes: 197 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
parameters:
ignoreErrors:
-
message: "#^Method Mouf\\\\Database\\\\QueryWriter\\\\QueryResult\\:\\:val\\(\\) should return array but returns Mouf\\\\Database\\\\QueryWriter\\\\ResultSet\\.$#"
count: 1
path: src/Mouf/Database/QueryWriter/QueryResult.php

-
message: "#^Method Mouf\\\\Database\\\\QueryWriter\\\\Utils\\\\DbHelper\\:\\:getAll\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/Mouf/Database/QueryWriter/Utils/DbHelper.php

-
message: "#^Parameter \\#1 \\$rightOperand of method SQLParser\\\\Node\\\\AbstractInListOperator\\:\\:refactorParameterToExpression\\(\\) expects SQLParser\\\\Node\\\\NodeInterface, array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\|string given\\.$#"
count: 1
path: src/SQLParser/Node/AbstractInListOperator.php

-
message: "#^Cannot access offset 0 on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\.$#"
count: 1
path: src/SQLParser/Node/AbstractInListOperator.php

-
message: "#^Method SQLParser\\\\Node\\\\AbstractTwoOperandsOperator\\:\\:setLeftOperand\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/AbstractTwoOperandsOperator.php

-
message: "#^Method SQLParser\\\\Node\\\\AbstractTwoOperandsOperator\\:\\:setRightOperand\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/AbstractTwoOperandsOperator.php

-
message: "#^Cannot call method walk\\(\\) on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\|string\\.$#"
count: 2
path: src/SQLParser/Node/AbstractTwoOperandsOperator.php

-
message: "#^Method SQLParser\\\\Node\\\\Between\\:\\:setLeftOperand\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/Between.php

-
message: "#^Method SQLParser\\\\Node\\\\Between\\:\\:setMinValueOperand\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/Between.php

-
message: "#^Cannot call method walk\\(\\) on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\|string\\.$#"
count: 1
path: src/SQLParser/Node/Between.php

-
message: "#^Cannot call method walk\\(\\) on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\|string\\.$#"
count: 1
path: src/SQLParser/Node/CaseOperation.php

-
message: "#^Cannot access offset mixed on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\.$#"
count: 2
path: src/SQLParser/Node/Expression.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:toObject\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Parameter \\#1 \\$refClause of method SQLParser\\\\Node\\\\SubQuery\\:\\:setRefClause\\(\\) expects array\\<SQLParser\\\\Node\\\\NodeInterface\\>, array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface given\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:buildFromSubtree\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:buildFromSubtree\\(\\) has parameter \\$subTree with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:mapArrayToNodeObjectList\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Property SQLParser\\\\Node\\\\NodeFactory\\:\\:\\$PRECEDENCE has no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Property SQLParser\\\\Node\\\\NodeFactory\\:\\:\\$OPERATOR_TO_CLASS has no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface given\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface given\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:array_map_deep\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:array_map_deep\\(\\) has parameter \\$array with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Method SQLParser\\\\Node\\\\NodeFactory\\:\\:array_map_deep\\(\\) has parameter \\$callback with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/NodeFactory.php

-
message: "#^Property SQLParser\\\\Node\\\\Operator\\:\\:\\$value has no typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/Operator.php

-
message: "#^Method SQLParser\\\\Node\\\\Operator\\:\\:getValue\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/Operator.php

-
message: "#^Method SQLParser\\\\Node\\\\Operator\\:\\:setValue\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/SQLParser/Node/Operator.php

-
message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#"
count: 1
path: src/SQLParser/Node/Parameter.php

-
message: "#^Argument of an invalid type array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/SQLParser/Node/SimpleFunction.php

-
message: "#^Cannot access offset mixed on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\.$#"
count: 2
path: src/SQLParser/Node/SimpleFunction.php

-
message: "#^Cannot access offset mixed on array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\.$#"
count: 2
path: src/SQLParser/Node/Table.php

-
message: "#^Elseif condition is always true\\.$#"
count: 1
path: src/SQLParser/Node/Table.php

-
message: "#^Property SQLParser\\\\Node\\\\Table\\:\\:\\$refClause \\(array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface\\) does not accept null\\.$#"
count: 1
path: src/SQLParser/Node/Table.php

-
message: "#^Method SQLParser\\\\Query\\\\Select\\:\\:overwriteInstanceDescriptor\\(\\) has parameter \\$name with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Query/Select.php

-
message: "#^Method SQLParser\\\\Query\\\\Select\\:\\:walkChildren\\(\\) has parameter \\$children with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Query/Select.php

-
message: "#^Argument of an invalid type array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/SQLParser/Query/StatementFactory.php

-
message: "#^Cannot access offset mixed on \\(array\\<SQLParser\\\\Node\\\\NodeInterface\\>&nonEmpty\\)\\|SQLParser\\\\Node\\\\NodeInterface\\.$#"
count: 1
path: src/SQLParser/Query/StatementFactory.php

-
message: "#^Parameter \\#1 \\$columns of method SQLParser\\\\Query\\\\Select\\:\\:setColumns\\(\\) expects array\\<SQLParser\\\\Node\\\\NodeInterface\\>, array\\<SQLParser\\\\Node\\\\NodeInterface\\>\\|SQLParser\\\\Node\\\\NodeInterface given\\.$#"
count: 1
path: src/SQLParser/Query/StatementFactory.php

-
message: "#^Method SQLParser\\\\Query\\\\Union\\:\\:overwriteInstanceDescriptor\\(\\) has parameter \\$name with no typehint specified\\.$#"
count: 1
path: src/SQLParser/Query/Union.php

9 changes: 8 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
includes:
- phpstan-baseline.neon

parameters:
level: 7
paths:
- src
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- "#Mouf\\\\MoufManager#"
- "#Mouf\\\\MoufInstanceDescriptor#"
- '#Method Mouf\\Database\\QueryWriter\\Utils\\FindParametersService::findParameters\(\) should return array<string> but returns array<int, int\|string>#'
- '#Method Mouf\\Database\\QueryWriter\\Utils\\FindParametersService::findParameters\(\) should return array<string> but returns array<int, int\|string>#'
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
>

<php>
<var name="db_host" value="localhost" />
<var name="db_host" value="127.0.0.1" />
<var name="db_port" value="3306"/>
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_driver" value="pdo_mysql"/>
Expand Down
26 changes: 10 additions & 16 deletions src/Mouf/Database/MagicQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mouf\Database;

use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
Expand Down Expand Up @@ -34,21 +35,20 @@
class MagicQuery
{
private $connection;
/** @var Cache */
private $cache;
/** @var SchemaAnalyzer */
private $schemaAnalyzer;
/**
* @var AbstractPlatform
*/
/** @var AbstractPlatform */
private $platform;
/**
* @var Environment
*/
/** @var Environment */
private $twigEnvironment;
/** @var bool */
private $enableTwig = false;

/**
* @param \Doctrine\DBAL\Connection $connection
* @param \Doctrine\Common\Cache\Cache $cache
* @param Cache $cache
* @param SchemaAnalyzer $schemaAnalyzer (optional). If not set, it is initialized from the connection.
*/
public function __construct($connection = null, $cache = null, SchemaAnalyzer $schemaAnalyzer = null)
Expand Down Expand Up @@ -205,11 +205,9 @@ public function toSql(NodeInterface $sqlNode, array $parameters = array(), bool
/**
* Scans the SQL statement and replaces the "magicjoin" part with the correct joins.
*
* @param NodeInterface $select
*
* @throws MagicQueryMissingConnectionException
*/
private function magicJoin(NodeInterface $select)
private function magicJoin(NodeInterface $select): void
{
// Let's find if this is a MagicJoin query.
$magicJoinDetector = new DetectMagicJoinSelectVisitor();
Expand All @@ -227,12 +225,8 @@ private function magicJoin(NodeInterface $select)

/**
* For one given MagicJoin select, let's apply MagicJoin.
*
* @param MagicJoinSelect $magicJoinSelect
*
* @return Select
*/
private function magicJoinOnOneQuery(MagicJoinSelect $magicJoinSelect)
private function magicJoinOnOneQuery(MagicJoinSelect $magicJoinSelect): void
{
$tableSearchNodeTraverser = new NodeTraverser();
$detectTableVisitor = new DetectTablesVisitor($magicJoinSelect->getMainTable());
Expand Down Expand Up @@ -316,7 +310,7 @@ private function getSchemaAnalyzer()
return $this->schemaAnalyzer;
}

private function getConnectionUniqueId(Connection $connection)
private function getConnectionUniqueId(Connection $connection): string
{
return hash('md4', $connection->getHost().'-'.$connection->getPort().'-'.$connection->getDatabase().'-'.$connection->getDriver()->getName());
}
Expand Down
Loading