2020-01-03 05:50:19 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use const DIRECTORY_SEPARATOR;
|
|
|
|
use Psalm\Config;
|
|
|
|
use Psalm\Context;
|
|
|
|
|
|
|
|
class MixinAnnotationTest extends TestCase
|
|
|
|
{
|
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
|
|
|
*/
|
|
|
|
public function providerValidCodeParse()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'validSimpleAnnotations' => [
|
|
|
|
'<?php
|
|
|
|
class ParentClass {
|
|
|
|
public function __call(string $name, array $args) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Provider {
|
|
|
|
public function getString() : string {
|
|
|
|
return "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setInteger(int $i) : void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @mixin Provider */
|
|
|
|
class Child extends ParentClass {}
|
|
|
|
|
|
|
|
$child = new Child();
|
|
|
|
|
|
|
|
$a = $child->getString();
|
|
|
|
$child->setInteger(4);',
|
|
|
|
'assertions' => [
|
|
|
|
'$a' => 'string',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'anotherSimpleExample' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @mixin B
|
|
|
|
*/
|
|
|
|
class A {
|
|
|
|
/** @var B */
|
|
|
|
private $b;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->b = new B();
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:04:21 +01:00
|
|
|
public function c(string $s) : void {}
|
|
|
|
|
2020-01-03 05:50:19 +01:00
|
|
|
/**
|
|
|
|
* @param array<mixed> $arguments
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __call(string $method, array $arguments)
|
|
|
|
{
|
|
|
|
return $this->b->$method(...$arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B {
|
|
|
|
public function b(): void {
|
|
|
|
echo "b";
|
|
|
|
}
|
2020-01-07 00:04:21 +01:00
|
|
|
|
|
|
|
public function c(int $s) : void {}
|
2020-01-03 05:50:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$a = new A();
|
|
|
|
$a->b();'
|
|
|
|
],
|
2020-03-19 02:38:53 +01:00
|
|
|
'allowConstructor' => [
|
|
|
|
'<?php
|
|
|
|
abstract class AParent {
|
|
|
|
protected int $i;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->i = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class M {
|
|
|
|
public function __construct() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin M
|
|
|
|
*/
|
|
|
|
class A extends AParent {}'
|
|
|
|
],
|
2020-04-26 22:49:52 +02:00
|
|
|
'implicitMixin' => [
|
|
|
|
'<?php
|
|
|
|
function foo(string $dir) : void {
|
|
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
|
|
new \RecursiveDirectoryIterator($dir)
|
|
|
|
);
|
|
|
|
|
|
|
|
while ($iterator->valid()) {
|
|
|
|
if (!$iterator->isDot() && $iterator->isLink()) {}
|
|
|
|
|
|
|
|
$iterator->next();
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
],
|
2020-01-03 05:50:19 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|