Completed
Push — master ( ac0b2b...25e509 )
by Nate
02:57
created

MetadataFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createClassMetadata() 0 4 1
A createPropertyMetadata() 0 12 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Gson\Internal;
8
9
use Tebru\Gson\ClassMetadata;
10
use Tebru\Gson\Internal\Data\AnnotationCollectionFactory;
11
use Tebru\Gson\Internal\Data\AnnotationSet;
12
use Tebru\Gson\Internal\Data\Property;
13
use Tebru\Gson\PropertyMetadata;
14
15
/**
16
 * Class MetadataFactory
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
final class MetadataFactory
21
{
22
    /**
23
     * Reads annotations from a class, property, or method and returns
24
     * an [@see AnnotationSet]
25
     *
26
     * @var AnnotationCollectionFactory
27
     */
28
    private $annotationCollectionFactory;
29
30
    /**
31
     * Constructor
32
     *
33
     * @param AnnotationCollectionFactory $annotationCollectionFactory
34
     */
35 2
    public function __construct(AnnotationCollectionFactory $annotationCollectionFactory)
36
    {
37 2
        $this->annotationCollectionFactory = $annotationCollectionFactory;
38 2
    }
39
40
    /**
41
     * Create class metadata
42
     *
43
     * @param string $className
44
     * @return ClassMetadata
45
     * @throws \InvalidArgumentException If the type does not exist
46
     */
47 2
    public function createClassMetadata(string $className): ClassMetadata
48
    {
49 2
        return new ClassMetadata($className, $this->annotationCollectionFactory->createClassAnnotations($className));
50
    }
51
52
    /**
53
     * Creates property metadata
54
     *
55
     * @param Property $property
56
     * @param ClassMetadata $classMetadata
57
     * @return PropertyMetadata
58
     */
59 1
    public function createPropertyMetadata(Property $property, ClassMetadata $classMetadata): PropertyMetadata
60
    {
61 1
        return new PropertyMetadata(
62 1
            $property->getRealName(),
63 1
            $property->getSerializedName(),
64 1
            $property->getType(),
65 1
            $property->getModifiers(),
66
            $classMetadata,
67 1
            $property->getAnnotations(),
68 1
            $property->isVirtual()
69
        );
70
    }
71
}
72