PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.1
Independent Analytics – WordPress Analytics Plugin v2.15.1
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 2 years ago Macro.php 2 years ago MacroExtension.php 2 years ago MacroScanner.php 2 years ago
AbstractMacro.php
239 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 IAWPSCOPED\Carbon\PHPStan;
13
14 use Closure;
15 use InvalidArgumentException;
16 use IAWPSCOPED\PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter as AdapterReflectionParameter;
17 use IAWPSCOPED\PHPStan\BetterReflection\Reflection\Adapter\ReflectionType as AdapterReflectionType;
18 use IAWPSCOPED\PHPStan\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
19 use IAWPSCOPED\PHPStan\BetterReflection\Reflection\ReflectionFunction as BetterReflectionFunction;
20 use IAWPSCOPED\PHPStan\BetterReflection\Reflection\ReflectionParameter as BetterReflectionParameter;
21 use IAWPSCOPED\PHPStan\Reflection\Php\BuiltinMethodReflection;
22 use IAWPSCOPED\PHPStan\TrinaryLogic;
23 use ReflectionClass;
24 use ReflectionFunction;
25 use ReflectionMethod;
26 use ReflectionParameter;
27 use ReflectionType;
28 use stdClass;
29 use Throwable;
30 /** @internal */
31 abstract class AbstractMacro implements BuiltinMethodReflection
32 {
33 /**
34 * The reflection function/method.
35 *
36 * @var ReflectionFunction|ReflectionMethod
37 */
38 protected $reflectionFunction;
39 /**
40 * The class name.
41 *
42 * @var class-string
43 */
44 private $className;
45 /**
46 * The method name.
47 *
48 * @var string
49 */
50 private $methodName;
51 /**
52 * The parameters.
53 *
54 * @var ReflectionParameter[]
55 */
56 private $parameters;
57 /**
58 * The is static.
59 *
60 * @var bool
61 */
62 private $static = \false;
63 /**
64 * Macro constructor.
65 *
66 * @param class-string $className
67 * @param string $methodName
68 * @param callable $macro
69 */
70 public function __construct(string $className, string $methodName, $macro)
71 {
72 $this->className = $className;
73 $this->methodName = $methodName;
74 $rawReflectionFunction = \is_array($macro) ? new ReflectionMethod($macro[0], $macro[1]) : new ReflectionFunction($macro);
75 $this->reflectionFunction = self::hasModernParser() ? $this->getReflectionFunction($macro) : $rawReflectionFunction;
76 // @codeCoverageIgnore
77 $this->parameters = \array_map(function ($parameter) {
78 if ($parameter instanceof BetterReflectionParameter) {
79 return new AdapterReflectionParameter($parameter);
80 }
81 return $parameter;
82 // @codeCoverageIgnore
83 }, $this->reflectionFunction->getParameters());
84 if ($rawReflectionFunction->isClosure()) {
85 try {
86 $closure = $rawReflectionFunction->getClosure();
87 $boundClosure = Closure::bind($closure, new stdClass());
88 $this->static = !$boundClosure || (new ReflectionFunction($boundClosure))->getClosureThis() === null;
89 } catch (Throwable $e) {
90 $this->static = \true;
91 }
92 }
93 }
94 private function getReflectionFunction($spec)
95 {
96 if (\is_array($spec) && \count($spec) === 2 && \is_string($spec[1])) {
97 \assert($spec[1] !== '');
98 if (\is_object($spec[0])) {
99 return BetterReflectionClass::createFromInstance($spec[0])->getMethod($spec[1]);
100 }
101 return BetterReflectionClass::createFromName($spec[0])->getMethod($spec[1]);
102 }
103 if (\is_string($spec)) {
104 return BetterReflectionFunction::createFromName($spec);
105 }
106 if ($spec instanceof Closure) {
107 return BetterReflectionFunction::createFromClosure($spec);
108 }
109 throw new InvalidArgumentException('Could not create reflection from the spec given');
110 // @codeCoverageIgnore
111 }
112 /**
113 * {@inheritdoc}
114 */
115 public function getDeclaringClass() : ReflectionClass
116 {
117 return new ReflectionClass($this->className);
118 }
119 /**
120 * {@inheritdoc}
121 */
122 public function isPrivate() : bool
123 {
124 return \false;
125 }
126 /**
127 * {@inheritdoc}
128 */
129 public function isPublic() : bool
130 {
131 return \true;
132 }
133 /**
134 * {@inheritdoc}
135 */
136 public function isFinal() : bool
137 {
138 return \false;
139 }
140 /**
141 * {@inheritdoc}
142 */
143 public function isInternal() : bool
144 {
145 return \false;
146 }
147 /**
148 * {@inheritdoc}
149 */
150 public function isAbstract() : bool
151 {
152 return \false;
153 }
154 /**
155 * {@inheritdoc}
156 */
157 public function isStatic() : bool
158 {
159 return $this->static;
160 }
161 /**
162 * {@inheritdoc}
163 */
164 public function getDocComment() : ?string
165 {
166 return $this->reflectionFunction->getDocComment() ?: null;
167 }
168 /**
169 * {@inheritdoc}
170 */
171 public function getName() : string
172 {
173 return $this->methodName;
174 }
175 /**
176 * {@inheritdoc}
177 */
178 public function getParameters() : array
179 {
180 return $this->parameters;
181 }
182 /**
183 * {@inheritdoc}
184 */
185 public function getReturnType() : ?ReflectionType
186 {
187 $type = $this->reflectionFunction->getReturnType();
188 if ($type instanceof ReflectionType) {
189 return $type;
190 // @codeCoverageIgnore
191 }
192 return self::adaptType($type);
193 }
194 /**
195 * {@inheritdoc}
196 */
197 public function isDeprecated() : TrinaryLogic
198 {
199 return TrinaryLogic::createFromBoolean($this->reflectionFunction->isDeprecated() || \preg_match('/@deprecated/i', $this->getDocComment() ?: ''));
200 }
201 /**
202 * {@inheritdoc}
203 */
204 public function isVariadic() : bool
205 {
206 return $this->reflectionFunction->isVariadic();
207 }
208 /**
209 * {@inheritdoc}
210 */
211 public function getPrototype() : BuiltinMethodReflection
212 {
213 return $this;
214 }
215 public function getTentativeReturnType() : ?ReflectionType
216 {
217 return null;
218 }
219 public function returnsByReference() : TrinaryLogic
220 {
221 return TrinaryLogic::createNo();
222 }
223 private static function adaptType($type)
224 {
225 $method = \method_exists(AdapterReflectionType::class, 'fromTypeOrNull') ? 'fromTypeOrNull' : 'fromReturnTypeOrNull';
226 // @codeCoverageIgnore
227 return AdapterReflectionType::$method($type);
228 }
229 private static function hasModernParser() : bool
230 {
231 static $modernParser = null;
232 if ($modernParser !== null) {
233 return $modernParser;
234 }
235 $modernParser = \method_exists(AdapterReflectionType::class, 'fromTypeOrNull');
236 return $modernParser;
237 }
238 }
239