Skip to content

Commit 071a9d3

Browse files
authored
when a method returns $this set the return type to static (#56092)
while PHP is a little lenient here, the more accurate return type when returning `$this` is static, not self. when returning `new static()` the return type should also be `static` over `self`.
1 parent 82a86ac commit 071a9d3

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

src/Illuminate/Support/Defer/DeferredCallback.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(public $callback, public ?string $name = null, publi
2222
* @param string $name
2323
* @return $this
2424
*/
25-
public function name(string $name): self
25+
public function name(string $name): static
2626
{
2727
$this->name = $name;
2828

@@ -35,7 +35,7 @@ public function name(string $name): self
3535
* @param bool $always
3636
* @return $this
3737
*/
38-
public function always(bool $always = true): self
38+
public function always(bool $always = true): static
3939
{
4040
$this->always = $always;
4141

src/Illuminate/Support/Defer/DeferredCallbackCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function forget(string $name): void
7676
*
7777
* @return $this
7878
*/
79-
protected function forgetDuplicates(): self
79+
protected function forgetDuplicates(): static
8080
{
8181
$this->callbacks = (new Collection($this->callbacks))
8282
->reverse()

src/Illuminate/Testing/Fluent/AssertableJson.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function prop(?string $key = null)
8080
* @param \Closure $callback
8181
* @return $this
8282
*/
83-
protected function scope(string $key, Closure $callback): self
83+
protected function scope(string $key, Closure $callback): static
8484
{
8585
$props = $this->prop($key);
8686
$path = $this->dotPath($key);
@@ -100,7 +100,7 @@ protected function scope(string $key, Closure $callback): self
100100
* @param \Closure $callback
101101
* @return $this
102102
*/
103-
public function first(Closure $callback): self
103+
public function first(Closure $callback): static
104104
{
105105
$props = $this->prop();
106106

@@ -124,7 +124,7 @@ public function first(Closure $callback): self
124124
* @param \Closure $callback
125125
* @return $this
126126
*/
127-
public function each(Closure $callback): self
127+
public function each(Closure $callback): static
128128
{
129129
$props = $this->prop();
130130

@@ -150,7 +150,7 @@ public function each(Closure $callback): self
150150
* @param array $data
151151
* @return static
152152
*/
153-
public static function fromArray(array $data): self
153+
public static function fromArray(array $data): static
154154
{
155155
return new static($data);
156156
}
@@ -161,7 +161,7 @@ public static function fromArray(array $data): self
161161
* @param \Illuminate\Testing\AssertableJsonString $json
162162
* @return static
163163
*/
164-
public static function fromAssertableJsonString(AssertableJsonString $json): self
164+
public static function fromAssertableJsonString(AssertableJsonString $json): static
165165
{
166166
return static::fromArray($json->json());
167167
}

src/Illuminate/Testing/Fluent/Concerns/Debugging.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Debugging
1414
* @param string|null $prop
1515
* @return $this
1616
*/
17-
public function dump(?string $prop = null): self
17+
public function dump(?string $prop = null): static
1818
{
1919
dump($this->prop($prop));
2020

src/Illuminate/Testing/Fluent/Concerns/Has.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait Has
1515
* @param int|null $length
1616
* @return $this
1717
*/
18-
public function count($key, ?int $length = null): self
18+
public function count($key, ?int $length = null): static
1919
{
2020
if (is_null($length)) {
2121
$path = $this->dotPath();
@@ -47,7 +47,7 @@ public function count($key, ?int $length = null): self
4747
* @param int|string $max
4848
* @return $this
4949
*/
50-
public function countBetween(int|string $min, int|string $max): self
50+
public function countBetween(int|string $min, int|string $max): static
5151
{
5252
$path = $this->dotPath();
5353

@@ -80,7 +80,7 @@ public function countBetween(int|string $min, int|string $max): self
8080
* @param \Closure|null $callback
8181
* @return $this
8282
*/
83-
public function has($key, $length = null, ?Closure $callback = null): self
83+
public function has($key, $length = null, ?Closure $callback = null): static
8484
{
8585
$prop = $this->prop();
8686

@@ -125,7 +125,7 @@ public function has($key, $length = null, ?Closure $callback = null): self
125125
* @param array|string $key
126126
* @return $this
127127
*/
128-
public function hasAll($key): self
128+
public function hasAll($key): static
129129
{
130130
$keys = is_array($key) ? $key : func_get_args();
131131

@@ -146,7 +146,7 @@ public function hasAll($key): self
146146
* @param array|string $key
147147
* @return $this
148148
*/
149-
public function hasAny($key): self
149+
public function hasAny($key): static
150150
{
151151
$keys = is_array($key) ? $key : func_get_args();
152152

@@ -168,7 +168,7 @@ public function hasAny($key): self
168168
* @param array|string $key
169169
* @return $this
170170
*/
171-
public function missingAll($key): self
171+
public function missingAll($key): static
172172
{
173173
$keys = is_array($key) ? $key : func_get_args();
174174

@@ -185,7 +185,7 @@ public function missingAll($key): self
185185
* @param string $key
186186
* @return $this
187187
*/
188-
public function missing(string $key): self
188+
public function missing(string $key): static
189189
{
190190
PHPUnit::assertNotTrue(
191191
Arr::has($this->prop(), $key),

src/Illuminate/Testing/Fluent/Concerns/Interaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function interacted(): void
5050
*
5151
* @return $this
5252
*/
53-
public function etc(): self
53+
public function etc(): static
5454
{
5555
$this->interacted = array_keys($this->prop());
5656

src/Illuminate/Testing/Fluent/Concerns/Matching.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Matching
1818
* @param mixed|\Closure $expected
1919
* @return $this
2020
*/
21-
public function where(string $key, $expected): self
21+
public function where(string $key, $expected): static
2222
{
2323
$this->has($key);
2424

@@ -56,7 +56,7 @@ public function where(string $key, $expected): self
5656
* @param mixed|\Closure $expected
5757
* @return $this
5858
*/
59-
public function whereNot(string $key, $expected): self
59+
public function whereNot(string $key, $expected): static
6060
{
6161
$this->has($key);
6262

@@ -98,7 +98,7 @@ public function whereNot(string $key, $expected): self
9898
* @param string $key
9999
* @return $this
100100
*/
101-
public function whereNull(string $key): self
101+
public function whereNull(string $key): static
102102
{
103103
$this->has($key);
104104

@@ -121,7 +121,7 @@ public function whereNull(string $key): self
121121
* @param string $key
122122
* @return $this
123123
*/
124-
public function whereNotNull(string $key): self
124+
public function whereNotNull(string $key): static
125125
{
126126
$this->has($key);
127127

@@ -144,7 +144,7 @@ public function whereNotNull(string $key): self
144144
* @param array $bindings
145145
* @return $this
146146
*/
147-
public function whereAll(array $bindings): self
147+
public function whereAll(array $bindings): static
148148
{
149149
foreach ($bindings as $key => $value) {
150150
$this->where($key, $value);
@@ -160,7 +160,7 @@ public function whereAll(array $bindings): self
160160
* @param string|array $expected
161161
* @return $this
162162
*/
163-
public function whereType(string $key, $expected): self
163+
public function whereType(string $key, $expected): static
164164
{
165165
$this->has($key);
166166

@@ -185,7 +185,7 @@ public function whereType(string $key, $expected): self
185185
* @param array $bindings
186186
* @return $this
187187
*/
188-
public function whereAllType(array $bindings): self
188+
public function whereAllType(array $bindings): static
189189
{
190190
foreach ($bindings as $key => $value) {
191191
$this->whereType($key, $value);

src/Illuminate/Testing/TestResponseAssert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private function __construct(protected TestResponse $response)
2525
/**
2626
* Create a new TestResponse assertion helper.
2727
*/
28-
public static function withResponse(TestResponse $response): self
28+
public static function withResponse(TestResponse $response): static
2929
{
3030
return new static($response);
3131
}

0 commit comments

Comments
 (0)