Passed
Push — cleanup ( 1df3c6 )
by Luis
14:39
created

Method::private()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
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
    private static $symbols = [
18
        'private' => '-',
19
        'protected' => '#',
20
        'public' => '+',
21
    ];
22
23
    /** @var string */
24
    public $name;
25
26
    /** @var string */
27
    public $modifier;
28
29
    /** @var Variable[] */
30
    public $params;
31
32
    private function __construct(string $name, string $modifier = 'public', array $params = [])
33
    {
34
        $this->name = $name;
35
        $this->modifier = $modifier;
36
        $this->params = $params;
37
    }
38
39
    public static function public(string $name, array $params = []): Method
40
    {
41
        return new Method($name, 'public', $params);
42
    }
43
44
    public static function protected(string $name, array $params = []): Method
45
    {
46
        return new Method($name, 'protected', $params);
47
    }
48
49
    public static function private(string $name, array $params = []): Method
50
    {
51
        return new Method($name, 'private', $params);
52
    }
53
54
    public function isConstructor(): bool
55
    {
56
        return $this->name === '__construct';
57
    }
58
59
    public function __toString()
60
    {
61
        return sprintf(
62
            '%s%s%s',
63
            self::$symbols[$this->modifier],
64
            $this->name,
65
            empty($this->params) ? '()' : '( ' . implode($this->params, ', ') . ' )'
0 ignored issues
show
Bug introduced by
$this->params of type PhUml\Code\Variable[] is incompatible with the type string expected by parameter $glue of implode(). ( Ignorable by Annotation )

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

65
            empty($this->params) ? '()' : '( ' . implode(/** @scrutinizer ignore-type */ $this->params, ', ') . ' )'
Loading history...
Bug introduced by
', ' of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

65
            empty($this->params) ? '()' : '( ' . implode($this->params, /** @scrutinizer ignore-type */ ', ') . ' )'
Loading history...
66
        );
67
    }
68
}
69