Completed
Push — master ( 2b42cc...3dab4c )
by Max
01:07
created

MetaData   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 47
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHelper() 0 7 2
A methods() 0 5 1
A fields() 0 5 1
A filterRules() 0 13 4
1
<?php
2
/*
3
 *  @copyright (c) 2019 Mendel <[email protected]>
4
 *  @license see license.txt
5
 */
6
7
namespace drycart\data;
8
9
/**
10
 * Metadata for some class
11
 * i.e. some data from comments for class, fields, methods
12
 * 
13
 * @deprecated
14
 * #see MetaDataHelper
15
 * 
16
 * @author mendel
17
 */
18
class MetaData
19
{
20
    protected static $helper;
21
    protected $className;
22
    protected $rules = [
23
    ];
24
    
25
    public function __construct(string $className, array $rules) {
26
        $this->rules = $rules;
27
        $this->className = $className;
28
    }
29
    
30
    protected static function getHelper() : MetaDataHelper
31
    {
32
        if(!isset(static::$helper)) {
33
            static::$helper = new MetaDataHelper();
34
        }
35
        return static::$helper;
36
    }
37
38
39
    public function methods() : array {
40
        $data = self::getHelper()->methodsMeta($this->className);
41
        $preparedData = $this->getHelper()->prepareRules($data);
42
        return $this->filterRules($preparedData, $this->rules);
43
    }
44
    
45
    public function fields() : array {
46
        $data = self::getHelper()->fieldsMeta($this->className);
47
        $preparedData = $this->getHelper()->prepareRules($data);
48
        return $this->filterRules($preparedData, $this->rules);
49
    }
50
    
51
    protected function filterRules(array $data, array $rules) : array
52
    {
53
        $result = [];
54
        foreach($data as $name=>$line) {
55
            foreach($line as $key=>$value) {
56
                if(isset($rules[$key])) {
57
                    $rule = $rules[$key];
58
                    $result[$name][$rule] = $value;
59
                }
60
            }
61
        }
62
        return $result;
63
    }
64
}
65