Should assertType always be inside a function or can it be on the top level? #10889
-
Hello! Please see larastan/larastan#1876 (comment) for context. Essentially should For example, which of the following (if either) is more correct / performant? <?php
namespace Test;
use function PHPStan\Testing\assertType;
/** @var ?string $v */
assertType('?string', $v); or <?php
namespace Test;
use function PHPStan\Testing\assertType;
function (?string $v) {
assertType('?string', $v);
}; If there is a difference, should the docs be updated to reflect this? I couldn't find anything in the documentation. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I don't think it's because of performance. There might have been some performance-related issue in the past that might have manifested in this case like sebastianbergmann/phpunit#5524 or sebastianbergmann/phpunit#5758 - essentially PHPUnit taking a long time because data returned by data provider contained huge objects. But that should be solved and shouldn't influence how tests look like. But I see two different reasons to put
|
Beta Was this translation helpful? Give feedback.
I don't think it's because of performance. There might have been some performance-related issue in the past that might have manifested in this case like sebastianbergmann/phpunit#5524 or sebastianbergmann/phpunit#5758 - essentially PHPUnit taking a long time because data returned by data provider contained huge objects. But that should be solved and shouldn't influence how tests look like.
But I see two different reasons to put
assertType
and similar in a non-root scope: