Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'
coverage: xdebug

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'

- name: Install dependencies
run: composer install --prefer-dist --no-progress
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
.DS_Store
dev.php
vendor
composer.lock
.phpunit.result.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"version": "1.0.2",
"require": {
"php": ">=8.1",
"php": ">=8.3",
"ext-mysqli": "*",
"ext-pdo": "*"
},
Expand Down
17 changes: 9 additions & 8 deletions src/ClassBuilder/BuildContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;

/**
* @psalm-suppress PossiblyUnusedProperty
* Class BuildOutput
*
* This class encapsulates the output of a build process for handling methods and properties
Expand All @@ -24,8 +25,8 @@ class BuildContext {

/**
* Constructor for the BuildOutput class.
*
* @param Kmap $methods List of methods in the output.
**
* @param Kmap $methods List of methods in the output.
* @param Kmap $properties List of class properties in the output.
*/
public function __construct(
Expand All @@ -40,8 +41,8 @@ public function __construct(
* Add a method with its signature and implementation to the output.
* Modifies the internal state directly.
*
* @param string $name The method name.
* @param string $signature The method signature.
* @param string $name The method name.
* @param string $signature The method signature.
* @param string $implementation The method implementation.
*
* @return void
Expand All @@ -55,7 +56,7 @@ public function addMethod( string $name, string $signature, string $implementati
* Add a property to the output.
* Modifies the internal state directly.
*
* @param string $name The property name.
* @param string $name The property name.
* @param string $implementation The property implementation.
*
* @return void
Expand All @@ -76,7 +77,7 @@ public function addProperty( string $name, string $implementation ): void {
*/
public function injectProperty( string $name, string $class ): string {
$this->addProperty(
name: $class,
name: $class,
implementation: "#[" . Inject::class . "] private $class \$$name;",
);

Expand All @@ -89,10 +90,10 @@ public function injectProperty( string $name, string $class ): string {
*
* @psalm-suppress PossiblyUnusedMethod
*
* @param Kmap $methods List of methods to append.
* @param Kmap $methods List of methods to append.
* @param Kmap $properties List of properties to append.
*
// * @return void
* // * @return void
*/
public function add( Kmap $methods, Kmap $properties ): void {
$this->methods->merge( $methods );
Expand Down
2 changes: 1 addition & 1 deletion src/ClassBuilder/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function build( string $class ): string {
*/
private function generateProxyClass( string $class, BuildContext $buildOutput ): string {
// Generate a unique proxy class name by replacing backslashes in the class name.
$proxiedClassName = str_replace( "\\", '_', $class );
$proxiedClassName = str_replace( "\\", '_', $class ) . 'Proxy';

// Define whether the proxy class extends or implements the original class.
$inheritanceType = $this->reflect->isInterface( $class ) ? 'implements' : 'extends';
Expand Down
44 changes: 35 additions & 9 deletions src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ public function isNotEmpty(): bool;
* Filter the collection based on a predicate.
*
* @param Closure(TValue):bool $predicate
*
* @return static
*/
public function filter(Closure $predicate): static;
public function filter( Closure $predicate ): static;

/**
* Filter out null values from the collection.
Expand All @@ -62,25 +63,28 @@ public function filterNotNull(): static;
*
* @template TOut
* @param Closure(TValue):TOut $transform
*
* @return CollectionInterface<TKey, TOut>
*/
public function map(Closure $transform): CollectionInterface;
public function map( Closure $transform ): CollectionInterface;

/**
* Execute a function for each element in the collection.
*
* @param Closure(TValue):void $transform
*
* @return static
*/
public function foreach(Closure $transform): static;
public function foreach( Closure $transform ): static;

/**
* Determine if any element in the collection satisfies a predicate.
*
* @param Closure(TValue):bool $predicate
*
* @return bool
*/
public function any(Closure $predicate): bool;
public function any( Closure $predicate ): bool;

/**
* Retrieve the first element in the collection or null if empty.
Expand All @@ -93,25 +97,28 @@ public function firstOrNull(): mixed;
* Determine if all elements in the collection satisfy a predicate.
*
* @param Closure(TValue):bool $predicate
*
* @return bool
*/
public function all(Closure $predicate): bool;
public function all( Closure $predicate ): bool;

/**
* Merge the collection with another array.
*
* @param array<TKey, TValue> $array
*
* @return static
*/
public function mergeArray(array $array): static;
public function mergeArray( array $array ): static;

/**
* Merge the collection with another collection.
*
* @param CollectionInterface<TKey, TValue> $collection
*
* @return static
*/
public function merge(CollectionInterface $collection): static;
public function merge( CollectionInterface $collection ): static;

/**
* Join elements of the collection into a string with a separator.
Expand All @@ -120,7 +127,7 @@ public function merge(CollectionInterface $collection): static;
*
* @return string
*/
public function join(string $separator): string;
public function join( string $separator ): string;

/**
* Apply a predicate if the collection is not empty.
Expand All @@ -131,7 +138,7 @@ public function join(string $separator): string;
*
* @return static
*/
public function maybe(Closure $predicate): static;
public function maybe( Closure $predicate ): static;

/**
* Convert the collection to a mutable variant.
Expand All @@ -157,4 +164,23 @@ public function toImmutable(): static;
* @return static
*/
public function flatten(): static;

/**
* Reduce the collection to a single value using a callback.
*
* @psalm-suppress PossiblyUnusedMethod
*
* @param Closure(mixed, TValue):mixed $transform
* @param mixed|null $initial
*
* @return mixed
*/
public function reduce( Closure $transform, mixed $initial = null ): mixed;

/**
* Returns the current item and advances the internal pointer.
*
* @return TValue|null
*/
public function nextAndGet(): mixed;
}
23 changes: 23 additions & 0 deletions src/Collection/Klist.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ public function next(): void {
$this->internalMap->next();
}

/**
* Returns the current item and advances the internal pointer.
*
* @return TValue|null
*/
#[Override]
public function nextAndGet(): mixed {
return $this->internalMap->nextAndGet();
}

#[Override]
public function key(): mixed {
return $this->internalMap->key();
Expand Down Expand Up @@ -257,4 +267,17 @@ public function firstOrNull(): mixed {
public function mapOf( Closure $transform ): KMap {
return $this->internalMap->map( fn( $key, $value ) => $transform( $value ) );
}

/**
* Reduce the collection to a single value.
*
* @param Closure(mixed, TValue):mixed $transform
* @param mixed|null $initial
*
* @return mixed
*/
#[Override]
public function reduce( Closure $transform, mixed $initial = null ): mixed {
return $this->internalMap->reduce( $transform, $initial );
}
}
36 changes: 34 additions & 2 deletions src/Collection/Kmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Kmap implements CollectionInterface {

/**
* @param array<TKey, TValue> $array
* @param bool $mutable
* @param bool $mutable
*/
public function __construct( array $array = [], private readonly bool $mutable = false ) {
$this->keys = array_keys( $array );
Expand All @@ -46,6 +46,19 @@ public function next(): void {
$this->index ++;
}

/**
* Returns the current item and advances the internal pointer.
*
* @return TValue|null
*/
#[Override]
public function nextAndGet(): mixed {
$current = $this->current();
$this->next();

return $current;
}

#[Override]
public function valid(): bool {
return isset( $this->keys[ $this->index ] ) && array_key_exists( $this->keys[ $this->index ], $this->array );
Expand Down Expand Up @@ -216,6 +229,7 @@ public function merge( CollectionInterface $collection ): static {
* @template TMapKey of array-key
* @template TMapValue
* @param Closure(TKey, TValue): array<TMapKey, TMapValue> $transform
*
* @return Kmap<TMapKey, TMapValue>
*/
#[Override]
Expand Down Expand Up @@ -329,7 +343,7 @@ public function firstOrNull(): mixed {
}

/**
* @param TKey $key
* @param TKey $key
* @param TValue $element
*
* @return void
Expand All @@ -348,4 +362,22 @@ public function resetKeys(): void {
$this->array = array_values( $this->array );
$this->keys = array_keys( $this->array );
}

/**
* Reduce the collection to a single value.
*
* @param Closure(mixed, TValue):mixed $transform
* @param mixed|null $initial
*
* @return mixed
*/
#[Override]
public function reduce( Closure $transform, mixed $initial = null ): mixed {
$carry = $initial;
foreach ( $this->array as $element ) {
$carry = $transform( $carry, $element );
}

return $carry;
}
}
24 changes: 19 additions & 5 deletions src/Repository/Handler/ParsedMethodPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@
/**
* @psalm-suppress PossiblyUnusedProperty
*/
class ParsedMethodPart {
readonly class ParsedMethodPart {
public function __construct(
public readonly Prefix $prefix,
public readonly LogicOperator $logicOperator,
public readonly string $field,
public readonly Operator $operator,
public Prefix $prefix,
public LogicOperator $logicOperator,
public string $field,
public Operator $operator,
) {
}

public function copy(
?Prefix $prefix = null,
?LogicOperator $logicOperator = null,
?string $field = null,
?Operator $operator = null,
): self {
return new self(
prefix: $prefix ?? $this->prefix,
logicOperator: $logicOperator ?? $this->logicOperator,
field: $field ?? $this->field,
operator: $operator ?? $this->operator,
);
}
}
Loading