ConstantWriter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeElement() 0 4 1
A writeElements() 0 14 2
1
<?php
2
3
namespace Flagbit\Plantuml\TokenReflection;
4
5
use TokenReflection\IReflectionConstant;
6
7
class ConstantWriter extends WriterAbstract
8
{
9
    /**
10
     * @param IReflectionConstant $constant
11
     *
12
     * @return string
13
     */
14 4
    public function writeElement(IReflectionConstant $constant)
15
    {
16 4
        return $this->formatLine('+{static}' . $constant->getName() . ' = ' . $this->formatValue($constant->getValue()));
17
    }
18
19
    /**
20
     * @param IReflectionConstant[] $constants
21
     *
22
     * @return string
23
     */
24 11
    public function writeElements(array $constants)
25
    {
26
        // see https://bugs.php.net/bug.php?id=50688
27 11
        @usort($constants, function(IReflectionConstant $a, IReflectionConstant $b) {
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
28 3
            return strnatcasecmp($a->getName(), $b->getName());
29 11
        });
30
31 11
        $constantsString = '';
32 11
        foreach ($constants as $constant) {
33
            /** @var $property IReflectionConstant */
34 3
            $constantsString .= $this->writeElement($constant);
35 11
        }
36 11
        return $constantsString;
37
    }
38
}
39