TableBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 52
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getTables() 0 10 3
A getAnnotations() 0 4 1
A createTable() 0 5 1
1
<?php
2
namespace Pumpkin\Database;
3
4
use Doctrine\Common\Annotations\AnnotationReader;
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Doctrine\Common\Annotations\Reader;
7
use Pumpkin\Test\Test;
8
use Pumpkin\Test\TestHelper;
9
10
class TableBuilder extends TestHelper
11
{
12
    /**
13
     * @var Reader
14
     */
15
    private $reader;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param Test $test
21
     * @param Reader $reader
0 ignored issues
show
Documentation introduced by
Should the type for parameter $reader not be null|Reader?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
22
     */
23 3
    public function __construct(Test $test, Reader $reader = null)
24
    {
25 3
        AnnotationRegistry::registerAutoloadNamespace('Pumpkin\Database\Annotation', __DIR__ . '/../..');
26 3
        $this->reader = $reader ?: new AnnotationReader();
27 3
        parent::__construct($test);
28 3
    }
29
30
    /**
31
     * @return Table[]
32
     */
33 3
    public function getTables()
34
    {
35 3
        $result = array();
36 3
        foreach ($this->getAnnotations() as $annotation) {
37 3
            if ($annotation instanceof Annotation) {
38 3
                $result[$annotation->value] = $this->createTable($annotation->value);
39 3
            }
40 3
        }
41 3
        return $result;
42
    }
43
44
    /**
45
     * @return array
46
     */
47 3
    private function getAnnotations()
48
    {
49 3
        return $this->reader->getMethodAnnotations($this->getTest()->getReflectedTestMethod());
50
    }
51
52
    /**
53
     * @param string $tableFullName
54
     * @return Table
55
     */
56 3
    private function createTable($tableFullName)
57
    {
58 3
        list($dataBaseName, $tableName) = explode('.', $tableFullName);
59 3
        return new Table($this->getTest(), $dataBaseName, $tableName);
60
    }
61
}
62