1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
if (! \function_exists('\\sdl')) { |
11
|
|
|
/** |
12
|
|
|
* @param string $fileOrSources |
13
|
|
|
* @param bool $filename |
14
|
|
|
* @return \Railt\Reflection\Contracts\Document |
15
|
|
|
* @throws \Railt\Io\Exception\ExternalFileException |
16
|
|
|
* @throws \Railt\Io\Exception\NotReadableException |
17
|
|
|
* @throws \Railt\Reflection\Exception\TypeConflictException |
18
|
|
|
*/ |
19
|
|
|
function sdl(string $fileOrSources, bool $filename = false): \Railt\Reflection\Contracts\Document |
20
|
|
|
{ |
21
|
|
|
$file = $filename ? \Railt\Io\File::fromPathname($fileOrSources) : \Railt\Io\File::fromSources($fileOrSources); |
22
|
|
|
|
23
|
|
|
return (new \Railt\SDL\Compiler())->compile($file); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
if (! function_exists('trait_uses_recursive')) { |
29
|
|
|
/** |
30
|
|
|
* Returns all traits used by a trait and its traits. |
31
|
|
|
* |
32
|
|
|
* @param string $trait |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
function trait_uses_recursive($trait): array |
36
|
|
|
{ |
37
|
|
|
$traits = \class_uses($trait); |
38
|
|
|
|
39
|
|
|
foreach ($traits as $trait) { |
40
|
|
|
$traits += \trait_uses_recursive($trait); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $traits; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
if (! function_exists('class_uses_recursive')) { |
49
|
|
|
/** |
50
|
|
|
* Returns all traits used by a class, its parent classes and trait of their traits. |
51
|
|
|
* |
52
|
|
|
* @param object|string $class |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
function class_uses_recursive($class): array |
56
|
|
|
{ |
57
|
|
|
if (\is_object($class)) { |
58
|
|
|
$class = \get_class($class); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$results = []; |
62
|
|
|
|
63
|
|
|
foreach (\array_reverse(\class_parents($class)) + [$class => $class] as $class) { |
64
|
|
|
$results += \trait_uses_recursive($class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return \array_unique($results); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
if (! function_exists('class_basename')) { |
73
|
|
|
/** |
74
|
|
|
* Get the class "basename" of the given object / class. |
75
|
|
|
* |
76
|
|
|
* @param string|object $class |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
function class_basename($class): string |
80
|
|
|
{ |
81
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
82
|
|
|
|
83
|
|
|
return basename(\str_replace('\\', '/', $class)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.