Completed
Push — master ( ce4dc0...d5077a )
by Tim
02:08
created

ReflectionService::getClassTagValues()   A

Complexity

Conditions 3
Paths 7

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 7
nop 2
1
<?php
2
3
/**
4
 * ReflectionService
5
 */
6
7
namespace HDNET\Autoloader\Service;
8
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
11
/**
12
 * ReflectionService
13
 */
14
class ReflectionService
15
{
16
17
    /**
18
     * Get the tag value
19
     * - Array (if the tag exist)
20
     * - false (if the tag do not exists)
21
     *
22
     * @param string $className
23
     * @param string $tag
24
     * @return array|bool
25
     */
26
    public function getClassTagValues(string $className, string $tag)
27
    {
28
        try {
29
            $coreReflectionService = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
30
            $classSchema = $coreReflectionService->getClassSchema($className);
31
            $tags = $classSchema->getTags();
32
33
            if (!array_key_exists($tag, $tags)) {
34
                return false;
35
            }
36
37
            return $tags[$tag] ?? [];
38
        } catch (\Exception $e) {
39
            return false;
40
        }
41
    }
42
43
    /**
44
     * Get method tag values
45
     * - Array
46
     * - False (if there are any problems)
47
     *
48
     * @param string $className
49
     * @param string $methodName
50
     * @return array|bool
51
     */
52
    public function getMethodTagValues(string $className, string $methodName)
53
    {
54
        try {
55
            $coreReflectionService = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class);
56
            $classSchema = $coreReflectionService->getClassSchema($className);
57
            return $classSchema->getMethod($methodName)['tags'] ?? [];
58
        } catch (\Exception $e) {
59
            return false;
60
        }
61
    }
62
63
}
64