1+ <?php // Auto-generated from vscode-languageserver-protocol (typescript)
2+
3+ namespace Phpactor \LanguageServerProtocol ;
4+
5+ use DTL \Invoke \Invoke ;
6+ use Exception ;
7+ use RuntimeException ;
8+
9+ /**
10+ * Mixins (implemented TS interfaces): WorkDoneProgressParams
11+ */
12+ class InlineValueParams
13+ {
14+ /**
15+ * The text document.
16+ *
17+ * @var TextDocumentIdentifier
18+ */
19+ public $ textDocument ;
20+
21+ /**
22+ * The document range for which inline values should be computed.
23+ *
24+ * @var Range
25+ */
26+ public $ range ;
27+
28+ /**
29+ * Additional information about the context in which inline values were
30+ * requested.
31+ *
32+ * @var array{frameId:int,stoppedLocation:Range}
33+ */
34+ public $ context ;
35+
36+ /**
37+ * An optional token that a server can use to report work done progress.
38+ *
39+ * @var int|string|null
40+ */
41+ public $ workDoneToken ;
42+
43+ /**
44+ * @param TextDocumentIdentifier $textDocument
45+ * @param Range $range
46+ * @param array{frameId:int,stoppedLocation:Range} $context
47+ * @param int|string|null $workDoneToken
48+ */
49+ public function __construct (TextDocumentIdentifier $ textDocument , Range $ range , array $ context , $ workDoneToken = null )
50+ {
51+ $ this ->textDocument = $ textDocument ;
52+ $ this ->range = $ range ;
53+ $ this ->context = $ context ;
54+ $ this ->workDoneToken = $ workDoneToken ;
55+ }
56+
57+ /**
58+ * @param array<string,mixed> $array
59+ * @return self
60+ */
61+ public static function fromArray (array $ array , bool $ allowUnknownKeys = false )
62+ {
63+ $ map = [
64+ 'textDocument ' => ['names ' => [TextDocumentIdentifier::class], 'iterable ' => false ],
65+ 'range ' => ['names ' => [Range::class], 'iterable ' => false ],
66+ 'context ' => ['names ' => [], 'iterable ' => false ],
67+ 'workDoneToken ' => ['names ' => [], 'iterable ' => false ],
68+ ];
69+
70+ foreach ($ array as $ key => &$ value ) {
71+ if (!isset ($ map [$ key ])) {
72+ if ($ allowUnknownKeys ) {
73+ unset($ array [$ key ]);
74+ continue ;
75+ }
76+
77+ throw new RuntimeException (sprintf (
78+ 'Parameter "%s" on class "%s" not known, known parameters: "%s" ' ,
79+ $ key ,
80+ self ::class,
81+ implode ('", " ' , array_keys ($ map ))
82+ ));
83+ }
84+
85+ // from here we only care about arrays that can be transformed into
86+ // objects
87+ if (!is_array ($ value )) {
88+ continue ;
89+ }
90+
91+ if (empty ($ map [$ key ]['names ' ])) {
92+ continue ;
93+ }
94+
95+ if ($ map [$ key ]['iterable ' ]) {
96+ $ value = array_map (function ($ object ) use ($ map , $ key , $ allowUnknownKeys ) {
97+ if (!is_array ($ object )) {
98+ return $ object ;
99+ }
100+
101+ return self ::invokeFromNames ($ map [$ key ]['names ' ], $ object , $ allowUnknownKeys ) ?: $ object ;
102+ }, $ value );
103+ continue ;
104+ }
105+
106+ $ names = $ map [$ key ]['names ' ];
107+ $ value = self ::invokeFromNames ($ names , $ value , $ allowUnknownKeys ) ?: $ value ;
108+ }
109+
110+ return Invoke::new (self ::class, $ array );
111+ }
112+
113+ /**
114+ * @param array<string> $classNames
115+ * @param array<string,mixed> $object
116+ */
117+ private static function invokeFromNames (array $ classNames , array $ object , bool $ allowUnknownKeys ): ?object
118+ {
119+ $ lastException = null ;
120+ foreach ($ classNames as $ className ) {
121+ try {
122+ // @phpstan-ignore-next-line
123+ return call_user_func_array ($ className . '::fromArray ' , [$ object , $ allowUnknownKeys ]);
124+ } catch (Exception $ exception ) {
125+ $ lastException = $ exception ;
126+ continue ;
127+ }
128+ }
129+
130+ throw $ lastException ;
131+ }
132+
133+ }
0 commit comments