SmartObjects   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 60
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareLoader() 0 24 4
A loadExtensionTables() 0 4 1
A loadExtensionConfiguration() 0 4 1
A addClassesToSmartRegister() 0 6 2
1
<?php
2
3
/**
4
 * Loading SmartObjects.
5
 */
6
declare(strict_types = 1);
7
8
namespace HDNET\Autoloader\Loader;
9
10
use HDNET\Autoloader\Loader;
11
use HDNET\Autoloader\LoaderInterface;
12
use HDNET\Autoloader\SmartObjectManager;
13
use HDNET\Autoloader\SmartObjectRegister;
14
use HDNET\Autoloader\Utility\ClassNamingUtility;
15
use HDNET\Autoloader\Utility\FileUtility;
16
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
17
18
/**
19
 * Loading SmartObjects.
20
 */
21
class SmartObjects implements LoaderInterface
22
{
23
    /**
24
     * Get all the complex data for the loader.
25
     * This return value will be cached and stored in the database
26
     * There is no file monitoring for this cache.
27
     */
28
    public function prepareLoader(Loader $loader, int $type): array
29
    {
30
        $configuration = [];
31
        $modelPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Classes/Domain/Model/';
32
        if (!is_dir($modelPath)) {
33
            return $configuration;
34
        }
35
36
        $models = FileUtility::getBaseFilesRecursivelyInDir($modelPath, 'php');
37
        foreach ($models as $model) {
38
            $className = ClassNamingUtility::getFqnByPath(
39
                $loader->getVendorName(),
40
                $loader->getExtensionKey(),
41
                'Domain/Model/' . $model
42
            );
43
            if (SmartObjectManager::isSmartObjectClass($className)) {
44
                $configuration[] = $className;
45
            }
46
        }
47
        // already add for the following processes
48
        $this->addClassesToSmartRegister($configuration);
49
50
        return $configuration;
51
    }
52
53
    /**
54
     * Run the loading process for the ext_tables.php file.
55
     */
56
    public function loadExtensionTables(Loader $loader, array $loaderInformation): void
57
    {
58
        $this->addClassesToSmartRegister($loaderInformation);
59
    }
60
61
    /**
62
     * Run the loading process for the ext_localconf.php file.
63
     */
64
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void
65
    {
66
        $this->addClassesToSmartRegister($loaderInformation);
67
    }
68
69
    /**
70
     * Add the given classes to the SmartObject Register.
71
     *
72
     * @param array $loaderInformation
73
     */
74
    protected function addClassesToSmartRegister($loaderInformation): void
75
    {
76
        foreach ($loaderInformation as $configuration) {
77
            SmartObjectRegister::register($configuration);
78
        }
79
    }
80
}
81