Skip to content

Commit 2041e7c

Browse files
committed
- Fixed Exception-Handling (Replaced \Exception with more appropriate \RuntimeException)
- Fixed various PHPDocs
1 parent 6c78282 commit 2041e7c

12 files changed

+32
-31
lines changed

src/Builder/Exception.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
namespace Kir\MySQL\Builder;
33

4-
class Exception extends \Exception {
4+
use RuntimeException;
5+
6+
class Exception extends RuntimeException {
57
}

src/Builder/Expr/DBExprFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Exception;
55

66
class DBExprFilter implements OptionalExpression {
7-
/** @var */
7+
/** @var mixed */
88
private $expression;
99
/** @var mixed */
1010
private $value;

src/Builder/Helpers/YieldPolyfillIterator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Closure;
55
use Iterator;
66
use Kir\MySQL\Builder\QueryStatement;
7+
use RuntimeException;
78

89
class YieldPolyfillIterator implements Iterator {
910
/** @var Closure|null */
@@ -88,7 +89,7 @@ public function valid() {
8889
*/
8990
public function rewind() {
9091
if($this->stmt !== null) {
91-
throw new \Exception("It's not possible to rewind this iterator");
92+
throw new RuntimeException("It's not possible to rewind this iterator");
9293
}
9394
$this->stmt = call_user_func($this->statementFactory);
9495
$this->idx = -1;

src/Builder/Insert.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public function addOrUpdate($field, $value) {
8484

8585
/**
8686
* @param string $str
87-
* @param string ...$params
87+
* @param string ...$_
8888
* @return $this
8989
*/
90-
public function addExpr($str) {
90+
public function addExpr($str, $_) {
9191
if(count(func_get_args()) > 1) {
9292
$this->fields[] = func_get_args();
9393
} else {
@@ -98,10 +98,10 @@ public function addExpr($str) {
9898

9999
/**
100100
* @param string $str
101-
* @param string ...$params
101+
* @param string ...$_
102102
* @return $this
103103
*/
104-
public function updateExpr($str) {
104+
public function updateExpr($str, $_) {
105105
if(count(func_get_args()) > 1) {
106106
$this->update[] = func_get_args();
107107
} else {

src/Builder/InsertUpdateStatement.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setMask(array $mask) {
2626
/**
2727
* @param array $fields
2828
* @param array $query
29-
* @return string
29+
* @return string[]
3030
*/
3131
protected function buildFieldList(array $fields, array $query = array()) {
3232
foreach ($fields as $fieldName => $fieldValue) {

src/Builder/RunnableSelect.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Kir\MySQL\Builder\Helpers\YieldPolyfillIterator;
1212
use Kir\MySQL\Databases\MySQL;
1313
use PDO;
14+
use RuntimeException;
1415
use Traversable;
1516

1617
/**
@@ -193,7 +194,7 @@ public function fetchValue($default = null) {
193194
}
194195

195196
/**
196-
* @return bool
197+
* @return int
197198
*/
198199
public function getFoundRows() {
199200
return $this->foundRows;
@@ -202,14 +203,14 @@ public function getFoundRows() {
202203
/**
203204
* @param callback $fn
204205
* @return mixed
205-
* @throws \Exception
206+
* @throws RuntimeException
206207
*/
207208
private function createTempStatement($fn) {
208209
$stmt = $this->createStatement();
209210
$res = null;
210211
try {
211212
$res = call_user_func($fn, $stmt);
212-
} catch (\Exception $e) { // PHP 5.4 compatibility
213+
} catch (RuntimeException $e) { // PHP 5.4 compatibility
213214
$stmt->closeCursor();
214215
throw $e;
215216
}
@@ -221,6 +222,7 @@ private function createTempStatement($fn) {
221222
* @return QueryStatement
222223
*/
223224
private function createStatement() {
225+
/** @var MySQL $db */
224226
$db = $this->db();
225227
$query = $this->__toString();
226228
$statement = $db->prepare($query);
@@ -243,7 +245,7 @@ public function getIterator() {
243245
* @param int $mode
244246
* @param mixed $arg0
245247
* @return mixed
246-
* @throws \Exception
248+
* @throws RuntimeException
247249
*/
248250
private function fetchAll(Closure $callback = null, $mode, $arg0 = null) {
249251
return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) {
@@ -276,7 +278,7 @@ private function fetchAll(Closure $callback = null, $mode, $arg0 = null) {
276278
* @param Closure $callback
277279
* @param int $mode
278280
* @param mixed $arg0
279-
* @return Generator|YieldPolyfillIterator|mixed[]
281+
* @return Traversable|YieldPolyfillIterator|mixed[]
280282
*/
281283
private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) {
282284
if(version_compare(PHP_VERSION, '5.5', '<')) {

src/Builder/Traits/HavingBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ trait HavingBuilder {
1212

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

src/Builder/Traits/WhereBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ trait WhereBuilder {
1212

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

src/Builder/Update.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function setDefault($fieldName) {
5959

6060
/**
6161
* @param string $expr
62-
* @param string[] ...$value
62+
* @param string[] ...$_
6363
* @return $this
6464
*/
65-
public function setExpr($expr) {
65+
public function setExpr($expr, $_) {
6666
$this->fields[] = func_get_args();
6767
return $this;
6868
}

src/QueryLogger/QueryLoggers.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
namespace Kir\MySQL\QueryLogger;
33

44
class QueryLoggers {
5-
/**
6-
* @var QueryLogger[]
7-
*/
5+
/** @var QueryLogger[] */
86
private $queryLoggers = [];
97

108
/**

src/Tools/AliasRegistry.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
namespace Kir\MySQL\Tools;
33

4+
use RuntimeException;
5+
46
class AliasRegistry {
5-
/**
6-
* @var string[]
7-
*/
8-
private $aliases = array();
7+
/** @var string[] */
8+
private $aliases = [];
99

1010
/**
1111
* @param string $alias
@@ -19,12 +19,12 @@ public function add($alias, $string) {
1919

2020
/**
2121
* @param string $alias
22-
* @throws \Exception
22+
* @throws RuntimeException
2323
* @return string
2424
*/
2525
public function get($alias) {
2626
if (!array_key_exists($alias, $this->aliases)) {
27-
throw new \Exception("Alias not found: {$alias}");
27+
throw new RuntimeException("Alias not found: {$alias}");
2828
}
2929
return $this->aliases[$alias];
3030
}

src/Tools/AliasReplacer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
namespace Kir\MySQL\Tools;
33

44
class AliasReplacer {
5-
/**
6-
* @var AliasRegistry
7-
*/
5+
/** @var AliasRegistry */
86
private $aliasRegistry;
97

108
/**

0 commit comments

Comments
 (0)