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

PatternPropertiesGetter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
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
}