Skip to content

Commit 0e38c35

Browse files
authored
Merge pull request #4 from rcrdortiz/fix/repository-build-handler-db-names-mappings
Fix Repository build handler db names mappings
2 parents 1623ebd + ad5a9f2 commit 0e38c35

File tree

16 files changed

+311
-152
lines changed

16 files changed

+311
-152
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: '8.1'
20+
php-version: '8.3'
2121
coverage: xdebug
2222

2323
- name: Install dependencies

.github/workflows/psalm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: '8.1'
19+
php-version: '8.3'
2020

2121
- name: Install dependencies
2222
run: composer install --prefer-dist --no-progress

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea
2+
.DS_Store
3+
dev.php
24
vendor
35
composer.lock
46
.phpunit.result.cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "library",
55
"version": "1.0.2",
66
"require": {
7-
"php": ">=8.1",
7+
"php": ">=8.3",
88
"ext-mysqli": "*",
99
"ext-pdo": "*"
1010
},

src/ClassBuilder/BuildContext.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88

99
/**
10+
* @psalm-suppress PossiblyUnusedProperty
1011
* Class BuildOutput
1112
*
1213
* This class encapsulates the output of a build process for handling methods and properties
@@ -24,8 +25,8 @@ class BuildContext {
2425

2526
/**
2627
* Constructor for the BuildOutput class.
27-
*
28-
* @param Kmap $methods List of methods in the output.
28+
**
29+
* @param Kmap $methods List of methods in the output.
2930
* @param Kmap $properties List of class properties in the output.
3031
*/
3132
public function __construct(
@@ -40,8 +41,8 @@ public function __construct(
4041
* Add a method with its signature and implementation to the output.
4142
* Modifies the internal state directly.
4243
*
43-
* @param string $name The method name.
44-
* @param string $signature The method signature.
44+
* @param string $name The method name.
45+
* @param string $signature The method signature.
4546
* @param string $implementation The method implementation.
4647
*
4748
* @return void
@@ -55,7 +56,7 @@ public function addMethod( string $name, string $signature, string $implementati
5556
* Add a property to the output.
5657
* Modifies the internal state directly.
5758
*
58-
* @param string $name The property name.
59+
* @param string $name The property name.
5960
* @param string $implementation The property implementation.
6061
*
6162
* @return void
@@ -76,7 +77,7 @@ public function addProperty( string $name, string $implementation ): void {
7677
*/
7778
public function injectProperty( string $name, string $class ): string {
7879
$this->addProperty(
79-
name: $class,
80+
name: $class,
8081
implementation: "#[" . Inject::class . "] private $class \$$name;",
8182
);
8283

@@ -89,10 +90,10 @@ public function injectProperty( string $name, string $class ): string {
8990
*
9091
* @psalm-suppress PossiblyUnusedMethod
9192
*
92-
* @param Kmap $methods List of methods to append.
93+
* @param Kmap $methods List of methods to append.
9394
* @param Kmap $properties List of properties to append.
9495
*
95-
// * @return void
96+
* // * @return void
9697
*/
9798
public function add( Kmap $methods, Kmap $properties ): void {
9899
$this->methods->merge( $methods );

src/ClassBuilder/ClassBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function build( string $class ): string {
7979
*/
8080
private function generateProxyClass( string $class, BuildContext $buildOutput ): string {
8181
// Generate a unique proxy class name by replacing backslashes in the class name.
82-
$proxiedClassName = str_replace( "\\", '_', $class );
82+
$proxiedClassName = str_replace( "\\", '_', $class ) . 'Proxy';
8383

8484
// Define whether the proxy class extends or implements the original class.
8585
$inheritanceType = $this->reflect->isInterface( $class ) ? 'implements' : 'extends';

src/Collection/CollectionInterface.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public function isNotEmpty(): bool;
4646
* Filter the collection based on a predicate.
4747
*
4848
* @param Closure(TValue):bool $predicate
49+
*
4950
* @return static
5051
*/
51-
public function filter(Closure $predicate): static;
52+
public function filter( Closure $predicate ): static;
5253

5354
/**
5455
* Filter out null values from the collection.
@@ -62,25 +63,28 @@ public function filterNotNull(): static;
6263
*
6364
* @template TOut
6465
* @param Closure(TValue):TOut $transform
66+
*
6567
* @return CollectionInterface<TKey, TOut>
6668
*/
67-
public function map(Closure $transform): CollectionInterface;
69+
public function map( Closure $transform ): CollectionInterface;
6870

6971
/**
7072
* Execute a function for each element in the collection.
7173
*
7274
* @param Closure(TValue):void $transform
75+
*
7376
* @return static
7477
*/
75-
public function foreach(Closure $transform): static;
78+
public function foreach( Closure $transform ): static;
7679

7780
/**
7881
* Determine if any element in the collection satisfies a predicate.
7982
*
8083
* @param Closure(TValue):bool $predicate
84+
*
8185
* @return bool
8286
*/
83-
public function any(Closure $predicate): bool;
87+
public function any( Closure $predicate ): bool;
8488

8589
/**
8690
* Retrieve the first element in the collection or null if empty.
@@ -93,25 +97,28 @@ public function firstOrNull(): mixed;
9397
* Determine if all elements in the collection satisfy a predicate.
9498
*
9599
* @param Closure(TValue):bool $predicate
100+
*
96101
* @return bool
97102
*/
98-
public function all(Closure $predicate): bool;
103+
public function all( Closure $predicate ): bool;
99104

100105
/**
101106
* Merge the collection with another array.
102107
*
103108
* @param array<TKey, TValue> $array
109+
*
104110
* @return static
105111
*/
106-
public function mergeArray(array $array): static;
112+
public function mergeArray( array $array ): static;
107113

108114
/**
109115
* Merge the collection with another collection.
110116
*
111117
* @param CollectionInterface<TKey, TValue> $collection
118+
*
112119
* @return static
113120
*/
114-
public function merge(CollectionInterface $collection): static;
121+
public function merge( CollectionInterface $collection ): static;
115122

116123
/**
117124
* Join elements of the collection into a string with a separator.
@@ -120,7 +127,7 @@ public function merge(CollectionInterface $collection): static;
120127
*
121128
* @return string
122129
*/
123-
public function join(string $separator): string;
130+
public function join( string $separator ): string;
124131

125132
/**
126133
* Apply a predicate if the collection is not empty.
@@ -131,7 +138,7 @@ public function join(string $separator): string;
131138
*
132139
* @return static
133140
*/
134-
public function maybe(Closure $predicate): static;
141+
public function maybe( Closure $predicate ): static;
135142

136143
/**
137144
* Convert the collection to a mutable variant.
@@ -157,4 +164,23 @@ public function toImmutable(): static;
157164
* @return static
158165
*/
159166
public function flatten(): static;
167+
168+
/**
169+
* Reduce the collection to a single value using a callback.
170+
*
171+
* @psalm-suppress PossiblyUnusedMethod
172+
*
173+
* @param Closure(mixed, TValue):mixed $transform
174+
* @param mixed|null $initial
175+
*
176+
* @return mixed
177+
*/
178+
public function reduce( Closure $transform, mixed $initial = null ): mixed;
179+
180+
/**
181+
* Returns the current item and advances the internal pointer.
182+
*
183+
* @return TValue|null
184+
*/
185+
public function nextAndGet(): mixed;
160186
}

src/Collection/Klist.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ public function next(): void {
170170
$this->internalMap->next();
171171
}
172172

173+
/**
174+
* Returns the current item and advances the internal pointer.
175+
*
176+
* @return TValue|null
177+
*/
178+
#[Override]
179+
public function nextAndGet(): mixed {
180+
return $this->internalMap->nextAndGet();
181+
}
182+
173183
#[Override]
174184
public function key(): mixed {
175185
return $this->internalMap->key();
@@ -257,4 +267,17 @@ public function firstOrNull(): mixed {
257267
public function mapOf( Closure $transform ): KMap {
258268
return $this->internalMap->map( fn( $key, $value ) => $transform( $value ) );
259269
}
270+
271+
/**
272+
* Reduce the collection to a single value.
273+
*
274+
* @param Closure(mixed, TValue):mixed $transform
275+
* @param mixed|null $initial
276+
*
277+
* @return mixed
278+
*/
279+
#[Override]
280+
public function reduce( Closure $transform, mixed $initial = null ): mixed {
281+
return $this->internalMap->reduce( $transform, $initial );
282+
}
260283
}

src/Collection/Kmap.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Kmap implements CollectionInterface {
2424

2525
/**
2626
* @param array<TKey, TValue> $array
27-
* @param bool $mutable
27+
* @param bool $mutable
2828
*/
2929
public function __construct( array $array = [], private readonly bool $mutable = false ) {
3030
$this->keys = array_keys( $array );
@@ -46,6 +46,19 @@ public function next(): void {
4646
$this->index ++;
4747
}
4848

49+
/**
50+
* Returns the current item and advances the internal pointer.
51+
*
52+
* @return TValue|null
53+
*/
54+
#[Override]
55+
public function nextAndGet(): mixed {
56+
$current = $this->current();
57+
$this->next();
58+
59+
return $current;
60+
}
61+
4962
#[Override]
5063
public function valid(): bool {
5164
return isset( $this->keys[ $this->index ] ) && array_key_exists( $this->keys[ $this->index ], $this->array );
@@ -216,6 +229,7 @@ public function merge( CollectionInterface $collection ): static {
216229
* @template TMapKey of array-key
217230
* @template TMapValue
218231
* @param Closure(TKey, TValue): array<TMapKey, TMapValue> $transform
232+
*
219233
* @return Kmap<TMapKey, TMapValue>
220234
*/
221235
#[Override]
@@ -329,7 +343,7 @@ public function firstOrNull(): mixed {
329343
}
330344

331345
/**
332-
* @param TKey $key
346+
* @param TKey $key
333347
* @param TValue $element
334348
*
335349
* @return void
@@ -348,4 +362,22 @@ public function resetKeys(): void {
348362
$this->array = array_values( $this->array );
349363
$this->keys = array_keys( $this->array );
350364
}
365+
366+
/**
367+
* Reduce the collection to a single value.
368+
*
369+
* @param Closure(mixed, TValue):mixed $transform
370+
* @param mixed|null $initial
371+
*
372+
* @return mixed
373+
*/
374+
#[Override]
375+
public function reduce( Closure $transform, mixed $initial = null ): mixed {
376+
$carry = $initial;
377+
foreach ( $this->array as $element ) {
378+
$carry = $transform( $carry, $element );
379+
}
380+
381+
return $carry;
382+
}
351383
}

src/Repository/Handler/ParsedMethodPart.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88
/**
99
* @psalm-suppress PossiblyUnusedProperty
1010
*/
11-
class ParsedMethodPart {
11+
readonly class ParsedMethodPart {
1212
public function __construct(
13-
public readonly Prefix $prefix,
14-
public readonly LogicOperator $logicOperator,
15-
public readonly string $field,
16-
public readonly Operator $operator,
13+
public Prefix $prefix,
14+
public LogicOperator $logicOperator,
15+
public string $field,
16+
public Operator $operator,
1717
) {
1818
}
19+
20+
public function copy(
21+
?Prefix $prefix = null,
22+
?LogicOperator $logicOperator = null,
23+
?string $field = null,
24+
?Operator $operator = null,
25+
): self {
26+
return new self(
27+
prefix: $prefix ?? $this->prefix,
28+
logicOperator: $logicOperator ?? $this->logicOperator,
29+
field: $field ?? $this->field,
30+
operator: $operator ?? $this->operator,
31+
);
32+
}
1933
}

0 commit comments

Comments
 (0)