AbstractType::__call()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 4
nop 2
crap 3
1
<?php
2
/**
3
 * Copyright (c) 2017–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\Type;
12
13
/**
14
 * The base type class that all other type classes extend from. It handles low-level functionality that is shared
15
 * across all type classes.
16
 */
17
abstract class AbstractType
18
{
19
    /**
20
     * Proxy method which forwards requests to an underlying handler.
21
     *
22
     * @param string $nodeName The name of the method being called.
23
     * @param array  $args     Any arguments passed into that method.
24
     *
25
     * @internal
26
     */
27 560
    public function __call(string $nodeName, array $args)
28
    {
29
        // Make sure we have *something*
30 560
        if (empty($args)) {
31 553
            $args[0] = null;
32
        }
33
34
        // Strip `get` from the start of the node name.
35 560
        if ('get' === \mb_substr($nodeName, 0, 3)) {
36 560
            $nodeName = \lcfirst(\mb_substr($nodeName, 3));
37
        }
38
39
        /** @scrutinizer ignore-call */
40 560
        $nodeName = $this->getAlias($nodeName);
41
42 560
        return $this->/* @scrutinizer ignore-call */getHandler($nodeName, $args);
43
    }
44
45
    /**
46
     * Gets the standard, pre-formatted message for unresolvable method calls.
47
     *
48
     * @param string $nodeName The short version of the call (without the `get`).
49
     *
50
     * @internal
51
     */
52 6
    protected function getUnresolvableMessage(string $nodeName): string
53
    {
54 6
        return \sprintf(
55 6
            '%s is an unresolvable method.',
56 6
            \sprintf('get%s', \ucfirst($nodeName))
57
        );
58
    }
59
}
60