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 ( 4b817a...541108 )
by Bruno
02:39
created

StringGenerator::setShowFieldsDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher;
4
5
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
6
use Doctrine\ORM\Mapping\ClassMetadataInfo;
7
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator\FieldGeneratorHelper;
8
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator\StringGeneratorHelper;
9
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator\StringGeneratorHelperInterface;
10
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator\VisitedAssociationLogger;
11
use Onurb\Doctrine\ORMMetadataGrapher\YumlMetadataGrapher\StringGenerator\VisitedAssociationLoggerInterface;
12
13
class StringGenerator implements StringGeneratorInterface
14
{
15
16
    /**
17
     * @var array
18
     */
19
    private $classStrings;
20
21
    /**
22
     * @var StringGeneratorHelperInterface
23
     */
24
    private $stringHelper;
25
26
27
    /**
28
     * @var ClassStoreInterface
29
     */
30
    private $classStore;
31
32
    /**
33
     * @var VisitedAssociationLoggerInterface
34
     */
35
    private $associationLogger;
36
37
    /**
38
     * @var AnnotationParser
39
     */
40
    private $annotationParser;
41
42
    /**
43
     * @var bool
44
     */
45
    private $showFieldsDescription = false;
46
47
    /**
48
     * @param ClassStoreInterface $classStore
49
     */
50 16
    public function __construct(ClassStoreInterface $classStore)
51
    {
52 16
        $this->classStore = $classStore;
53 16
        $this->associationLogger = new VisitedAssociationLogger();
54 16
        $this->stringHelper = new StringGeneratorHelper();
55 16
        $this->annotationParser = new AnnotationParser();
56 16
    }
57
58
    /**
59
     * @param bool $showDescription
60
     * @return $this
61
     */
62 4
    public function setShowFieldsDescription($showDescription)
63
    {
64 4
        $this->showFieldsDescription = $showDescription;
65
66 4
        return $this;
67
    }
68
69
    /**
70
     * @return VisitedAssociationLoggerInterface
71
     */
72 2
    public function getAssociationLogger()
73
    {
74 2
        return $this->associationLogger;
75
    }
76
77
    /**
78
     * Build the string representing the single graph item
79
     *
80
     * @param ClassMetadata $class
81
     * @param bool $showFieldsDescription
0 ignored issues
show
Bug introduced by
There is no parameter named $showFieldsDescription. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
82
     * @return string
83
     */
84 14
    public function getClassString(ClassMetadata $class)
85
    {
86 14
        $className = $class->getName();
87
88 14
        if (!isset($this->classStrings[$className])) {
89 14
            $this->associationLogger->visitAssociation($className);
90
91 14
            $parentFields = $this->getParentFields($class);
92 14
            $fields       = $this->getClassFields($class, $parentFields, $this->showFieldsDescription);
93
94
95 14
            $methods = $this->annotationParser->getClassMethodsAnnotations($className);
96
97 14
            $this->classStrings[$className] = $this->stringHelper->getClassText($className, $fields, $methods);
98 14
        }
99
100 14
        return $this->classStrings[$className];
101
    }
102
103
    /**
104
     * Recursive function to get all fields in inheritance
105
     *
106
     * @param ClassMetadata $class
107
     * @param array $fields
108
     * @return array
109
     */
110 14
    private function getParentFields(ClassMetadata $class, $fields = array())
111
    {
112 14
        if ($parent = $this->classStore->getParent($class)) {
113 2
            $parentFields = $parent->getFieldNames();
114
115 2
            foreach ($parentFields as $field) {
116 2
                if (!in_array($field, $fields)) {
117 2
                    $fields[] = $field;
118 2
                }
119 2
            }
120
121 2
            $fields = $this->getParentFields($parent, $fields);
122 2
        }
123
124 14
        return $fields;
125
    }
126
127
    /**
128
     * @param ClassMetadata $class1
129
     * @param string $association
130
     * @return string
131
     */
132 6
    public function getAssociationString(ClassMetadata $class1, $association)
133
    {
134 6
        $targetClassName  = $class1->getAssociationTargetClass($association);
135 6
        $class2           = $this->classStore->getClassByName($targetClassName);
136 6
        $isInverse        = $class1->isAssociationInverseSide($association);
137 6
        $associationCount = $this->getClassCount($class1, $association);
138
139 6
        if (null === $class2) {
140 2
            return $this->stringHelper->makeSingleSidedLinkString(
141 2
                $this->getClassString($class1),
142 2
                $isInverse,
143 2
                $association,
144 2
                $associationCount,
145
                $targetClassName
146 2
            );
147
        }
148
149 5
        $reverseAssociationName = $this->getClassReverseAssociationName($class1, $association);
150
151 5
        $reverseAssociationCount = 0;
152 5
        $bidirectional = $this->isBidirectional(
153 5
            $reverseAssociationName,
154 5
            $isInverse,
155
            $class2
156 5
        );
157
158 5
        if ($bidirectional) {
159 3
            $reverseAssociationCount = $this->getClassCount($class2, $reverseAssociationName);
160 3
            $bidirectional = true;
161 3
        }
162
163 5
        $this->associationLogger->visitAssociation($targetClassName, $reverseAssociationName);
164
165 5
        return $this->stringHelper->makeDoubleSidedLinkString(
166 5
            $this->getClassString($class1),
167 5
            $this->getClassString($class2),
168 5
            $bidirectional,
169 5
            $isInverse,
170 5
            $reverseAssociationName,
171 5
            $reverseAssociationCount,
172 5
            $association,
173
            $associationCount
174 5
        );
175
    }
176
177
178
179
180
    /**
181
     * @param boolean $isInverse
182
     * @param string|null $reverseAssociationName
183
     * @param ClassMetadata $class2
184
     * @return bool
185
     */
186 5
    private function isBidirectional(
187
        $reverseAssociationName,
188
        $isInverse,
189
        ClassMetadata $class2
190
    ) {
191 5
        return null !== $reverseAssociationName
192 5
        && ($isInverse || $class2->isAssociationInverseSide($reverseAssociationName));
193
    }
194
195
    /**
196
     * @param ClassMetadata $class
197
     * @param string $association
198
     * @return int
199
     */
200 6
    private function getClassCount(ClassMetadata $class, $association)
201
    {
202 6
        return $class->isCollectionValuedAssociation($association) ? 2 : 1;
203
    }
204
205
    /**
206
     * @param ClassMetadata $class
207
     * @param array $parentFields
208
     * @param bool $DisplayAttributesDetails
209
     * @return array
210
     */
211 14
    private function getClassFields(ClassMetadata $class, $parentFields, $DisplayAttributesDetails = false)
212
    {
213 14
        $fields = array();
214
215 14
        foreach ($class->getFieldNames() as $fieldName) {
216 7
            if (in_array($fieldName, $parentFields)) {
217 2
                continue;
218
            }
219 7
            $DisplayAttributesDetails = $this->checkDisplayAnnotations($class->getName(), $DisplayAttributesDetails);
220
221
            //$showTypes = $this->getClassAttrPropsDisplay($class->getName(), $showTypes);
222
223 7
            $fields[] = $class->isIdentifier($fieldName) ?
224 7
                '+' . $this->makeFieldName($class, $fieldName, $DisplayAttributesDetails) :
225 7
                $this->makeFieldName($class, $fieldName, $DisplayAttributesDetails);
226 14
        }
227
228 14
        return $fields;
229
    }
230
231
    /**
232
     * Returns the $class2 association name for $class1 if reverse related (or null if not)
233
     *
234
     * @param ClassMetadata $class1
235
     * @param string $association
236
     *
237
     * @return string|null
238
     */
239 5
    private function getClassReverseAssociationName(ClassMetadata $class1, $association)
240
    {
241
        /**
242
         * @var ClassMetadataInfo $class1
243
         */
244 5
        if ($class1->getAssociationMapping($association)['isOwningSide']) {
245 5
            return $class1->getAssociationMapping($association)['inversedBy'];
246
        }
247
248 3
        return $class1->getAssociationMapping($association)['mappedBy'];
249
    }
250
251 7
    private function makeFieldName(ClassMetadata $class, $fieldName, $showTypes)
252
    {
253 7
        if ($showTypes) {
254 3
            $helper = new FieldGeneratorHelper();
255 3
            return $helper->getFullField($class, $fieldName);
256
        }
257
258 4
        return $fieldName;
259
    }
260
261
    /**
262
     * @param string $className
263
     * @param boolean $DisplayAttributesDetails
264
     * @return bool
265
     */
266 7
    private function checkDisplayAnnotations($className, $DisplayAttributesDetails)
267
    {
268 7
        $showParams = $this->annotationParser->getClassDisplay($className);
269 7
        if ($DisplayAttributesDetails && $showParams == 'hide') {
270 1
            return false;
271 7
        } elseif (!$DisplayAttributesDetails && $showParams == 'show') {
272 1
            return true;
273
        }
274
275 7
        return $DisplayAttributesDetails;
276
    }
277
}
278