Completed
Push — master ( 3e4cb8...bfe96b )
by Tim
02:08
created

ReflectionService::is9orHigher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

This method has been deprecated.

Loading history...
64
                $methodReflection = $classReflection->getMethod($methodName);
65
                return $methodReflection->getTagsValues();
66
            }
67
        } catch (\Exception $e) {
68
            return false;
69
        }
70
    }
71
72
    /**
73
     * Is 9 or higher.
74
     *
75
     * @return bool
76
     */
77
    public function is9orHigher(): bool
78
    {
79
        return VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version()) >= VersionNumberUtility::convertVersionNumberToInteger('9.0.0');
80
    }
81
}
82