GetByMethod::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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