mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Merge pull request #901 from loilo/fix-default-param-values
Prevent generation of invalid code for certain parameter default values
This commit is contained in:
+1
-1
@@ -329,7 +329,7 @@ class Method
|
||||
} elseif (is_resource($default)) {
|
||||
//skip to not fail
|
||||
} else {
|
||||
$default = "'" . trim($default) . "'";
|
||||
$default = var_export($default, true);
|
||||
}
|
||||
$paramStr .= " = $default";
|
||||
}
|
||||
|
||||
@@ -47,6 +47,21 @@ class ExampleTest extends TestCase
|
||||
$this->assertEquals(['$last', '$first = \'Barry\'', '...$middle'], $method->getParamsWithDefault(false));
|
||||
$this->assertEquals(true, $method->shouldReturn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test special characters in methods default values
|
||||
*/
|
||||
public function testDefaultSpecialChars()
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass(ExampleClass::class);
|
||||
$reflectionMethod = $reflectionClass->getMethod('setSpecialChars');
|
||||
|
||||
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
||||
$this->assertEquals('$chars', $method->getParams(true));
|
||||
$this->assertEquals(['$chars'], $method->getParams(false));
|
||||
$this->assertEquals('$chars = \'$\\\'\\\\\'', $method->getParamsWithDefault(true));
|
||||
$this->assertEquals(['$chars = \'$\\\'\\\\\''], $method->getParamsWithDefault(false));
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleClass
|
||||
@@ -60,4 +75,9 @@ class ExampleClass
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function setSpecialChars($chars = "\$'\\")
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user