Skip to content

Commit cc61557

Browse files
committed
Add better flattened fields implementation
- Add BuilderInterface for all builder classes, moved this from the entities package - Add flattened fields trait from entities package to use the same logic about type casting here - Usages of the library should not break in any way, but because flattened fields are now more strict this will be a new "breaking" version
1 parent 23b3f19 commit cc61557

31 files changed

+838
-130
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.4",
22+
"php": ">=7.4",
2323
"ext-pdo": "*",
2424
"squirrelphp/debug": "^0.5",
2525
"doctrine/dbal": "^2.5"

docker/compose-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
POSTGRES_PASSWORD: 'password'
4141

4242
squirrel_queries_mysql:
43-
image: mysql/mysql-server:8.0
43+
image: mysql/mysql-server:latest
4444
container_name: squirrel_queries_mysql
4545
command: --default-authentication-plugin=mysql_native_password
4646
environment:

docker/test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
# Get directory of this script
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

5+
# Remove all running docker containers
6+
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v --remove-orphans
7+
58
# Test SQLite and real live tests with PostgreSQL and MySQL
6-
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." up --build --force-recreate --renew-anon-volumes squirrel_queries_74
9+
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." up --build --force-recreate --renew-anon-volumes squirrel_queries_74
10+
11+
# Remove all running docker containers
12+
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v

docker/test-pull

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

55
# Remove all running docker containers
6-
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v
6+
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." down -v --remove-orphans
77

88
# Pull new docker images in case there were updates
99
docker-compose -f "$DIR/compose-test.yml" --project-directory "$DIR/.." pull

phpstan-baseline.neon

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
parameters:
2-
ignoreErrors:
2+
ignoreErrors:
3+
-
4+
message: "#^Method Squirrel\\\\Queries\\\\Builder\\\\SelectEntries\\:\\:getFlattenedIntegerFields\\(\\) should return array\\<int\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
5+
count: 1
6+
path: src/Builder/SelectEntries.php
7+
8+
-
9+
message: "#^Method Squirrel\\\\Queries\\\\Builder\\\\SelectEntries\\:\\:getFlattenedFloatFields\\(\\) should return array\\<float\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
10+
count: 1
11+
path: src/Builder/SelectEntries.php
12+
13+
-
14+
message: "#^Method Squirrel\\\\Queries\\\\Builder\\\\SelectEntries\\:\\:getFlattenedStringFields\\(\\) should return array\\<string\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
15+
count: 1
16+
path: src/Builder/SelectEntries.php
17+
18+
-
19+
message: "#^Method Squirrel\\\\Queries\\\\Builder\\\\SelectEntries\\:\\:getFlattenedBooleanFields\\(\\) should return array\\<bool\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
20+
count: 1
21+
path: src/Builder/SelectEntries.php
22+

psalm-baseline.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
2+
<files psalm-version="3.14.2@3538fe1955d47f6ee926c0769d71af6db08aa488">
3+
<file src="src/Builder/FlattenedFieldsWithTypeTrait.php">
4+
<InvalidReturnType occurrences="4">
5+
<code>int[]</code>
6+
<code>float[]</code>
7+
<code>string[]</code>
8+
<code>bool[]</code>
9+
</InvalidReturnType>
10+
</file>
311
<file src="src/Builder/SelectIteratorTrait.php">
412
<ImplementedReturnTypeMismatch occurrences="1">
513
<code>int</code>

ruleset.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,23 @@
3737
</properties>
3838
</rule>
3939
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
40+
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
41+
<rule ref="SlevomatCodingStandard.Functions.StrictCall"/>
42+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
43+
<rule ref="SlevomatCodingStandard.PHP.DisallowReference"/>
44+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
45+
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
46+
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
47+
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/>
48+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
49+
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
50+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
51+
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
52+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
53+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
54+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
55+
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
56+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
57+
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
58+
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/>
4059
</ruleset>

src/Builder/BuilderInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Squirrel\Queries\Builder;
4+
5+
/**
6+
* Marker for query builder actions so an exception can reference the right origin (higher up in stack trace)
7+
*/
8+
interface BuilderInterface
9+
{
10+
}

src/Builder/CountEntries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Count query builder as a fluent object - build query and return entries or flattened fields
99
*/
10-
class CountEntries
10+
class CountEntries implements BuilderInterface
1111
{
1212
private DBInterface $db;
1313

src/Builder/DeleteEntries.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Delete query builder as a fluent object - build query and execute it
1111
*/
12-
class DeleteEntries
12+
class DeleteEntries implements BuilderInterface
1313
{
1414
private DBInterface $db;
1515
private string $table = '';
@@ -81,7 +81,7 @@ private function accidentalDeleteAllCheck(): void
8181
DBInvalidOptionException::class,
8282
[self::class],
8383
'No restricting "where" arguments defined for DELETE' .
84-
'and no override confirmation with "confirmNoWhereRestrictions" call'
84+
'and no override confirmation with "confirmNoWhereRestrictions" call',
8585
);
8686
}
8787
}

0 commit comments

Comments
 (0)