Completed
Push — master ( 0e6e64...9192b1 )
by Viacheslav
12s
created

PatternPropertiesGetter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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