Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Aug 15, 2024
1 parent 93a4de3 commit 4658af4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/linter/quickfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func (g *QuickFixGenerator) NullableType(param ir.Node) quickfix.TextEdit {
EndPos: v.Position.EndPos,
}
value = v.Value
default:
panic("unexpected type")
}

return quickfix.TextEdit{
Expand Down
2 changes: 1 addition & 1 deletion src/linter/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func addBuiltinCheckers(reg *CheckersRegistry) {
Name: "nullableType",
Default: true,
Quickfix: true,
Comment: "Report not nullable string can be null.",
Comment: "Report not nullable param can be null.",
Before: `function f(string $str = null);`,
After: `function f(?string $str = null);`,
},
Expand Down
27 changes: 27 additions & 0 deletions src/tests/checkers/nullable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,30 @@ class MyClass2 {
}
test.RunAndMatch()
}

func TestNullableMultipleArgs(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
function multipleArgsExample(?string $a, ?int $b = null, ?bool $c = null) {
return 0;
}
`)

test.RunAndMatch()
}

func TestNotNullableMultipleArgs(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
function multipleArgsExample(string $a, int $b = null, bool $c = null) {
return 0;
}
`)

test.Expect = []string{
"parameter with null default value should be explicitly nullable",
"parameter with null default value should be explicitly nullable",
}

test.RunAndMatch()
}
4 changes: 2 additions & 2 deletions src/tests/golden/testdata/quickfix/nullableTypes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function f(string $filed = null) {
function notNullableString(string $filed = null) {
return 1;
}

Expand All @@ -19,4 +19,4 @@ public function myMethod(MyClass1 $a = null) {

function nullableArray(array $a = null) {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

function f(?string $filed = null) {
function notNullableString(?string $filed = null) {
return 1;
}

Expand All @@ -19,4 +19,4 @@ class MyClass2 {

function nullableArray(?array $a = null) {
return 0;
}
}

0 comments on commit 4658af4

Please sign in to comment.