Passed
Pull Request — master (#933)
by Asmir
14:31
created

DefaultAccessorStrategy::startAccessing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace JMS\Serializer\Accessor;
22
23
use GeneratedHydrator\Configuration;
24
use JMS\Serializer\Metadata\ClassMetadata;
25
use JMS\Serializer\Metadata\PropertyMetadata;
26
27
/**
28
 * @author Asmir Mustafic <[email protected]>
29
 */
30
final class DefaultAccessorStrategy implements AccessorStrategyInterface
31 160
{
32
    private $gen = array();
33 160
34
    public function getValue(object $object, PropertyMetadata $metadata, $context)
35
    {
36 59
37
        if (!$metadata->getter && array_key_exists($metadata->name, $context)) {
38 59
            return $context[$metadata->name];
39 59
        }
40
41
        return $metadata->getValue($object);
42
    }
43
44
    public function setValue(object $object, $value, PropertyMetadata $metadata): void
45
    {
46
        $metadata->setValue($object, $value);
47
    }
48
49
    public function startAccessing(object $object, ClassMetadata $metadata)
0 ignored issues
show
Unused Code introduced by
The parameter $metadata is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    public function startAccessing(object $object, /** @scrutinizer ignore-unused */ ClassMetadata $metadata)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        $class = get_class($object);
52
53
        if (!isset($this->gen[$class])) {
54
            $config = new Configuration($class);
55
            $hydratorClass = $config->createFactory()->getHydratorClass();
56
            $this->gen[$class] = new $hydratorClass();
57
        }
58
59
        return $this->gen[$class]->extract($object);
60
    }
61
62
    public function endAccessing(object $object, ClassMetadata $metadata, $context)
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
    public function endAccessing(object $object, ClassMetadata $metadata, /** @scrutinizer ignore-unused */ $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
    public function endAccessing(/** @scrutinizer ignore-unused */ object $object, ClassMetadata $metadata, $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $metadata is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
    public function endAccessing(object $object, /** @scrutinizer ignore-unused */ ClassMetadata $metadata, $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
65
    }
66
}
67