Skip to content

Commit

Permalink
test: closure and callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Dec 5, 2024
1 parent 27f27dd commit a17ae19
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/tests/checkers/not_explicit_nullable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,34 @@ $closure_fn = fn(?string $a, int $b = null, ?bool $c = null) => null;

test.RunAndMatch()
}

func TestClassWithFunCallback(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
class SomeClass {
public function willReturnCallback($callback): self
{
return $this;
}
private function funWithCallback(array $participation_statuses_data) {
$this
->willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, Date $finished_at = null) use ($participation_statuses_data) {
return;
});
}
}
`)

test.Expect = []string{
"parameter with null default value should be explicitly nullable",
"Missing PHPDoc for \\SomeClass::willReturnCallback public method",
"Specify the type for the parameter $participation_statuses_data",
"Expression evaluated but not used",
"Variable $participation_statuses_data is unused",
"Class or interface named \\Date does not exist",
}

test.RunAndMatch()
}
15 changes: 15 additions & 0 deletions src/tests/golden/testdata/quickfix/notExplicitNullableParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ function multipleArgsExample(string $a, int $b = null, bool $c = null) {}
function nullableOrString(null|string $a = null) {}

function mixedParam(mixed $a = null) {}

class SomeClass {

public function willReturnCallback($callback): self
{
return $this;
}

private function funWithCallback(array $participation_statuses_data) {
$this
->willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, Date $finished_at = null) use ($participation_statuses_data) {
return;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ function multipleArgsExample(string $a, ?int $b = null, ?bool $c = null) {}
function nullableOrString(null|string $a = null) {}

function mixedParam(mixed $a = null) {}

class SomeClass {

public function willReturnCallback($callback): self
{
return $this;
}

private function funWithCallback(array $participation_statuses_data) {
$this
->willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, ?Date $finished_at = null) use ($participation_statuses_data) {
return;
});
}
}

0 comments on commit a17ae19

Please sign in to comment.