I have classes with static methods that I need to change to instance methods for unit testing. However I can not change the code that calls them statically. So I'm trying to implement a facade (similar to what Laravel does) so that I can call the functions both statically and dynamically. My code itself is working, but PHPStorm is complaining about the static calls. Here is my facade class with a test child class and phpunit test:
abstract class Facade
{
/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
$instance = new static;
return call_user_func_array([$instance, $method], $parameters);
}
}
class Foo extends Facade
{
/**
* @param string $param1
* @return string
*/
public function TestMethod1($param1)
{
return 'Test: '.$param1;
}
}
class FooTest extends \PHPUnit_Framework_TestCase
{
public function testFacade()
{
$param1 = 'ok';
$result = Foo::TestMethod1($param1);
$this->assertEquals('Test: '.$param1, $result);
}
}
I have tried using phpdoc @method on Foo and @static on the TestMethod1 method, but neither seems to work. How can I get PHPStorm to stop complaining about the static calls? Is there a way to handle this other than turning off the inspection?