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 ( 0acf33...2eba7c )
by Bruno
04:10
created

YUMLMetadataGrapher::generateFromMetadata()   C

Complexity

Conditions 8
Paths 5

Size

Total Lines 39
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 8

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 39
ccs 27
cts 27
cp 1
rs 5.3846
cc 8
eloc 21
nc 5
nop 1
crap 8
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
     * Generate a yUML compatible `dsl_text` to describe a given array
48
     * of entities
49
     *
50
     * @param  $metadata ClassMetadata[]
51
     *
52
     * @return string
53
     */
54 24
    public function generateFromMetadata(array $metadata)
55
    {
56 24
        $this->classStore = new ClassStore($metadata);
57 24
        $this->stringGenerator = new StringGenerator($this->classStore);
58
59 24
        $str = array();
60
61 24
        foreach ($metadata as $class) {
62 24
            if ($parent = $this->classStore->getParent($class)) {
63 4
                $str[] = $this->stringGenerator->getClassString($parent) . '^'
64 4
                    . $this->stringGenerator->getClassString($class);
65 4
            }
66
67 24
            $associations = $class->getAssociationNames();
68
69 24
            if (empty($associations)
70 24
                && !$this->stringGenerator->getAssociationLogger()->isVisitedAssociation($class->getName())
71 24
            ) {
72 3
                $str[] = $this->stringGenerator->getClassString($class);
73
74 3
                continue;
75
            }
76
77 22
            $inheritanceAssociations = $this->getInheritanceAssociations($class);
78
79 22
            foreach ($associations as $associationName) {
80 19
                if (in_array($associationName, $inheritanceAssociations)) {
81 1
                    continue;
82
                }
83
84 19
                if ($this->stringGenerator->getAssociationLogger()
85 19
                    ->visitAssociation($class->getName(), $associationName)
86 19
                ) {
87 19
                    $str[] = $this->stringGenerator->getAssociationString($class, $associationName);
88 19
                }
89 22
            }
90 24
        }
91 24
        return implode(',', $str);
92
    }
93
94
    /**
95
     * Recursive function to get all associations in inheritance
96
     *
97
     * @param ClassMetadata $class
98
     * @param array $associations
99
     * @return array
100
     */
101 22
    private function getInheritanceAssociations(ClassMetadata $class, $associations = array())
102
    {
103 22
        if ($parent = $this->classStore->getParent($class)) {
104 4
            foreach ($parent->getAssociationNames() as $association) {
105 1
                if (!in_array($association, $associations)) {
106 1
                    $associations[] = $association;
107 1
                }
108 4
            }
109 4
            $associations = $this->getInheritanceAssociations($parent, $associations);
110 4
        }
111
112 22
        return $associations;
113
    }
114
}
115