Skip to content

Commit ee07060

Browse files
committed
fix phpstan warnings
1 parent 59731b2 commit ee07060

9 files changed

Lines changed: 56 additions & 46 deletions

File tree

phpstan.neon

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ parameters:
66
- php
77
bootstrapFiles:
88
- ./vendor/autoload.php
9-
reportUnmatchedIgnoredErrors: false
9+
ignoreErrors:
10+
-
11+
message: '#Variable method call on Pecee\\Pixie\\QueryBuilder\\Adapters\\BaseAdapter#'
12+
path: %currentWorkingDirectory%/src/Pecee\Pixie\QueryBuilder\QueryBuilderHandler.php
13+
-
14+
message: '#Variable method call on \$this\(Pecee\\Pixie\\QueryBuilder\\QueryBuilderHandler\)#'
15+
path: %currentWorkingDirectory%/src/Pecee\Pixie\QueryBuilder\QueryBuilderHandler.php
16+
reportUnmatchedIgnoredErrors: true
1017
checkMissingIterableValueType: false
1118
checkGenericClassInNonGenericObjectType: false
1219
parallel:

src/Pecee/Pixie/Connection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Connection
1616
{
1717

1818
/**
19-
* @var Connection
19+
* @var Connection|null
2020
*/
2121
protected static $storedConnection;
2222

@@ -33,7 +33,7 @@ class Connection
3333
protected $adapterConfig;
3434

3535
/**
36-
* @var \PDO
36+
* @var \PDO|null
3737
*/
3838
protected $pdoInstance;
3939

@@ -48,7 +48,7 @@ class Connection
4848
protected $lastQuery;
4949

5050
/**
51-
* @param string $adapter Adapter name or class
51+
* @param string|IConnectionAdapter $adapter Adapter name or class
5252
* @param array $adapterConfig
5353
*/
5454
public function __construct($adapter, array $adapterConfig)
@@ -225,4 +225,4 @@ public function __destruct()
225225
$this->close();
226226
}
227227

228-
}
228+
}

src/Pecee/Pixie/Event/EventArguments.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ class EventArguments
2828
*/
2929
private $arguments;
3030

31-
public function __construct($name, QueryObject $qo, QueryBuilderHandler $qb, array $arguments)
31+
/**
32+
* EventArguments constructor.
33+
*
34+
* @param string $name
35+
* @param \Pecee\Pixie\QueryBuilder\QueryObject $qo
36+
* @param \Pecee\Pixie\QueryBuilder\QueryBuilderHandler $qb
37+
* @param array $arguments
38+
*/
39+
public function __construct(string $name, QueryObject $qo, QueryBuilderHandler $qb, array $arguments)
3240
{
3341
$this->name = $name;
3442
$this->queryObject = $qo;
@@ -96,4 +104,4 @@ public function getArguments(): array
96104
return $this->arguments;
97105
}
98106

99-
}
107+
}

src/Pecee/Pixie/Event/EventHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public function registerEvent(string $event, ?string $table = null, \Closure $ac
193193
*
194194
* @return void
195195
*/
196-
public function removeEvent($event, $table = null): void
196+
public function removeEvent(string $event, $table = null): void
197197
{
198198
unset($this->events[$table ?? static::TABLE_ANY][$event]);
199199
}
200-
}
200+
}

src/Pecee/Pixie/Exception.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
*/
2424
class Exception extends \Exception
2525
{
26+
/**
27+
* @var \Pecee\Pixie\QueryBuilder\QueryObject|null
28+
*/
2629
protected $query;
2730

28-
public function __construct(string $message = '', int $code = 0, Throwable $previous = null, QueryObject $query = null)
31+
final public function __construct(string $message = '', int $code = 0, Throwable $previous = null, QueryObject $query = null)
2932
{
3033
parent::__construct($message, $code, $previous);
3134
$this->query = $query;
@@ -150,4 +153,4 @@ public function getQuery(): ?QueryObject
150153
{
151154
return $this->query;
152155
}
153-
}
156+
}

src/Pecee/Pixie/QueryBuilder/NestedCriteria.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class NestedCriteria extends QueryBuilderHandler
1111
{
1212
/**
1313
* @param string|Raw|\Closure $key
14-
* @param string|Raw|\Closure|null $operator
15-
* @param string|Raw|\Closure|null $value
14+
* @param string|null $operator
15+
* @param string|array|Raw|\Closure|null $value
1616
* @param string $joiner
1717
*
1818
* @return static
@@ -24,4 +24,4 @@ protected function whereHandler($key, string $operator = null, $value = null, $j
2424

2525
return $this;
2626
}
27-
}
27+
}

src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class QueryBuilderHandler implements IQueryBuilderHandler
3838
*/
3939
public const UNION_TYPE_ALL = 'ALL';
4040
/**
41-
* @var Connection
41+
* @var Connection|null
4242
*/
4343
protected $connection;
4444

@@ -84,7 +84,7 @@ class QueryBuilderHandler implements IQueryBuilderHandler
8484
*
8585
* @throws Exception
8686
*/
87-
public function __construct(Connection $connection = null)
87+
final public function __construct(Connection $connection = null)
8888
{
8989
$this->connection = $connection ?? Connection::getStoredConnection();
9090

@@ -241,7 +241,7 @@ public function first()
241241
{
242242
$result = $this->limit(1)->get();
243243

244-
return ($result !== null && \count($result) !== 0) ? $result[0] : null;
244+
return (\count($result) !== 0) ? $result[0] : null;
245245
}
246246

247247
/**
@@ -260,19 +260,12 @@ public function first()
260260
*/
261261
public function get(): array
262262
{
263-
/**
264-
* @var $queryObject QueryObject
265-
* @var $executionTime float
266-
* @var $start float
267-
* @var $result array
268-
*/
269-
270263
$queryObject = $this->getQuery();
271264
$this->connection->setLastQuery($queryObject);
272265

273266
$this->fireEvents(EventHandler::EVENT_BEFORE_SELECT, $queryObject);
274267

275-
$executionTime = 0;
268+
$executionTime = 0.0;
276269
$startTime = microtime(true);
277270

278271
if ($this->pdoStatement === null) {
@@ -548,7 +541,7 @@ public function addTablePrefix($values, bool $tableFieldMix = true)
548541
$target = &$key;
549542
}
550543

551-
if ($tableFieldMix === false || ($tableFieldMix && strpos($target, '.') !== false)) {
544+
if (($tableFieldMix === false) || (strpos($target, '.') !== false)) {
552545
$target = $this->tablePrefix . $target;
553546
}
554547

@@ -631,7 +624,7 @@ public function from($tables = null): self
631624

632625
$tTables = [];
633626

634-
foreach ((array)$tables as $key => $value) {
627+
foreach ($tables as $key => $value) {
635628
if (\is_string($key) === true) {
636629
$this->alias($value, $key);
637630
$tTables[] = $key;
@@ -890,7 +883,7 @@ public function where($key, $operator = null, $value = null): self
890883
*
891884
* @param string|Raw|\Closure $key
892885
* @param string|null $operator
893-
* @param string|Raw|\Closure|null $value
886+
* @param string|array|Raw|\Closure|null $value
894887
* @param string $joiner
895888
*
896889
* @return static
@@ -1017,7 +1010,7 @@ public function join($table, $key = null, $operator = null, $value = null, $type
10171010
* in the closure should reflect here
10181011
*/
10191012
if ($key instanceof \Closure === false) {
1020-
$key = static function (JoinBuilder $joinBuilder) use ($key, $operator, $value) {
1013+
$key = static function (JoinBuilder $joinBuilder) use ($key, $operator, $value): void {
10211014
$joinBuilder->on($key, $operator, $value);
10221015
};
10231016
}
@@ -1086,10 +1079,9 @@ private function doInsert(array $data, string $type)
10861079
$this->connection->setLastQuery($queryObject);
10871080

10881081
$this->fireEvents(EventHandler::EVENT_BEFORE_INSERT, $queryObject);
1089-
/**
1090-
* @var $result \PDOStatement
1091-
* @var $executionTime float
1092-
*/
1082+
1083+
/** @var float $executionTime */
1084+
/** @var \PDOStatement $result */
10931085
[$result, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());
10941086

10951087
$insertId = $result->rowCount() === 1 ? $this->pdo()->lastInsertId() : null;
@@ -1107,7 +1099,7 @@ private function doInsert(array $data, string $type)
11071099

11081100
if ($this->pdo()->inTransaction() === false) {
11091101

1110-
$this->transaction(function (Transaction $transaction) use (&$insertIds, $data, $type) {
1102+
$this->transaction(function (Transaction $transaction) use (&$insertIds, $data, $type): void {
11111103
foreach ($data as $subData) {
11121104
$insertIds[] = $transaction->doInsert($subData, $type);
11131105
}
@@ -1405,7 +1397,7 @@ public function orderBy($fields, string $direction = 'ASC'): self
14051397
$fields = [$fields];
14061398
}
14071399

1408-
foreach ((array)$fields as $key => $value) {
1400+
foreach ($fields as $key => $value) {
14091401
$field = $key;
14101402
$type = $value;
14111403

@@ -1632,15 +1624,13 @@ public function updateOrInsert(array $data)
16321624
*/
16331625
public function update(array $data): \PDOStatement
16341626
{
1635-
/**
1636-
* @var $response \PDOStatement
1637-
*/
16381627
$queryObject = $this->getQuery('update', $data);
16391628

16401629
$this->connection->setLastQuery($queryObject);
16411630

16421631
$this->fireEvents(EventHandler::EVENT_BEFORE_UPDATE, $queryObject);
16431632

1633+
/** @var \PDOStatement $response */
16441634
[$response, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());
16451635

16461636
$this->fireEvents(EventHandler::EVENT_AFTER_UPDATE, $queryObject, [
@@ -1757,7 +1747,7 @@ public function whereNull($key): self
17571747

17581748
/**
17591749
* Will add FOR statement to the end of the SELECT statement, like FOR UPDATE, FOR SHARE etc.
1760-
* @param $statement string
1750+
* @param string $statement
17611751
* @return static
17621752
*/
17631753
public function for(string $statement): self

src/Pecee/Pixie/QueryBuilder/Raw.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Raw
1616
protected $value;
1717

1818
/**
19-
* @var array
19+
* @var mixed[]
2020
*/
2121
protected $bindings;
2222

@@ -26,25 +26,25 @@ class Raw
2626
* @param string $value
2727
* @param array|string $bindings
2828
*/
29-
public function __construct(string $value, array $bindings = [])
29+
public function __construct(string $value, $bindings = [])
3030
{
3131
$this->value = $value;
32-
$this->bindings = $bindings;
32+
$this->bindings = (array)$bindings;
3333
}
3434

3535
/**
3636
* @return string
3737
*/
3838
public function __toString(): string
3939
{
40-
return (string)$this->value;
40+
return $this->value;
4141
}
4242

4343
/**
44-
* @return array
44+
* @return mixed[]
4545
*/
4646
public function getBindings(): array
4747
{
4848
return $this->bindings;
4949
}
50-
}
50+
}

src/Pecee/Pixie/QueryBuilder/Transaction.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313
class Transaction extends QueryBuilderHandler
1414
{
15-
15+
/**
16+
* @var \PDOStatement|null
17+
*/
1618
protected $transactionStatement;
1719

1820
/**

0 commit comments

Comments
 (0)