Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
|
|
3 |
namespace Carbon\PHPStan; |
|
4 |
|
|
5 |
use Carbon\CarbonInterface; |
|
6 |
use ReflectionClass; |
|
7 |
use ReflectionException; |
|
8 |
|
|
9 |
final class MacroScanner |
|
10 |
{
|
|
11 |
/**
|
|
12 |
* Return true if the given pair class-method is a Carbon macro.
|
|
13 |
*
|
|
14 |
* @param string $className
|
|
15 |
* @phpstan-param class-string $className
|
|
16 |
*
|
|
17 |
* @param string $methodName
|
|
18 |
*
|
|
19 |
* @return bool
|
|
20 |
*/
|
|
21 | 1 |
public function hasMethod(string $className, string $methodName): bool |
22 |
{
|
|
23 | 1 |
return is_a($className, CarbonInterface::class, true) && |
24 | 1 |
\is_callable([$className, 'hasMacro']) && |
25 | 1 |
$className::hasMacro($methodName); |
26 |
}
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Return the Macro for a given pair class-method.
|
|
30 |
*
|
|
31 |
* @param string $className
|
|
32 |
* @phpstan-param class-string $className
|
|
33 |
*
|
|
34 |
* @param string $methodName
|
|
35 |
*
|
|
36 |
* @throws ReflectionException
|
|
37 |
*
|
|
38 |
* @return Macro
|
|
39 |
*/
|
|
40 | 1 |
public function getMethod(string $className, string $methodName): Macro |
41 |
{
|
|
42 | 1 |
$reflectionClass = new ReflectionClass($className); |
43 | 1 |
$property = $reflectionClass->getProperty('globalMacros'); |
44 |
|
|
45 | 1 |
$property->setAccessible(true); |
46 | 1 |
$macro = $property->getValue()[$methodName]; |
47 |
|
|
48 | 1 |
return new Macro( |
49 | 1 |
$className, |
50 |
$methodName, |
|
51 |
$macro
|
|
52 |
);
|
|
53 |
}
|
|
54 |
}
|
Read our documentation on viewing source code .