Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspection: phpdoc type to typehint #1221

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new tests for typeHints
  • Loading branch information
Hidanio committed Sep 5, 2024
commit ac2b32a92b068cd3aa90ff71b3e3ff354946bf90
63 changes: 63 additions & 0 deletions src/tests/checkers/typehint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,66 @@ function f2() {
}
linttest.RunFilterMatch(test, "typeHint")
}

func TestTypeHintToFunParam(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
declare(strict_types = 1);
/* @param $str string */
function test($str){}
`)
test.Expect = []string{
`Non-canonical order of variable and type`,
`Type for $str can be wrote explicitly from typeHint`,
}
test.RunAndMatch()
}

func TestTypeHintClassAndFunc(t *testing.T) {
test := linttest.NewSuite(t)
test.AddFile(`<?php
declare(strict_types = 1);

class SimpleClass
{

/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;


/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private $foo2 ;

/**
* @param $str string
* @param $str2 string
*/
function test($str, string $str){
}
}

/**
* @param $str string
*/
function test2($str){
}
`)
test.Expect = []string{
`Specify the access modifier for \SimpleClass::test method explicitly`,
`Non-canonical order of variable and type `,
`@param for non-existing argument $str2`,
`Non-canonical order of variable and type`,
`Type for $foo2 can be wrote explicitly from typeHint`,
`Type for $str can be wrote explicitly from typeHint`,
`Type for $str2 can be wrote explicitly from typeHint`,
`Non-canonical order of variable and type`,
`Type for $str can be wrote explicitly from typeHint`,
}
test.RunAndMatch()
}
32 changes: 32 additions & 0 deletions src/tests/golden/testdata/quickfix/phpTypeHintApply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types = 1);

class SimpleClass
{

/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;


/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo2 ;

/**
* @param $str string
* @param $str2 string
*/
function test($str, $str2){
}
}

/**
* @param $str string
*/
function test2($str){
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types = 1);

class SimpleClass
{

/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo;


/**
* This is what the variable does. The var line contains the type stored in this variable.
* @var string
*/
private string $foo2 ;

/**
* @param $str string
* @param $str2 string
*/
function test(string $str, string $str){
}
}

/**
* @param $str string
*/
function test2(string $str){
}