Skip to content

Commit bdf7861

Browse files
committed
- Raised PHP min version to 7.0
- Various minor changes
1 parent 3097a52 commit bdf7861

32 files changed

+142
-166
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ php:
66
- 7.2
77
- 7.1
88
- 7.0
9-
- 5.6
109

1110
services:
1211
- mysql

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mysql query builder (php 5.6+)
1+
mysql query builder (php 7.0+)
22
==============================
33

44
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a57881f2-af75-48b7-9f5f-e821cdb75d0c/mini.png)](https://insight.sensiolabs.com/projects/a57881f2-af75-48b7-9f5f-e821cdb75d0c)

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
"email": "[email protected]"
88
}],
99
"require": {
10-
"php": ">= 5.6",
10+
"php": ">= 7.0",
1111
"ext-pdo": "*",
1212
"ext-spl": "*",
13+
"ext-ctype": "*",
1314
"psr/log": "~1"
1415
},
1516
"require-dev": {
1617
"phpunit/phpunit": "~5.0",
1718
"phake/phake": "1.0.5",
19+
"phpstan/phpstan": "*@stable",
1820
"rkr/fakepdo": "0.1.*"
1921
},
2022
"autoload": {

src/Builder/DBExpr.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Kir\MySQL\Builder;
43

54
class DBExpr {

src/Builder/Delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function from($alias, $table = null) {
4141
*/
4242
public function __toString() {
4343
$query = "DELETE ";
44-
$query .= join(', ', $this->aliases);
44+
$query .= implode(', ', $this->aliases);
4545
$query = trim($query) . " FROM\n";
4646
$query = $this->buildTables($query);
4747
$query = $this->buildJoins($query);

src/Builder/Expr/DBExprFilter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($expression, array $data, $keyPath, $validator = nul
3636
};
3737
}
3838
if($validationResultHandler === null) {
39-
$validationResultHandler = function () {};
39+
$validationResultHandler = static function () {};
4040
}
4141
$this->validator = $validator;
4242
$this->validationResultHandler = $validationResultHandler;
@@ -56,7 +56,7 @@ public function isValid() {
5656
$result = call_user_func($this->validator, $this->value);
5757
call_user_func($this->validationResultHandler, $result, [
5858
'value' => $this->value,
59-
'key' => join('.', $this->keyPath),
59+
'key' => implode('.', $this->keyPath),
6060
]);
6161
return $result;
6262
}
@@ -107,8 +107,8 @@ private function recursiveGet($array, $path, $default) {
107107
if (!$count) {
108108
return $default;
109109
}
110-
for($idx = 0; $idx < $count; $idx++) {
111-
$part = $path[$idx];
110+
foreach($path as $idxValue) {
111+
$part = $idxValue;
112112
if(!array_key_exists($part, $array)) {
113113
return $default;
114114
}

src/Builder/Expr/OptionalDBFilterMap.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class OptionalDBFilterMap {
88
/**
99
* @param array $map
1010
*/
11-
public function __construct(array $map) {
11+
final public function __construct(array $map) {
1212
$this->map = $map;
1313
}
1414

@@ -20,6 +20,13 @@ public static function from(array $map) {
2020
return new static($map);
2121
}
2222

23+
/**
24+
* @return array
25+
*/
26+
protected function getMap(): array {
27+
return $this->map;
28+
}
29+
2330
/**
2431
* @param string $expression
2532
* @param string|string[] $keyPath

src/Builder/Expr/RequiredDBFilterMap.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class RequiredDBFilterMap {
88
/**
99
* @param array $map
1010
*/
11-
public function __construct(array $map) {
11+
final public function __construct(array $map) {
1212
$this->map = $map;
1313
}
1414

@@ -20,14 +20,21 @@ public static function from(array $map) {
2020
return new static($map);
2121
}
2222

23+
/**
24+
* @return array
25+
*/
26+
protected function getMap(): array {
27+
return $this->map;
28+
}
29+
2330
/**
2431
* @param string $expression
2532
* @param string|string[] $keyPath
2633
* @param callable|null $validator
2734
* @return DBExprFilter
2835
*/
2936
public function __invoke($expression, $keyPath, $validator = null) {
30-
return new DBExprFilter($expression, $this->map, $keyPath, $validator, function ($result, array $data) {
37+
return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function ($result, array $data) {
3138
if(!$result) {
3239
throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key']));
3340
}

src/Builder/Insert.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class Insert extends InsertUpdateStatement {
1111
/** @var array */
1212
private $update = [];
1313
/** @var string */
14-
private $table = null;
14+
private $table;
1515
/** @var string */
16-
private $keyField = null;
16+
private $keyField;
1717
/** @var bool */
1818
private $ignore = false;
1919
/** @var Select */
20-
private $from = null;
20+
private $from;
2121

2222
/**
2323
* @param string $table
@@ -107,7 +107,7 @@ public function updateExpr($str, ...$args) {
107107
}
108108
return $this;
109109
}
110-
110+
111111
/**
112112
* @param string $expr
113113
* @param mixed ...$args
@@ -189,25 +189,23 @@ public function __toString() {
189189

190190
if($this->from !== null) {
191191
$fields = $this->from->getFields();
192-
$queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields)));
192+
$queryArr[] = sprintf("\t(%s)\n", implode(', ', array_keys($fields)));
193193
$queryArr[] = $this->from;
194194
} else {
195195
$fields = $this->fields;
196196
$insertData = $this->buildFieldList($fields);
197197
if (!count($insertData)) {
198198
throw new RuntimeException('No field-data found');
199199
}
200-
$queryArr[] = sprintf("SET\n%s\n", join(",\n", $insertData));
200+
$queryArr[] = sprintf("SET\n%s\n", implode(",\n", $insertData));
201201
}
202202

203203
$updateData = $this->buildUpdate();
204204
if($updateData) {
205205
$queryArr[] = "{$updateData}\n";
206206
}
207207

208-
$query = join('', $queryArr);
209-
210-
return $query;
208+
return implode('', $queryArr);
211209
}
212210

213211
/**
@@ -246,7 +244,7 @@ private function addAllTo(array $data, array $mask = null, array $excludeFields
246244
}
247245
$data = $this->clearValues($data);
248246
foreach ($data as $field => $value) {
249-
call_user_func($fn, $field, $value);
247+
$fn($field, $value);
250248
}
251249
return $this;
252250
}
@@ -264,9 +262,9 @@ private function buildUpdate() {
264262
}
265263
$updateArr = $this->buildFieldList($this->update, $updateArr);
266264

267-
$queryArr[] = join(",\n", $updateArr);
265+
$queryArr[] = implode(",\n", $updateArr);
268266
}
269-
return join('', $queryArr);
267+
return implode('', $queryArr);
270268
}
271269

272270
/**

src/Builder/InsertUpdateStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
abstract class InsertUpdateStatement extends Statement {
77
/** @var array */
8-
private $mask = null;
8+
private $mask;
99

1010
/**
1111
* @return array|null

0 commit comments

Comments
 (0)