Skip to content

Commit 96d299e

Browse files
committed
- Fixed type-hinting in various cases
1 parent e650862 commit 96d299e

File tree

11 files changed

+52
-52
lines changed

11 files changed

+52
-52
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
"psr-4": {
2727
"Kir\\MySQL\\": ["src/", "tests/"]
2828
}
29+
},
30+
"scripts": {
31+
"phpstan": "phpstan analyse --level 4 src",
32+
"phploc": "phploc --names *.php,*.phtml src"
2933
}
3034
}

src/Builder/Insert.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function setKey($field) {
5252
/**
5353
* @param string $field
5454
* @param bool|int|float|string $value
55-
* @throws UnexpectedValueException
5655
* @return $this
5756
*/
5857
public function add($field, $value) {
@@ -63,7 +62,6 @@ public function add($field, $value) {
6362
/**
6463
* @param string $field
6564
* @param bool|int|float|string $value
66-
* @throws UnexpectedValueException
6765
* @return $this
6866
*/
6967
public function update($field, $value) {
@@ -74,7 +72,6 @@ public function update($field, $value) {
7472
/**
7573
* @param string $field
7674
* @param bool|int|float|string $value
77-
* @throws UnexpectedValueException
7875
* @return $this
7976
*/
8077
public function addOrUpdate($field, $value) {
@@ -85,11 +82,11 @@ public function addOrUpdate($field, $value) {
8582

8683
/**
8784
* @param string $str
88-
* @param string ...$_
85+
* @param mixed ...$args
8986
* @return $this
9087
*/
91-
public function addExpr($str, $_ = null) {
92-
if(count(func_get_args()) > 1) {
88+
public function addExpr($str, ...$args) {
89+
if(count($args) > 0) {
9390
$this->fields[] = func_get_args();
9491
} else {
9592
$this->fields[] = $str;
@@ -99,29 +96,30 @@ public function addExpr($str, $_ = null) {
9996

10097
/**
10198
* @param string $str
102-
* @param string ...$_
99+
* @param mixed ...$args
103100
* @return $this
104101
*/
105-
public function updateExpr($str, $_ = null) {
106-
if(count(func_get_args()) > 1) {
102+
public function updateExpr($str, ...$args) {
103+
if(count($args) > 0) {
107104
$this->update[] = func_get_args();
108105
} else {
109106
$this->update[] = $str;
110107
}
111108
return $this;
112109
}
113-
110+
114111
/**
115-
* @param string $str
112+
* @param string $expr
113+
* @param mixed ...$args
116114
* @return $this
117115
*/
118-
public function addOrUpdateExpr($str) {
119-
if(count(func_get_args()) > 1) {
116+
public function addOrUpdateExpr($expr, ...$args) {
117+
if(count($args) > 0) {
120118
$this->fields[] = func_get_args();
121119
$this->update[] = func_get_args();
122120
} else {
123-
$this->fields[] = $str;
124-
$this->update[] = $str;
121+
$this->fields[] = $expr;
122+
$this->update[] = $expr;
125123
}
126124
return $this;
127125
}
@@ -176,7 +174,6 @@ public function from(Select $select) {
176174
}
177175

178176
/**
179-
* @throws RuntimeException
180177
* @return string
181178
*/
182179
public function __toString() {

src/Builder/Select.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function getCalcFoundRows() {
103103

104104
/**
105105
* @param bool $calcFoundRows
106-
* @throws RuntimeException
107106
* @return $this
108107
*/
109108
public function setCalcFoundRows($calcFoundRows = true) {

src/Builder/Traits/GroupByBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ trait GroupByBuilder {
66

77
/** @var array */
88
private $groupBy = [];
9-
9+
1010
/**
11+
* @param mixed ...$args
1112
* @return $this
1213
*/
13-
public function groupBy() {
14-
foreach(func_get_args() as $expression) {
14+
public function groupBy(...$args) {
15+
foreach($args as $expression) {
1516
if(is_array($expression)) {
1617
if(!count($expression)) {
1718
continue;

src/Builder/Traits/HavingBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ trait HavingBuilder {
1212

1313
/**
1414
* @param string|array $expression
15-
* @param mixed ...$_
15+
* @param mixed[] $args
1616
* @return $this
1717
*/
18-
public function having($expression, $_ = null) {
18+
public function having($expression, ...$args) {
1919
if($expression instanceof OptionalExpression) {
2020
if($expression->isValid()) {
2121
$this->having[] = [$expression->getExpression(), $expression->getValue()];

src/Builder/Traits/JoinBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait JoinBuilder {
1212
* @param string $alias
1313
* @param string $table
1414
* @param string $expression
15-
* @param array $args
15+
* @param mixed[] $args
1616
* @return $this
1717
*/
1818
public function joinInner($alias, $table, $expression = null, ...$args) {
@@ -23,7 +23,7 @@ public function joinInner($alias, $table, $expression = null, ...$args) {
2323
* @param string $alias
2424
* @param string $table
2525
* @param string $expression
26-
* @param array $args
26+
* @param mixed[] $args
2727
* @return $this
2828
*/
2929
public function joinLeft($alias, $table, $expression, ...$args) {
@@ -34,7 +34,7 @@ public function joinLeft($alias, $table, $expression, ...$args) {
3434
* @param string $alias
3535
* @param string $table
3636
* @param string $expression
37-
* @param array $args
37+
* @param mixed[] $args
3838
* @return $this
3939
*/
4040
public function joinRight($alias, $table, $expression, ...$args) {
@@ -66,7 +66,7 @@ protected function buildJoins($query) {
6666
* @param string $alias
6767
* @param string $name
6868
* @param string $expression
69-
* @param array $arguments
69+
* @param mixed[] $arguments
7070
* @return $this
7171
*/
7272
private function addJoin($type, $alias, $name, $expression = null, array $arguments = []) {

src/Builder/Traits/UnionBuilder.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
<?php
22
namespace Kir\MySQL\Builder\Traits;
33

4+
use Kir\MySQL\Builder\Select;
5+
46
trait UnionBuilder {
57
use AbstractDB;
68

79
/** @var array */
810
private $unions = [];
911

1012
/**
11-
* @param string $query
13+
* @param string[]|Select[] $queries
1214
* @return $this
1315
*/
14-
public function union($query) {
15-
$this->unions[] = ['', $query];
16+
public function union(...$queries) {
17+
foreach($queries as $query) {
18+
$this->unions[] = ['', $query];
19+
}
1620
return $this;
1721
}
1822

1923
/**
20-
* @param string $query
24+
* @param string[]|Select[] $queries
2125
* @return $this
2226
*/
23-
public function unionAll($query) {
24-
$this->unions[] = ['ALL', $query];
27+
public function unionAll(...$queries) {
28+
foreach($queries as $query) {
29+
$this->unions[] = ['ALL', $query];
30+
}
2531
return $this;
2632
}
2733

src/Builder/Traits/WhereBuilder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Kir\MySQL\Builder\Traits;
33

4+
use Kir\MySQL\Builder\DBExpr;
45
use Kir\MySQL\Builder\Expr\OptionalExpression;
56
use Kir\MySQL\Builder\Internal\ConditionBuilder;
67

@@ -9,19 +10,19 @@ trait WhereBuilder {
910

1011
/** @var array */
1112
private $where = [];
12-
13+
1314
/**
1415
* @param string|array $expression
15-
* @param mixed ...$_
16+
* @param mixed[] $args
1617
* @return $this
1718
*/
18-
public function where($expression, $_ = null) {
19+
public function where($expression, ...$args) {
1920
if($expression instanceof OptionalExpression) {
2021
if($expression->isValid()) {
2122
$this->where[] = [$expression->getExpression(), $expression->getValue()];
2223
}
2324
} else {
24-
$this->where[] = [$expression, array_slice(func_get_args(), 1)];
25+
$this->where[] = [$expression, $args];
2526
}
2627
return $this;
2728
}

src/Builder/Update.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class Update extends InsertUpdateStatement {
2020
use LimitBuilder;
2121
use OffsetBuilder;
2222

23-
/**
24-
* @var array
25-
*/
23+
/** @var mixed[] */
2624
private $fields = [];
2725

2826
/**
@@ -38,7 +36,6 @@ public function table($alias, $table = null) {
3836
/**
3937
* @param string $fieldName
4038
* @param string $value
41-
* @throws \UnexpectedValueException
4239
* @return $this
4340
*/
4441
public function set($fieldName, $value) {
@@ -60,19 +57,22 @@ public function setDefault($fieldName) {
6057

6158
/**
6259
* @param string $expr
63-
* @param string[] ...$_
60+
* @param mixed ...$args
6461
* @return $this
6562
*/
66-
public function setExpr($expr, $_ = null) {
67-
$this->fields[] = func_get_args();
63+
public function setExpr($expr, ...$args) {
64+
if(count($args) > 0) {
65+
$this->fields[] = func_get_args();
66+
} else {
67+
$this->fields[] = $expr;
68+
}
6869
return $this;
6970
}
7071

7172
/**
7273
* @param array $data
7374
* @param array $allowedFields
7475
* @return $this
75-
* @throws Exception
7676
*/
7777
public function setAll(array $data, array $allowedFields = null) {
7878
if ($allowedFields !== null) {
@@ -91,7 +91,6 @@ public function setAll(array $data, array $allowedFields = null) {
9191
}
9292

9393
/**
94-
* @throws Exception
9594
* @return string
9695
*/
9796
public function __toString() {
@@ -110,7 +109,6 @@ public function __toString() {
110109
/**
111110
* @param string $query
112111
* @return string
113-
* @throws RuntimeException
114112
*/
115113
private function buildAssignments($query) {
116114
$sqlFields = $this->buildFieldList($this->fields);
@@ -123,7 +121,6 @@ private function buildAssignments($query) {
123121
/**
124122
* @param array $values
125123
* @return array
126-
* @throws RuntimeException
127124
*/
128125
private function clearValues(array $values) {
129126
if (!count($values)) {

src/Databases/MySQL.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function getVirtualTables() {
8383

8484
/**
8585
* @param string $query
86-
* @throws Exception
8786
* @return QueryStatement
8887
*/
8988
public function query($query) {
@@ -95,7 +94,6 @@ public function query($query) {
9594

9695
/**
9796
* @param string|object $query
98-
* @throws Exception
9997
* @return QueryStatement
10098
*/
10199
public function prepare($query) {
@@ -349,7 +347,6 @@ public function transaction(callable $callback = null) {
349347
/**
350348
* @param callable $fn
351349
* @return $this
352-
* @throws RuntimeException
353350
*/
354351
private function transactionEnd($fn) {
355352
$this->transactionLevel--;
@@ -369,7 +366,6 @@ private function transactionEnd($fn) {
369366
* @param string $query
370367
* @param callable $fn
371368
* @return QueryStatement
372-
* @throws RuntimeException
373369
*/
374370
private function buildQueryStatement($query, $fn) {
375371
$stmt = call_user_func($fn, $query);

src/Tools/AliasRegistry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function add($alias, $string) {
1919

2020
/**
2121
* @param string $alias
22-
* @throws RuntimeException
2322
* @return string
2423
*/
2524
public function get($alias) {

0 commit comments

Comments
 (0)