Skip to content

Commit b2be414

Browse files
committed
Merge branch 'develop'
* develop: specify next release fix psalm losing types of contraints when composing them
2 parents 8a1d02d + 4af5fbb commit b2be414

12 files changed

+270
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.6.1 - 2024-11-11
4+
5+
### Fixed
6+
7+
- Psalm losing the types of contraints when composing them via `and`, `or`, `map` and `asPredicate`
8+
39
## 1.6.0 - 2024-11-11
410

511
### Added

src/AndConstraint.php

+24
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,45 @@ public static function of(Constraint $a, Constraint $b): self
5656
return new self($a, $b);
5757
}
5858

59+
/**
60+
* @template T
61+
*
62+
* @param Constraint<C, T> $constraint
63+
*
64+
* @return self<A, C, T>
65+
*/
5966
public function and(Constraint $constraint): self
6067
{
6168
return new self($this, $constraint);
6269
}
6370

71+
/**
72+
* @template T
73+
*
74+
* @param Constraint<A, T> $constraint
75+
*
76+
* @return Constraint<A, C|T>
77+
*/
6478
public function or(Constraint $constraint): Constraint
6579
{
6680
return OrConstraint::of($this, $constraint);
6781
}
6882

83+
/**
84+
* @template T
85+
*
86+
* @param pure-callable(C): T $map
87+
*
88+
* @return Constraint<A, T>
89+
*/
6990
public function map(callable $map): Constraint
7091
{
7192
return Map::of($this, $map);
7293
}
7394

95+
/**
96+
* @return PredicateInterface<C>
97+
*/
7498
public function asPredicate(): PredicateInterface
7599
{
76100
return Predicate::of($this);

src/AssociativeArray.php

+24
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,45 @@ public static function of(Constraint $key, Constraint $value): self
4646
return new self($key, $value);
4747
}
4848

49+
/**
50+
* @template T
51+
*
52+
* @param Constraint<Map<K, V>, T> $constraint
53+
*
54+
* @return Constraint<mixed, T>
55+
*/
4956
public function and(Constraint $constraint): Constraint
5057
{
5158
return AndConstraint::of($this, $constraint);
5259
}
5360

61+
/**
62+
* @template T
63+
*
64+
* @param Constraint<mixed, T> $constraint
65+
*
66+
* @return Constraint<mixed, Map<K, V>|T>
67+
*/
5468
public function or(Constraint $constraint): Constraint
5569
{
5670
return OrConstraint::of($this, $constraint);
5771
}
5872

73+
/**
74+
* @template T
75+
*
76+
* @param pure-callable(Map<K, V>): T $map
77+
*
78+
* @return Constraint<mixed, T>
79+
*/
5980
public function map(callable $map): Constraint
6081
{
6182
return namespace\Map::of($this, $map);
6283
}
6384

85+
/**
86+
* @return Predicate<Map<K, V>>
87+
*/
6488
public function asPredicate(): Predicate
6589
{
6690
return namespace\Predicate::of($this);

src/Each.php

+24
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,45 @@ public static function of(Constraint $constraint): self
5656
return new self($constraint);
5757
}
5858

59+
/**
60+
* @template V
61+
*
62+
* @param Constraint<list<T>, V> $constraint
63+
*
64+
* @return Constraint<list, V>
65+
*/
5966
public function and(Constraint $constraint): Constraint
6067
{
6168
return AndConstraint::of($this, $constraint);
6269
}
6370

71+
/**
72+
* @template V
73+
*
74+
* @param Constraint<list, V> $constraint
75+
*
76+
* @return Constraint<list, list<T>|V>
77+
*/
6478
public function or(Constraint $constraint): Constraint
6579
{
6680
return OrConstraint::of($this, $constraint);
6781
}
6882

83+
/**
84+
* @template V
85+
*
86+
* @param pure-callable(list<T>): V $map
87+
*
88+
* @return Constraint<list, V>
89+
*/
6990
public function map(callable $map): Constraint
7091
{
7192
return Map::of($this, $map);
7293
}
7394

95+
/**
96+
* @return PredicateInterface<list<T>>
97+
*/
7498
public function asPredicate(): PredicateInterface
7599
{
76100
return Predicate::of($this);

src/Has.php

+24
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,45 @@ public function withFailure(callable $message): self
6363
return new self($this->key, $message);
6464
}
6565

66+
/**
67+
* @template T
68+
*
69+
* @param Constraint<mixed, T> $constraint
70+
*
71+
* @return Constraint<array, T>
72+
*/
6673
public function and(Constraint $constraint): Constraint
6774
{
6875
return AndConstraint::of($this, $constraint);
6976
}
7077

78+
/**
79+
* @template T
80+
*
81+
* @param Constraint<array, T> $constraint
82+
*
83+
* @return Constraint<array, mixed|T>
84+
*/
7185
public function or(Constraint $constraint): Constraint
7286
{
7387
return OrConstraint::of($this, $constraint);
7488
}
7589

90+
/**
91+
* @template T
92+
*
93+
* @param pure-callable(mixed): T $map
94+
*
95+
* @return Constraint<array, T>
96+
*/
7697
public function map(callable $map): Constraint
7798
{
7899
return Map::of($this, $map);
79100
}
80101

102+
/**
103+
* @return PredicateInterface<mixed>
104+
*/
81105
public function asPredicate(): PredicateInterface
82106
{
83107
return Predicate::of($this);

src/Instance.php

+24
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,45 @@ public static function of(string $class): self
5252
return new self(Predicate\Instance::of($class), $class);
5353
}
5454

55+
/**
56+
* @template V
57+
*
58+
* @param Constraint<T, V> $constraint
59+
*
60+
* @return Constraint<mixed, V>
61+
*/
5562
public function and(Constraint $constraint): Constraint
5663
{
5764
return AndConstraint::of($this, $constraint);
5865
}
5966

67+
/**
68+
* @template V
69+
*
70+
* @param Constraint<mixed, V> $constraint
71+
*
72+
* @return Constraint<mixed, T|V>
73+
*/
6074
public function or(Constraint $constraint): Constraint
6175
{
6276
return OrConstraint::of($this, $constraint);
6377
}
6478

79+
/**
80+
* @template V
81+
*
82+
* @param pure-callable(T): V $map
83+
*
84+
* @return Constraint<mixed, V>
85+
*/
6586
public function map(callable $map): Constraint
6687
{
6788
return Map::of($this, $map);
6889
}
6990

91+
/**
92+
* @return Predicate<T>
93+
*/
7094
public function asPredicate(): Predicate
7195
{
7296
return $this->assert;

src/Is.php

+24
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,45 @@ public function withFailure(string $message): self
192192
return new self($this->assert, $this->type, $message);
193193
}
194194

195+
/**
196+
* @template V
197+
*
198+
* @param Constraint<U, V> $constraint
199+
*
200+
* @return Constraint<T, V>
201+
*/
195202
public function and(Constraint $constraint): Constraint
196203
{
197204
return AndConstraint::of($this, $constraint);
198205
}
199206

207+
/**
208+
* @template V
209+
*
210+
* @param Constraint<T, V> $constraint
211+
*
212+
* @return Constraint<T, U|V>
213+
*/
200214
public function or(Constraint $constraint): Constraint
201215
{
202216
return OrConstraint::of($this, $constraint);
203217
}
204218

219+
/**
220+
* @template V
221+
*
222+
* @param pure-callable(U): V $map
223+
*
224+
* @return Constraint<T, V>
225+
*/
205226
public function map(callable $map): Constraint
206227
{
207228
return Map::of($this, $map);
208229
}
209230

231+
/**
232+
* @return PredicateInterface<U>
233+
*/
210234
public function asPredicate(): PredicateInterface
211235
{
212236
return Predicate::of($this);

src/Map.php

+24
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,45 @@ public static function of(Constraint $constraint, callable $map): self
5353
return new self($constraint, $map);
5454
}
5555

56+
/**
57+
* @template V
58+
*
59+
* @param Constraint<T, V> $constraint
60+
*
61+
* @return Constraint<I, V>
62+
*/
5663
public function and(Constraint $constraint): Constraint
5764
{
5865
return AndConstraint::of($this, $constraint);
5966
}
6067

68+
/**
69+
* @template V
70+
*
71+
* @param Constraint<I, V> $constraint
72+
*
73+
* @return Constraint<I, T|V>
74+
*/
6175
public function or(Constraint $constraint): Constraint
6276
{
6377
return OrConstraint::of($this, $constraint);
6478
}
6579

80+
/**
81+
* @template V
82+
*
83+
* @param pure-callable(T): V $map
84+
*
85+
* @return self<I, T, V>
86+
*/
6687
public function map(callable $map): self
6788
{
6889
return new self($this, $map);
6990
}
7091

92+
/**
93+
* @return PredicateInterface<T>
94+
*/
7195
public function asPredicate(): PredicateInterface
7296
{
7397
return Predicate::of($this);

src/Of.php

+24
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,45 @@ public static function callable(callable $assert): self
4646
return new self($assert);
4747
}
4848

49+
/**
50+
* @template T
51+
*
52+
* @param Constraint<B, T> $constraint
53+
*
54+
* @return Constraint<A, T>
55+
*/
4956
public function and(Constraint $constraint): Constraint
5057
{
5158
return AndConstraint::of($this, $constraint);
5259
}
5360

61+
/**
62+
* @template T
63+
*
64+
* @param Constraint<A, T> $constraint
65+
*
66+
* @return Constraint<A, B|T>
67+
*/
5468
public function or(Constraint $constraint): Constraint
5569
{
5670
return OrConstraint::of($this, $constraint);
5771
}
5872

73+
/**
74+
* @template T
75+
*
76+
* @param pure-callable(B): T $map
77+
*
78+
* @return Constraint<A, T>
79+
*/
5980
public function map(callable $map): Constraint
6081
{
6182
return Map::of($this, $map);
6283
}
6384

85+
/**
86+
* @return PredicateInterface<B>
87+
*/
6488
public function asPredicate(): PredicateInterface
6589
{
6690
return Predicate::of($this);

0 commit comments

Comments
 (0)