AbstractType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 3
b 0
f 0
dl 0
loc 40
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUnresolvableMessage() 0 5 1
A __call() 0 16 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