Passed
Push — master ( eef7fd...128351 )
by Ryan
12:25
created

AbstractType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 15 3
A getUnresolvableMessage() 0 5 1
1
<?php
2
/**
3
 * Copyright (c) 2017 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\Type;
12
13
abstract class AbstractType
14
{
15
    /**
16
     * Proxy method which forwards requests to an underlying handler.
17
     *
18
     * @param string $nodeName The name of the method being called.
19
     * @param array  $args     Any arguments passed into that method.
20
     *
21
     * @return mixed
22
     *
23
     * @codingStandardsIgnoreStart
24
     *
25
     *
26
     * @codingStandardsIgnoreEnd
27
     */
28
    public function __call(string $nodeName, array $args)
29
    {
30
        // Make sure we have *something*
31
        if (empty($args)) {
32
            $args[0] = null;
33
        }
34
35
        // Strip `get` from the start of the node name.
36
        if ('get' === \mb_substr($nodeName, 0, 3)) {
37
            $nodeName = \lcfirst(\mb_substr($nodeName, 3));
38
        }
39
40
        $nodeName = $this->getAlias($nodeName);
0 ignored issues
show
Bug introduced by
The method getAlias() does not exist on SimplePie\Type\AbstractType. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

40
        /** @scrutinizer ignore-call */ 
41
        $nodeName = $this->getAlias($nodeName);
Loading history...
41
42
        return $this->getHandler($nodeName, $args);
0 ignored issues
show
Bug introduced by
The method getHandler() does not exist on SimplePie\Type\AbstractType. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

42
        return $this->/** @scrutinizer ignore-call */ getHandler($nodeName, $args);
Loading history...
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
     * @return string
51
     */
52
    protected function getUnresolvableMessage(string $nodeName): string
53
    {
54
        return \sprintf(
55
            '%s is an unresolvable method.',
56
            \sprintf('get%s', \ucfirst($nodeName))
57
        );
58
    }
59
}
60