Skip to content

Commit 133af25

Browse files
committed
Simplify code by extending variadic usage
1 parent 2385d30 commit 133af25

12 files changed

Lines changed: 27 additions & 37 deletions

File tree

src/core/etl/src/Flow/ETL/Constraint/SortedByConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ final class SortedByConstraint implements Constraint
1919

2020
private readonly References $references;
2121

22-
public function __construct(Reference $column, Reference ...$columns)
22+
public function __construct(Reference ...$columns)
2323
{
24-
$this->references = new References($column, ...$columns);
24+
$this->references = new References(...$columns);
2525
}
2626

2727
public function isSatisfiedBy(Row $row) : bool

src/core/etl/src/Flow/ETL/Constraint/UniqueConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ final class UniqueConstraint implements Constraint
1515

1616
private Storage $storage;
1717

18-
public function __construct(string|Reference $column, string|Reference ...$columns)
18+
public function __construct(string|Reference ...$columns)
1919
{
20-
$this->reference = refs($column, ...$columns);
20+
$this->reference = refs(...$columns);
2121
$this->storage = new InMemoryStorage();
2222
}
2323

src/core/etl/src/Flow/ETL/DSL/functions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,9 +2405,9 @@ function type_is(Type $type, string $typeClass) : bool
24052405
* @deprecated please use \Flow\Types\DSL\type_is_any($type, $typeClass, ...$typeClasses): bool instead
24062406
*/
24072407
#[DocumentationDSL(module: Module::DEPRECATED, type: DSLType::DEPRECATED)]
2408-
function type_is_any(Type $type, string $typeClass, string ...$typeClasses) : bool
2408+
function type_is_any(Type $type, string ...$typeClasses) : bool
24092409
{
2410-
return type_is_any_new($type, $typeClass, ...$typeClasses);
2410+
return type_is_any_new($type, ...$typeClasses);
24112411
}
24122412

24132413
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
@@ -2497,17 +2497,17 @@ function with_entry(string $name, ScalarFunction $function) : WithEntry
24972497
}
24982498

24992499
#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
2500-
function constraint_unique(string $reference, string ...$references) : UniqueConstraint
2500+
function constraint_unique(string ...$references) : UniqueConstraint
25012501
{
2502-
return new UniqueConstraint($reference, ...$references);
2502+
return new UniqueConstraint(...$references);
25032503
}
25042504

25052505
#[DocumentationDSL(module: Module::CORE, type: DSLType::HELPER)]
2506-
function constraint_sorted_by(string|Reference $column, string|Reference ...$columns) : SortedByConstraint
2506+
function constraint_sorted_by(string|Reference ...$columns) : SortedByConstraint
25072507
{
25082508
$references = \array_map(
25092509
static fn (string|Reference $ref) => EntryReference::init($ref),
2510-
[$column, ...$columns]
2510+
$columns,
25112511
);
25122512

25132513
return new SortedByConstraint(...$references);

src/core/etl/src/Flow/ETL/DataFrame.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ public function collectRefs(References $references) : self
205205
return $this;
206206
}
207207

208-
public function constrain(Constraint $constraint, Constraint ...$constraints) : self
208+
public function constrain(Constraint ...$constraints) : self
209209
{
210-
$constraints = \array_merge([$constraint], $constraints);
211-
212210
$this->pipeline->add(new ConstrainedProcessor($constraints));
213211

214212
return $this;
@@ -665,10 +663,8 @@ public function onError(ErrorHandler $handler) : self
665663
/**
666664
* @lazy
667665
*/
668-
public function partitionBy(string|Reference $entry, string|Reference ...$entries) : self
666+
public function partitionBy(string|Reference ...$entries) : self
669667
{
670-
\array_unshift($entries, $entry);
671-
672668
$this->pipeline->add(new PartitioningProcessor(References::init(...$entries)->all()));
673669

674670
return $this;

src/core/etl/src/Flow/ETL/Rows.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,15 @@ public function offsetUnset(mixed $offset) : void
583583
}
584584

585585
/**
586-
* @param Reference|string $reference
587586
* @param Reference|string ...$references
588587
*
589588
* @throws InvalidArgumentException
590589
*
591590
* @return array<Rows>
592591
*/
593-
public function partitionBy(string|Reference $reference, string|Reference ...$references) : array
592+
public function partitionBy(string|Reference ...$references) : array
594593
{
595-
$refs = References::init($reference, ...$references);
594+
$refs = References::init(...$references);
596595

597596
/** @var array<string, array<mixed>> $partitions */
598597
$partitions = [];

src/lib/filesystem/src/Flow/Filesystem/Path.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static function realpath(string $path, array|Options $options = []) : sel
4242
);
4343
}
4444

45-
public function addPartitions(Partition $partition, Partition ...$partitions) : self
45+
public function addPartitions(Partition ...$partitions) : self
4646
{
47-
return new self($this->implementation->addPartitions($partition, ...$partitions));
47+
return new self($this->implementation->addPartitions(...$partitions));
4848
}
4949

5050
public function basename() : string

src/lib/filesystem/src/Flow/Filesystem/Path/UnixPath.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function realpath(string $path, array|Options $options = []) : sel
9595
return new self('/' . \implode('/', $absoluteParts), $options);
9696
}
9797

98-
public function addPartitions(Partition $partition, Partition ...$partitions) : self
98+
public function addPartitions(Partition ...$partitions) : self
9999
{
100100
if ($this->isPattern()) {
101101
throw new InvalidArgumentException("Can't add partitions to path pattern.");
@@ -104,11 +104,10 @@ public function addPartitions(Partition $partition, Partition ...$partitions) :
104104
$pathInfo = \pathinfo($this->path);
105105
$dirname = $pathInfo['dirname'] ?? '';
106106
$basename = $pathInfo['basename'] ?? '';
107-
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, [$partition, ...$partitions]));
107+
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, $partitions));
108108

109109
return match ($dirname) {
110-
'', '.' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
111-
'/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
110+
'', '.', '/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),
112111
default => new self($this->protocol->scheme() . $dirname . '/' . $partitionsString . '/' . $basename, $this->options),
113112
};
114113
}

src/lib/filesystem/src/Flow/Filesystem/Path/WindowsPath.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static function realpath(string $path, array|Options $options = []) : sel
9191
return new self($drive . '/' . \implode('/', $absoluteParts), $options);
9292
}
9393

94-
public function addPartitions(Partition $partition, Partition ...$partitions) : self
94+
public function addPartitions(Partition ...$partitions) : self
9595
{
9696
if ($this->isPattern()) {
9797
throw new InvalidArgumentException("Can't add partitions to path pattern.");
@@ -100,7 +100,7 @@ public function addPartitions(Partition $partition, Partition ...$partitions) :
100100
$pathInfo = \pathinfo($this->path);
101101
$dirname = $pathInfo['dirname'] ?? '';
102102
$basename = $pathInfo['basename'] ?? '';
103-
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, [$partition, ...$partitions]));
103+
$partitionsString = \implode('/', \array_map(static fn (Partition $p) => $p->name . '=' . $p->value, $partitions));
104104

105105
return match ($dirname) {
106106
'', '.', '/', '\\' => new self($this->protocol->scheme() . '/' . $partitionsString . '/' . $basename, $this->options),

src/lib/types/src/Flow/Types/DSL/functions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,12 @@ function type_is(Type $type, string $typeClass) : bool
471471
* @template T
472472
*
473473
* @param Type<T> $type
474-
* @param class-string<Type<mixed>> $typeClass
475474
* @param class-string<Type<mixed>> ...$typeClasses
476475
*/
477476
#[DocumentationDSL(module: Module::TYPES, type: DSLType::HELPER)]
478-
function type_is_any(Type $type, string $typeClass, string ...$typeClasses) : bool
477+
function type_is_any(Type $type, string ...$typeClasses) : bool
479478
{
480-
return (new Comparator())->isAny($type, $typeClass, ...$typeClasses);
479+
return (new Comparator())->isAny($type, ...$typeClasses);
481480
}
482481

483482
/**

src/lib/types/src/Flow/Types/Type/Comparator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,11 @@ public function is(Type $type, string $typeClass) : bool
145145
* @template T
146146
*
147147
* @param Type<T> $type
148-
* @param class-string<Type<mixed>> $typeClass
149148
* @param class-string<Type<mixed>> ...$typeClasses
150149
*/
151-
public function isAny(Type $type, string $typeClass, string ...$typeClasses) : bool
150+
public function isAny(Type $type, string ...$typeClasses) : bool
152151
{
153-
$classes = [$typeClass, ...$typeClasses];
154-
155-
foreach ($classes as $class) {
152+
foreach ($typeClasses as $class) {
156153
if ($this->is($type, $class)) {
157154
return true;
158155
}

0 commit comments

Comments
 (0)