GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 47f9c5...37c9bf )
by Bruno
02:35
created

YUMLMetadataGrapher::writeClassAssociations()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Onurb\Doctrine\ORMMetadataGrapher;
21
22
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
23
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\ClassStore;
24
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator;
25
26
/**
27
 * Utility to generate yUML compatible strings from metadata graphs
28
 *
29
 * @license MIT
30
 * @link    http://www.doctrine-project.org/
31
 * @author  Marco Pivetta   <[email protected]>
32
 * @author  Bruno Heron     <<[email protected]>
33
 */
34
class YUMLMetadataGrapher implements YUMLMetadataGrapherInterface
35
{
36
    /**
37
     * @var ClassStore
38
     */
39
    protected $classStore;
40
41
    /**
42
     * @var StringGenerator
43
     */
44
    protected $stringGenerator;
45
46
    /**
47
     * @var array
48
     */
49
    protected $str = array();
50
51
    /**
52
     * Generate a yUML compatible `dsl_text` to describe a given array
53
     * of entities
54
     *
55
     * @param  $metadata ClassMetadata[]
56
     *
57
     * @return string
58
     */
59 24
    public function generateFromMetadata(array $metadata)
60
    {
61 24
        $this->classStore = new ClassStore($metadata);
62 24
        $this->stringGenerator = new StringGenerator($this->classStore);
63
64 24
        foreach ($metadata as $class) {
65 24
            $this->writeParentAssociation($class);
66
67 24
            $associations = $class->getAssociationNames();
68
69 24
            if (empty($associations)) {
70 8
                $this->writeSingleClass($class);
71 8
            } else {
72 19
                $this->writeClassAssociations($class, $associations);
73
            }
74
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
75 24
        }
76 24
        return implode(',', $this->str);
77
    }
78
79
    /**
80
     * @param ClassMetadata $class
81
     */
82 24
    private function writeParentAssociation(ClassMetadata $class)
83
    {
84 24
        if ($parent = $this->classStore->getParent($class)) {
85 4
            $this->str[] = $this->stringGenerator->getClassString($parent) . '^'
86 4
                . $this->stringGenerator->getClassString($class);
87 4
        }
88 24
    }
89
90
    /**
91
     * @param ClassMetadata $class
92
     */
93 8
    private function writeSingleClass(ClassMetadata $class)
94
    {
95 8
        if (!$this->stringGenerator->getAssociationLogger()->isVisitedAssociation($class->getName())) {
96 3
            $this->str[] = $this->stringGenerator->getClassString($class);
97 3
        }
98 8
    }
99
100
    /**
101
     * @param ClassMetadata $class
102
     * @param array $associations
103
     */
104 19
    private function writeClassAssociations(ClassMetadata $class, $associations)
105
    {
106 19
        $inheritanceAssociations = $this->getInheritanceAssociations($class);
107
108 19
        foreach ($associations as $associationName) {
109 19
            if (in_array($associationName, $inheritanceAssociations)) {
110 1
                continue;
111
            }
112
113 19
            $this->writeAssociation($class, $associationName);
114 19
        }
115 19
    }
116
117
    /**
118
     * @param ClassMetadata $class
119
     * @param string $association
120
     */
121 19
    private function writeAssociation(ClassMetadata $class, $association)
122
    {
123 19
        if ($this->stringGenerator->getAssociationLogger()
124 19
            ->visitAssociation($class->getName(), $association)
125 19
        ) {
126 19
            $this->str[] = $this->stringGenerator->getAssociationString($class, $association);
127 19
        }
128 19
    }
129
130
    /**
131
     * Recursive function to get all associations in inheritance
132
     *
133
     * @param ClassMetadata $class
134
     * @param array $associations
135
     * @return array
136
     */
137 19
    private function getInheritanceAssociations(ClassMetadata $class, $associations = array())
138
    {
139 19
        if ($parent = $this->classStore->getParent($class)) {
140 1
            foreach ($parent->getAssociationNames() as $association) {
141 1
                if (!in_array($association, $associations)) {
142 1
                    $associations[] = $association;
143 1
                }
144 1
            }
145 1
            $associations = $this->getInheritanceAssociations($parent, $associations);
146 1
        }
147
148 19
        return $associations;
149
    }
150
}
151