Skip to content

Commit e9dd92d

Browse files
authored
Merge pull request #232 from simon-mundy/qa/mago-sql-dml
Bring the Sql DML classes to Mago compliance
2 parents 9d4f906 + 39c5278 commit e9dd92d

37 files changed

Lines changed: 981 additions & 1341 deletions

‎analyzer-baseline.toml‎

Lines changed: 225 additions & 993 deletions
Large diffs are not rendered by default.

‎lint-baseline.toml‎

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -342,24 +342,12 @@ code = "excessive-parameter-list"
342342
message = "Parameter list is too long."
343343
count = 1
344344

345-
[[issues]]
346-
file = "src/Sql/AbstractSql.php"
347-
code = "halstead"
348-
message = "Method has a high halstead difficulty"
349-
count = 1
350-
351345
[[issues]]
352346
file = "src/Sql/AbstractSql.php"
353347
code = "kan-defect"
354348
message = "Class has a high kan defect score."
355349
count = 1
356350

357-
[[issues]]
358-
file = "src/Sql/AbstractSql.php"
359-
code = "too-many-methods"
360-
message = "Class has too many methods."
361-
count = 1
362-
363351
[[issues]]
364352
file = "src/Sql/Combine.php"
365353
code = "cyclomatic-complexity"
@@ -372,24 +360,12 @@ code = "kan-defect"
372360
message = "Class has a high kan defect score."
373361
count = 1
374362

375-
[[issues]]
376-
file = "src/Sql/Combine.php"
377-
code = "no-array-accumulation-in-loop"
378-
message = "Array spread in reassignment inside a loop causes O(n²) array copying."
379-
count = 1
380-
381363
[[issues]]
382364
file = "src/Sql/Insert.php"
383365
code = "cyclomatic-complexity"
384366
message = "Class has high complexity."
385367
count = 1
386368

387-
[[issues]]
388-
file = "src/Sql/Insert.php"
389-
code = "too-many-methods"
390-
message = "Class has too many methods."
391-
count = 1
392-
393369
[[issues]]
394370
file = "src/Sql/Select.php"
395371
code = "cyclomatic-complexity"
@@ -400,44 +376,20 @@ count = 1
400376
file = "src/Sql/Select.php"
401377
code = "halstead"
402378
message = "Method has a high halstead difficulty"
403-
count = 2
379+
count = 1
404380

405381
[[issues]]
406382
file = "src/Sql/Select.php"
407383
code = "kan-defect"
408384
message = "Class has a high kan defect score."
409385
count = 1
410386

411-
[[issues]]
412-
file = "src/Sql/Select.php"
413-
code = "too-many-methods"
414-
message = "Class has too many methods."
415-
count = 1
416-
417-
[[issues]]
418-
file = "src/Sql/Select.php"
419-
code = "too-many-properties"
420-
message = "Class has too many properties."
421-
count = 1
422-
423387
[[issues]]
424388
file = "src/Sql/Update.php"
425389
code = "cyclomatic-complexity"
426390
message = "Class has high complexity."
427391
count = 1
428392

429-
[[issues]]
430-
file = "src/Sql/Update.php"
431-
code = "halstead"
432-
message = "Method has a high halstead difficulty"
433-
count = 1
434-
435-
[[issues]]
436-
file = "src/Sql/Update.php"
437-
code = "too-many-methods"
438-
message = "Class has too many methods."
439-
count = 1
440-
441393
[[issues]]
442394
file = "src/TableGateway/AbstractTableGateway.php"
443395
code = "cyclomatic-complexity"

‎mago.toml‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ baseline = "lint-baseline.toml"
1515
# Exception classes are message catalogues: one template and one named constructor per
1616
# condition, per the convention in docs/book/exceptions.md. The method count tracks the
1717
# number of distinct failures a component can report, so the maintainability signal does
18-
# not apply. Predicate, AlterTable and CreateTable are fluent builders: one public method per
19-
# clause they can emit, so their method count is the size of their public API. "test/"
20-
# repeats the phpdb-qa-tools default, which this key replaces.
18+
# not apply. Predicate, AlterTable, CreateTable, Select, Insert and Update are fluent builders:
19+
# one public method per clause they can emit, so their method count is the size of their
20+
# public API. AbstractSql is their base and carries one protected hook per clause it renders.
21+
# "test/" repeats the phpdb-qa-tools default, which this key replaces.
2122
too-many-methods = { exclude = [
2223
"test/",
2324
"src/Sql/Exception/",
@@ -27,8 +28,15 @@ too-many-methods = { exclude = [
2728
"src/Sql/Predicate/Predicate.php",
2829
"src/Sql/Ddl/AlterTable.php",
2930
"src/Sql/Ddl/CreateTable.php",
31+
"src/Sql/AbstractSql.php",
32+
"src/Sql/Select.php",
33+
"src/Sql/Insert.php",
34+
"src/Sql/Update.php",
3035
] }
3136

37+
# Select holds one property per clause of a SELECT statement.
38+
too-many-properties = { exclude = ["src/Sql/Select.php"] }
39+
3240
# These constructors take one argument per part of the SQL definition they model
3341
# (a foreign key's name, columns, reference table, reference columns and two rules; a
3442
# column's name, digits, scale, nullability, default and options). They are public API, so
@@ -48,6 +56,11 @@ prefer-self-return-type = { exclude = [
4856

4957
[analyzer]
5058
baseline = "analyzer-baseline.toml"
59+
# ArgumentType is string-backed and each case's value is a ::class constant, which PHP accepts
60+
# as a string. The analyzer reports the class-string type as not being a string.
61+
ignore = [
62+
{ code = "invalid-enum-case-value", in = ["src/Sql/ArgumentType.php"] },
63+
]
5164
class-initializers = [
5265
"PhpDb\\ResultSet\\AbstractResultSet::initialize",
5366
"PhpDb\\TableGateway\\Feature\\AbstractFeature::setTableGateway",

‎src/ResultSet/HydratingResultSet.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ArrayObject;
88
use Laminas\Hydrator\ArraySerializableHydrator;
9+
use Laminas\Hydrator\Exception\RuntimeException as HydratorRuntimeException;
910
use Laminas\Hydrator\HydratorInterface;
1011
use Override;
1112
use PhpDb\ResultSet\Exception\RuntimeException;
@@ -119,7 +120,7 @@ public function toArray(): array
119120
* Hydrate one row onto a clone of the prototype.
120121
*
121122
* @throws Exception\UnexpectedValueException If the row is not row data.
122-
* @throws \Laminas\Hydrator\Exception\RuntimeException If the hydrator cannot fill the prototype.
123+
* @throws HydratorRuntimeException If the hydrator cannot fill the prototype.
123124
*/
124125
#[Override]
125126
protected function mapRow(mixed $row): object

‎src/Sql/AbstractExpression.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace PhpDb\Sql;
66

7+
/**
8+
* @api
9+
*/
710
abstract class AbstractExpression implements ExpressionInterface
811
{
912
protected ?string $specification = null;

‎src/Sql/AbstractPreparableSql.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
use function array_values;
1313
use function is_array;
1414

15+
/**
16+
* @api
17+
*/
1518
abstract class AbstractPreparableSql extends AbstractSql implements PreparableSqlInterface
1619
{
20+
/**
21+
* @throws Exception\RuntimeException
22+
*/
1723
#[Override]
1824
public function prepareStatement(
1925
AdapterInterface $adapter,

0 commit comments

Comments
 (0)