GetByMethod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 28
ccs 5
cts 5
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 3 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Internal\AccessorStrategy;
10
11
use Tebru\Gson\Internal\GetterStrategy;
12
13
/**
14
 * Class GetByMethod
15
 *
16
 * Get data from an object using a public method
17
 *
18
 * This class contains public properties to improve performance.
19
 *
20
 * @author Nate Brunette <[email protected]>
21
 */
22
final class GetByMethod implements GetterStrategy
23
{
24
    /**
25
     * The name of the method
26
     *
27
     * @var string
28
     */
29
    public $methodName;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param string $methodName
35
     */
36 4
    public function __construct(string $methodName)
37
    {
38 4
        $this->methodName = $methodName;
39 4
    }
40
41
    /**
42
     * Get value from object by method name
43
     *
44
     * @param object $object
45
     * @return mixed
46
     */
47 2
    public function get($object)
48
    {
49 2
        return $object->{$this->methodName}();
50
    }
51
}
52