Completed
Push — master ( 716959...c2acd0 )
by Luis
04:37 queued 02:39
created

Method::parameters()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Code;
9
10
/**
11
 * It represents a class or interface method
12
 *
13
 * It doesn't distinguish neither static methods nor return types yet
14
 */
15
class Method
16
{
17
    /** @var string */
18
    private $name;
19
20
    /** @var Visibility */
21
    private $modifier;
22
23
    /** @var Variable[] */
24
    private $parameters;
25
26 105
    private function __construct(string $name, Visibility $modifier, array $params = [])
27
    {
28 105
        $this->name = $name;
29 105
        $this->modifier = $modifier;
30 105
        $this->parameters = $params;
31 105
    }
32
33 102
    public static function public(string $name, array $params = []): Method
34
    {
35 102
        return new Method($name, Visibility::public(), $params);
36
    }
37
38 15
    public static function protected(string $name, array $params = []): Method
39
    {
40 15
        return new Method($name, Visibility::protected(), $params);
41
    }
42
43 33
    public static function private(string $name, array $params = []): Method
44
    {
45 33
        return new Method($name, Visibility::private(), $params);
46
    }
47
48 27
    public function isConstructor(): bool
49
    {
50 27
        return $this->name === '__construct';
51
    }
52
53 12
    public function hasVisibility(Visibility $modifier): bool
54
    {
55 12
        return $this->modifier->equals($modifier);
56
    }
57
58 3
    public function name(): string
59
    {
60 3
        return $this->name;
61
    }
62
63 3
    public function modifier(): Visibility
64
    {
65 3
        return $this->modifier;
66
    }
67
68 21
    public function parameters(): array
69
    {
70 21
        return $this->parameters;
71
    }
72
73 27
    public function __toString()
74
    {
75 27
        return sprintf(
76 27
            '%s%s%s',
77 27
            $this->modifier,
78 27
            $this->name,
79 27
            empty($this->parameters) ? '()' : '( ' . implode($this->parameters, ', ') . ' )'
0 ignored issues
show
Unused Code introduced by
The call to implode() has too many arguments starting with ', '. ( Ignorable by Annotation )

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

79
            empty($this->parameters) ? '()' : '( ' . /** @scrutinizer ignore-call */ implode($this->parameters, ', ') . ' )'

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
80
        );
81
    }
82
}
83