Completed
Pull Request — develop (#27)
by Chris
13:09
created

AbstractMetadatas   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 2
A getByPropertyName() 0 8 3
A getIterator() 0 4 1
A load() 0 10 3
generateMetadata() 0 1 ?
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Model\Mapping;
4
5
abstract class AbstractMetadatas implements \IteratorAggregate
6
{
7
    protected $annotationReader;
8
    protected $metadatas = [];
9
10
    public function get($key)
11
    {
12
        if (isset($this->metadatas[$key])) {
13
            return $this->metadatas[$key];
14
        }
15
    }
16
17
    public function getByPropertyName($name)
18
    {
19
        foreach ($this->metadatas as $metadata) {
20
            if ($name === $metadata->getProperty()->getName()) {
21
                return $metadata;
22
            }
23
        }
24
    }
25
26
    public function getIterator()
27
    {
28
        return new \ArrayIterator($this->metadatas);
29
    }
30
31
    protected function load($class)
32
    {
33
        $refClass = new \ReflectionClass($class);
34
35
        foreach ($refClass->getProperties() as $refProp) {
36
            foreach ($this->annotationReader->getPropertyAnnotations($refProp) as $annot) {
37
                $this->generateMetadata($refProp, $annot);
38
            }
39
        }
40
    }
41
42
    abstract protected function generateMetadata(\ReflectionProperty $refProp, $annot);
43
}
44