Skip to content

Commit 8b5ba78

Browse files
committed
CI - GH Actions: Increase PHPStan version, fix a load of errors.
1 parent 631032c commit 8b5ba78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+290
-190
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ jobs:
137137
strategy:
138138
matrix:
139139
php-version:
140-
- "7.1"
141140
- "7.3"
142141
- "7.4"
143142

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.1.0",
16+
"php": ">=7.2.0",
1717
"mouf/utils.common.conditioninterface": "~2.0",
1818
"mouf/utils.value.value-interface": "~1.0",
1919
"mouf/utils.common.paginable-interface": "~1.0",
@@ -27,7 +27,7 @@
2727
"phpunit/phpunit": "^7.5.10",
2828
"satooshi/php-coveralls": "~1.0",
2929
"doctrine/dbal": "~2.5",
30-
"phpstan/phpstan": "^0.11.7"
30+
"phpstan/phpstan": "^0.12.82"
3131
},
3232
"suggest": {
3333
"doctrine/dbal": "To support more databases than just MySQL and to use MagicJoin feature",

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
25
level: 7
36
paths:
47
- src
58
inferPrivatePropertyTypeFromConstructor: true
9+
checkMissingIterableValueType: false
10+
checkGenericClassInNonGenericObjectType: false
611
ignoreErrors:
712
- "#Mouf\\\\MoufManager#"
813
- "#Mouf\\\\MoufInstanceDescriptor#"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
>
1313

1414
<php>
15-
<var name="db_host" value="localhost" />
15+
<var name="db_host" value="127.0.0.1" />
1616
<var name="db_username" value="root" />
1717
<var name="db_password" value="" />
1818
<var name="db_driver" value="pdo_mysql"/>

src/Mouf/Database/MagicQuery.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Mouf\Database;
44

5+
use Doctrine\Common\Cache\Cache;
56
use Doctrine\DBAL\Connection;
67
use Doctrine\DBAL\Platforms\AbstractPlatform;
78
use Doctrine\DBAL\Platforms\MySqlPlatform;
@@ -34,21 +35,20 @@
3435
class MagicQuery
3536
{
3637
private $connection;
38+
/** @var Cache */
3739
private $cache;
40+
/** @var SchemaAnalyzer */
3841
private $schemaAnalyzer;
39-
/**
40-
* @var AbstractPlatform
41-
*/
42+
/** @var AbstractPlatform */
4243
private $platform;
43-
/**
44-
* @var Environment
45-
*/
44+
/** @var Environment */
4645
private $twigEnvironment;
46+
/** @var bool */
4747
private $enableTwig = false;
4848

4949
/**
5050
* @param \Doctrine\DBAL\Connection $connection
51-
* @param \Doctrine\Common\Cache\Cache $cache
51+
* @param Cache $cache
5252
* @param SchemaAnalyzer $schemaAnalyzer (optional). If not set, it is initialized from the connection.
5353
*/
5454
public function __construct($connection = null, $cache = null, SchemaAnalyzer $schemaAnalyzer = null)
@@ -205,11 +205,9 @@ public function toSql(NodeInterface $sqlNode, array $parameters = array(), bool
205205
/**
206206
* Scans the SQL statement and replaces the "magicjoin" part with the correct joins.
207207
*
208-
* @param NodeInterface $select
209-
*
210208
* @throws MagicQueryMissingConnectionException
211209
*/
212-
private function magicJoin(NodeInterface $select)
210+
private function magicJoin(NodeInterface $select): void
213211
{
214212
// Let's find if this is a MagicJoin query.
215213
$magicJoinDetector = new DetectMagicJoinSelectVisitor();
@@ -227,12 +225,8 @@ private function magicJoin(NodeInterface $select)
227225

228226
/**
229227
* For one given MagicJoin select, let's apply MagicJoin.
230-
*
231-
* @param MagicJoinSelect $magicJoinSelect
232-
*
233-
* @return Select
234228
*/
235-
private function magicJoinOnOneQuery(MagicJoinSelect $magicJoinSelect)
229+
private function magicJoinOnOneQuery(MagicJoinSelect $magicJoinSelect): void
236230
{
237231
$tableSearchNodeTraverser = new NodeTraverser();
238232
$detectTableVisitor = new DetectTablesVisitor($magicJoinSelect->getMainTable());
@@ -316,7 +310,7 @@ private function getSchemaAnalyzer()
316310
return $this->schemaAnalyzer;
317311
}
318312

319-
private function getConnectionUniqueId(Connection $connection)
313+
private function getConnectionUniqueId(Connection $connection): string
320314
{
321315
return hash('md4', $connection->getHost().'-'.$connection->getPort().'-'.$connection->getDatabase().'-'.$connection->getDriver()->getName());
322316
}

src/Mouf/Database/MagicQuery/Twig/SqlTwigEnvironmentFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
*/
1313
class SqlTwigEnvironmentFactory
1414
{
15+
/** @var Environment|null */
1516
private static $twig;
1617

17-
public static function getTwigEnvironment()
18+
public static function getTwigEnvironment(): Environment
1819
{
1920
if (self::$twig) {
2021
return self::$twig;
@@ -45,7 +46,7 @@ public static function getTwigEnvironment()
4546
return $twig;
4647
}
4748

48-
private static function getCacheDirectory()
49+
private static function getCacheDirectory(): string
4950
{
5051
// If we are running on a Unix environment, let's prepend the cache with the user id of the PHP process.
5152
// This way, we can avoid rights conflicts.

src/Mouf/Database/MagicQuery/Twig/StringLoader.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,14 @@ class StringLoader implements LoaderInterface
2020
/**
2121
* {@inheritdoc}
2222
*/
23-
public function getSource($name)
23+
public function getCacheKey(string $name): string
2424
{
2525
return $name;
2626
}
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function getCacheKey($name): string
31-
{
32-
return $name;
33-
}
34-
/**
35-
* {@inheritdoc}
36-
*/
37-
public function isFresh($name, $time): bool
30+
public function isFresh(string $name, int $time): bool
3831
{
3932
return true;
4033
}

src/Mouf/Database/QueryWriter/QueryResult.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ class QueryResult implements ArrayValueInterface, PaginableInterface, SortableIn
4444
*/
4545
private $parameters = array();
4646

47-
private $limit;
47+
/** @var int|null */
4848
private $offset;
49+
/** @var int|null */
50+
private $limit;
4951

5052
/**
5153
* @param Select $select
@@ -62,7 +64,7 @@ public function __construct(Select $select, Connection $connection)
6264
*
6365
* @param array<string, string>|array<string, ValueInterface>|ArrayValueInterface $parameters
6466
*/
65-
public function setParameters($parameters)
67+
public function setParameters($parameters): void
6668
{
6769
$this->parameters = $parameters;
6870
}
@@ -98,7 +100,7 @@ public function toSql()
98100
* @param int $limit
99101
* @param int $offset
100102
*/
101-
public function paginate($limit, $offset = 0)
103+
public function paginate($limit, $offset = 0): void
102104
{
103105
$this->limit = $limit;
104106
$this->offset = $offset;
@@ -107,7 +109,7 @@ public function paginate($limit, $offset = 0)
107109
/* (non-PHPdoc)
108110
* @see \Mouf\Utils\Common\SortableInterface::sort()
109111
*/
110-
public function sort($key, $direction = SortableInterface::ASC)
112+
public function sort($key, $direction = SortableInterface::ASC): void
111113
{
112114
$result = $this->findColumnByKey($key);
113115
if ($result != null) {

src/Mouf/Database/QueryWriter/ResultSet.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Mouf\Database\QueryWriter;
44

5-
use Doctrine\DBAL\Statement;
5+
use Doctrine\DBAL\FetchMode;
6+
use Doctrine\DBAL\Driver\Statement;
67

78
/**
89
* Wraps the results of a PDOStatement.
@@ -11,20 +12,20 @@
1112
*/
1213
class ResultSet implements \Iterator
1314
{
14-
/**
15-
* @var \PDOStatement|Statement
16-
*/
15+
/** @var Statement */
1716
private $statement;
18-
private $castToClass;
17+
/** @var int */
1918
private $key = 0;
19+
/** @var array|false */
2020
private $result;
21+
/** @var bool */
2122
private $fetched = false;
23+
/** @var int */
2224
private $rewindCalls = 0;
2325

24-
public function __construct($statement, $castToClass = '')
26+
public function __construct(Statement $statement)
2527
{
2628
$this->statement = $statement;
27-
$this->castToClass = $castToClass;
2829
}
2930

3031
public function rewind()
@@ -35,6 +36,9 @@ public function rewind()
3536
}
3637
}
3738

39+
/**
40+
* @return array|false
41+
*/
3842
public function current()
3943
{
4044
if (!$this->fetched) {
@@ -44,6 +48,9 @@ public function current()
4448
return $this->result;
4549
}
4650

51+
/**
52+
* @return int
53+
*/
4754
public function key()
4855
{
4956
return $this->key;
@@ -56,9 +63,9 @@ public function next()
5663
$this->fetch();
5764
}
5865

59-
private function fetch()
66+
private function fetch(): void
6067
{
61-
$this->result = $this->statement->fetch(\PDO::FETCH_ASSOC);
68+
$this->result = $this->statement->fetch(FetchMode::ASSOCIATIVE);
6269
$this->fetched = true;
6370
}
6471

src/Mouf/Database/QueryWriter/Utils/DbHelper.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace Mouf\Database\QueryWriter\Utils;
44

5+
use Doctrine\DBAL\Connection;
56
use Mouf\MoufManager;
67

78
class DbHelper
89
{
9-
public static function getAll($sql, $offset, $limit)
10+
public static function getAll(string $sql, ?int $offset, ?int $limit)
1011
{
12+
/** @var Connection $dbalConnection */
1113
$dbalConnection = MoufManager::getMoufManager()->get('dbalConnection');
12-
/* @var $dbalConnection \Doctrine\DBAL\Connection */
1314
$sql .= self::getFromLimitString($offset, $limit);
1415
$statement = $dbalConnection->executeQuery($sql);
1516
$results = $statement->fetchAll();
@@ -23,15 +24,13 @@ public static function getAll($sql, $offset, $limit)
2324
return $array;
2425
}
2526

26-
public static function getFromLimitString($from = null, $limit = null)
27+
public static function getFromLimitString(?int $from = null, ?int $limit = null): string
2728
{
2829
if ($limit !== null) {
29-
$limitInt = (int) $limit;
30-
$queryStr = ' LIMIT '.$limitInt;
30+
$queryStr = ' LIMIT '.$limit;
3131

3232
if ($from !== null) {
33-
$fromInt = (int) $from;
34-
$queryStr .= ' OFFSET '.$fromInt;
33+
$queryStr .= ' OFFSET '.$from;
3534
}
3635

3736
return $queryStr;

0 commit comments

Comments
 (0)