PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.30.0
Independent Analytics – WordPress Analytics Plugin v1.30.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / nesbot / carbon / src / Carbon / PHPStan / AbstractMacro.php
independent-analytics / vendor / nesbot / carbon / src / Carbon / PHPStan Last commit date
AbstractMacro.php 3 years ago Macro.php 3 years ago MacroExtension.php 3 years ago MacroScanner.php 3 years ago
AbstractMacro.php
240 lines
1 <?php
2
3 declare (strict_types=1);
4 /**
5 * This file is part of the Carbon package.
6 *
7 * (c) Brian Nesbitt <brian@nesbot.com>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12 namespace IAWP_SCOPED\Carbon\PHPStan;
13
14 use Closure;
15 use InvalidArgumentException;
16 use IAWP_SCOPED\PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter as AdapterReflectionParameter;
17 use IAWP_SCOPED\PHPStan\BetterReflection\Reflection\Adapter\ReflectionType as AdapterReflectionType;
18 use IAWP_SCOPED\PHPStan\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
19 use IAWP_SCOPED\PHPStan\BetterReflection\Reflection\ReflectionFunction as BetterReflectionFunction;
20 use IAWP_SCOPED\PHPStan\BetterReflection\Reflection\ReflectionParameter as BetterReflectionParameter;
21 use IAWP_SCOPED\PHPStan\Reflection\Php\BuiltinMethodReflection;
22 use IAWP_SCOPED\PHPStan\TrinaryLogic;
23 use ReflectionClass;
24 use ReflectionFunction;
25 use ReflectionMethod;
26 use ReflectionParameter;
27 use ReflectionType;
28 use stdClass;
29 use Throwable;
30 abstract class AbstractMacro implements BuiltinMethodReflection
31 {
32 /**
33 * The reflection function/method.
34 *
35 * @var ReflectionFunction|ReflectionMethod
36 */
37 protected $reflectionFunction;
38 /**
39 * The class name.
40 *
41 * @var class-string
42 */
43 private $className;
44 /**
45 * The method name.
46 *
47 * @var string
48 */
49 private $methodName;
50 /**
51 * The parameters.
52 *
53 * @var ReflectionParameter[]
54 */
55 private $parameters;
56 /**
57 * The is static.
58 *
59 * @var bool
60 */
61 private $static = \false;
62 /**
63 * Macro constructor.
64 *
65 * @param string $className
66 * @phpstan-param class-string $className
67 *
68 * @param string $methodName
69 * @param callable $macro
70 */
71 public function __construct(string $className, string $methodName, $macro)
72 {
73 $this->className = $className;
74 $this->methodName = $methodName;
75 $rawReflectionFunction = \is_array($macro) ? new ReflectionMethod($macro[0], $macro[1]) : new ReflectionFunction($macro);
76 $this->reflectionFunction = self::hasModernParser() ? $this->getReflectionFunction($macro) : $rawReflectionFunction;
77 // @codeCoverageIgnore
78 $this->parameters = \array_map(function ($parameter) {
79 if ($parameter instanceof BetterReflectionParameter) {
80 return new AdapterReflectionParameter($parameter);
81 }
82 return $parameter;
83 // @codeCoverageIgnore
84 }, $this->reflectionFunction->getParameters());
85 if ($rawReflectionFunction->isClosure()) {
86 try {
87 $closure = $rawReflectionFunction->getClosure();
88 $boundClosure = Closure::bind($closure, new stdClass());
89 $this->static = !$boundClosure || (new ReflectionFunction($boundClosure))->getClosureThis() === null;
90 } catch (Throwable $e) {
91 $this->static = \true;
92 }
93 }
94 }
95 private function getReflectionFunction($spec)
96 {
97 if (\is_array($spec) && \count($spec) === 2 && \is_string($spec[1])) {
98 \assert($spec[1] !== '');
99 if (\is_object($spec[0])) {
100 return BetterReflectionClass::createFromInstance($spec[0])->getMethod($spec[1]);
101 }
102 return BetterReflectionClass::createFromName($spec[0])->getMethod($spec[1]);
103 }
104 if (\is_string($spec)) {
105 return BetterReflectionFunction::createFromName($spec);
106 }
107 if ($spec instanceof Closure) {
108 return BetterReflectionFunction::createFromClosure($spec);
109 }
110 throw new InvalidArgumentException('Could not create reflection from the spec given');
111 // @codeCoverageIgnore
112 }
113 /**
114 * {@inheritdoc}
115 */
116 public function getDeclaringClass() : ReflectionClass
117 {
118 return new ReflectionClass($this->className);
119 }
120 /**
121 * {@inheritdoc}
122 */
123 public function isPrivate() : bool
124 {
125 return \false;
126 }
127 /**
128 * {@inheritdoc}
129 */
130 public function isPublic() : bool
131 {
132 return \true;
133 }
134 /**
135 * {@inheritdoc}
136 */
137 public function isFinal() : bool
138 {
139 return \false;
140 }
141 /**
142 * {@inheritdoc}
143 */
144 public function isInternal() : bool
145 {
146 return \false;
147 }
148 /**
149 * {@inheritdoc}
150 */
151 public function isAbstract() : bool
152 {
153 return \false;
154 }
155 /**
156 * {@inheritdoc}
157 */
158 public function isStatic() : bool
159 {
160 return $this->static;
161 }
162 /**
163 * {@inheritdoc}
164 */
165 public function getDocComment() : ?string
166 {
167 return $this->reflectionFunction->getDocComment() ?: null;
168 }
169 /**
170 * {@inheritdoc}
171 */
172 public function getName() : string
173 {
174 return $this->methodName;
175 }
176 /**
177 * {@inheritdoc}
178 */
179 public function getParameters() : array
180 {
181 return $this->parameters;
182 }
183 /**
184 * {@inheritdoc}
185 */
186 public function getReturnType() : ?ReflectionType
187 {
188 $type = $this->reflectionFunction->getReturnType();
189 if ($type instanceof ReflectionType) {
190 return $type;
191 // @codeCoverageIgnore
192 }
193 return self::adaptType($type);
194 }
195 /**
196 * {@inheritdoc}
197 */
198 public function isDeprecated() : TrinaryLogic
199 {
200 return TrinaryLogic::createFromBoolean($this->reflectionFunction->isDeprecated() || \preg_match('/@deprecated/i', $this->getDocComment() ?: ''));
201 }
202 /**
203 * {@inheritdoc}
204 */
205 public function isVariadic() : bool
206 {
207 return $this->reflectionFunction->isVariadic();
208 }
209 /**
210 * {@inheritdoc}
211 */
212 public function getPrototype() : BuiltinMethodReflection
213 {
214 return $this;
215 }
216 public function getTentativeReturnType() : ?ReflectionType
217 {
218 return null;
219 }
220 public function returnsByReference() : TrinaryLogic
221 {
222 return TrinaryLogic::createNo();
223 }
224 private static function adaptType($type)
225 {
226 $method = \method_exists(AdapterReflectionType::class, 'fromTypeOrNull') ? 'fromTypeOrNull' : 'fromReturnTypeOrNull';
227 // @codeCoverageIgnore
228 return AdapterReflectionType::$method($type);
229 }
230 private static function hasModernParser() : bool
231 {
232 static $modernParser = null;
233 if ($modernParser !== null) {
234 return $modernParser;
235 }
236 $modernParser = \method_exists(AdapterReflectionType::class, 'fromTypeOrNull');
237 return $modernParser;
238 }
239 }
240