TypeTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 51
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A resolverType() 0 6 1
A transform() 0 4 1
A reverse() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpMob\Settings\Type;
15
16
use PhpMob\Settings\Schema\SettingSchemaRegistryInterface;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 */
21
class TypeTransformer implements TypeTransformerInterface
22
{
23
    /**
24
     * @var SettingSchemaRegistryInterface
25
     */
26
    private $schemaRegistry;
27
28
    /**
29
     * @var TypeRegistry
30
     */
31
    private $typeRegistry;
32
33
    /**
34
     * @param SettingSchemaRegistryInterface $schemaRegistry
35
     * @param TypeRegistryInterface $typeRegistry
36
     */
37
    public function __construct(SettingSchemaRegistryInterface $schemaRegistry, TypeRegistryInterface $typeRegistry)
38
    {
39
        $this->schemaRegistry = $schemaRegistry;
40
        $this->typeRegistry = $typeRegistry;
0 ignored issues
show
Documentation Bug introduced by
$typeRegistry is of type object<PhpMob\Settings\T...\TypeRegistryInterface>, but the property $typeRegistry was declared to be of type object<PhpMob\Settings\Type\TypeRegistry>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
41
    }
42
43
    /**
44
     * @param string $section
45
     * @param string $key
46
     *
47
     * @return TypeInterface
48
     */
49
    private function resolverType(string $section, string $key)
50
    {
51
        return $this->typeRegistry->get(
52
            $this->schemaRegistry->get($section, $key)->getType()
53
        );
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function transform(string $section, string $key, $value)
60
    {
61
        return $this->resolverType($section, $key)->setter($value);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function reverse(string $section, string $key, $value)
68
    {
69
        return $this->resolverType($section, $key)->getter($value);
70
    }
71
}
72