AdditionalPropertiesGetter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder\Property;
4
5
6
use Swaggest\PhpCodeBuilder\PhpAnyType;
7
use Swaggest\PhpCodeBuilder\PhpFlags;
8
use Swaggest\PhpCodeBuilder\PhpFunction;
9
use Swaggest\PhpCodeBuilder\Types\ArrayOf;
10
11
class AdditionalPropertiesGetter extends PhpFunction
12
{
13 2
    public function __construct(PhpAnyType $type)
14
    {
15 2
        parent::__construct('getAdditionalPropertyValues', PhpFlags::VIS_PUBLIC);
16
17 2
        $this->skipCodeCoverage = true;
18
19 2
        $this->setResult(new ArrayOf($type));
20 2
        $this->setBody(
21
            <<<'PHP'
22 2
$result = array();
23
if (!$names = $this->getAdditionalPropertyNames()) {
24
    return $result;
25
}
26
foreach ($names as $name) {
27
    $result[$name] = $this->$name;
28
}
29
return $result;
30
31
PHP
32
        );
33
    }
34
}