Method::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 6
dl 0
loc 11
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Code\Methods;
7
8
use PhUml\Code\Modifiers\CanBeAbstract;
9
use PhUml\Code\Modifiers\CanBeStatic;
10
use PhUml\Code\Modifiers\HasVisibility;
11
use PhUml\Code\Modifiers\Visibility;
0 ignored issues
show
Bug introduced by
The type PhUml\Code\Modifiers\Visibility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use PhUml\Code\Modifiers\WithAbstractModifier;
13
use PhUml\Code\Modifiers\WithStaticModifier;
14
use PhUml\Code\Modifiers\WithVisibility;
15
use PhUml\Code\Parameters\Parameter;
16
use PhUml\Code\Variables\TypeDeclaration;
17
use Stringable;
18
19
/**
20
 * It represents a class or interface method
21
 */
22
final class Method implements HasVisibility, CanBeAbstract, CanBeStatic, Stringable
23
{
24
    use WithVisibility;
25
    use WithAbstractModifier;
26
    use WithStaticModifier;
27
28
    /** @param Parameter[] $parameters */
29 51
    public function __construct(
30
        private readonly string $name,
31
        Visibility $visibility,
32
        private readonly TypeDeclaration $returnType,
33
        private readonly array $parameters = [],
34
        bool $isAbstract = false,
35
        bool $isStatic = false
36
    ) {
37 51
        $this->visibility = $visibility;
0 ignored issues
show
Bug introduced by
The property visibility is declared read-only in PhUml\Code\Methods\Method.
Loading history...
38 51
        $this->isAbstract = $isAbstract;
39 51
        $this->isStatic = $isStatic;
40
    }
41
42
    /**
43
     * It is used by the `ClassDefinition` to extract the parameters of a constructor
44
     *
45
     * @see \PhUml\Code\ClassDefinition::hasConstructor()
46
     * @see \PhUml\Code\ClassDefinition::constructorParameters()
47
     */
48 15
    public function isConstructor(): bool
49
    {
50 15
        return $this->name === '__construct';
51
    }
52
53
    /** @return Parameter[] */
54 16
    public function parameters(): array
55
    {
56 16
        return $this->parameters;
57
    }
58
59 15
    public function __toString(): string
60
    {
61 15
        return sprintf(
62
            '%s%s%s%s',
63 15
            $this->visibility->value,
64 15
            $this->name,
65 15
            $this->parameters === [] ? '()' : '(' . implode(', ', $this->parameters) . ')',
66 15
            $this->returnType->isPresent() ? ": {$this->returnType}" : ''
67
        );
68
    }
69
}
70