forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-12490.php
More file actions
89 lines (76 loc) · 1.58 KB
/
bug-12490.php
File metadata and controls
89 lines (76 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php declare(strict_types = 1);
namespace Bug12490;
/**
* @template TGet
* @template TSet
*/
class Attribute
{
/** @var (callable(mixed, array<string, mixed>): TGet)|null */
public $get;
/** @var (callable(TSet, array<string, mixed>): mixed)|null*/
public $set;
/**
* @param (callable(mixed, array<string, mixed>): TGet)|null $get
* @param (callable(TSet, array<string, mixed>): mixed)|null $set
*/
public function __construct(?callable $get = null, ?callable $set = null)
{
$this->get = $get;
$this->set = $set;
}
/**
* @template T
* @param callable(mixed, array<string, mixed>): T $get
* @return Attribute<T, never>
*/
public static function get(callable $get): self
{
return new self($get);
}
}
class Foo
{
public ?int $id = null;
public ?string $surveyable_type = null;
/**
* @return Attribute<null|string, never>
*/
protected function surveyedLink(): Attribute
{
return Attribute::get(fn () => $this->surveyable_type);
}
/** @return Attribute<null|float, never> */
protected function packageWeightCalculated(): Attribute
{
return Attribute::get(fn () => $this->id === null ? null : round(50 * .15, 2));
}
/** @return Attribute<?int, never> */
protected function durationMs(): Attribute
{
return Attribute::get(fn () => $this->id);
}
}
/**
* @template T
*/
class Container
{
/** @var T */
public $value;
/**
* @param T $value
*/
public function __construct($value)
{
$this->value = $value;
}
}
class Bar
{
/** @return Container<string> */
public function test(?string $val): Container
{
return new Container($val);
}
}