Passed
Pull Request — master (#20)
by
unknown
03:05
created

Article::getPublicationName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
use TypedArrays\AbstractTypedArray;
6
7
require getcwd() . '/vendor/autoload.php';
8
9
interface InterfacePublication
10
{
11
    public function getPublicationName(): string;
12
    public function getPublicationUrl(): string;
13
}
14
15
final class Article implements InterfacePublication
16
{
17
    private int $id;
18
    private string $name;
19
    private string $slug;
20
21
    public function __construct(int $id, string $name, string $slug)
22
    {
23
        $this->id = $id;
24
        $this->name = $name;
25
        $this->slug = $slug;
26
    }
27
28
    public function getPublicationName(): string
29
    {
30
        return $this->name;
31
    }
32
33
    public function getPublicationUrl(): string
34
    {
35
        return "https://example.org/articles/{$this->id}-{$this->slug}";
1 ignored issue
show
Bug Best Practice introduced by
The property slug does not exist on Article. Did you maybe forget to declare it?
Loading history...
36
    }
37
}
38
39
final class YouTubeVideo implements InterfacePublication
40
{
41
    private string $id;
42
    private string $name;
43
44
    public function __construct(string $id, string $name)
45
    {
46
        $this->id = $id;
47
        $this->name = $name;
48
    }
49
50
    public function getPublicationName(): string
51
    {
52
        return $this->name;
53
    }
54
55
    public function getPublicationUrl(): string
56
    {
57
        return "https://www.youtube.com/watch?v={$this->id}";
58
    }
59
}
60
61
final class PublicationList extends AbstractTypedArray
62
{
63
    protected function typeToEnforce(): string
64
    {
65
        return InterfacePublication::class;
66
    }
67
68
    protected function isMutable(): bool
69
    {
70
        return false;
71
    }
72
73
    protected function collectionType(): string
74
    {
75
        return self::COLLECTION_TYPE_LIST;
76
    }
77
}
78
79
$publications = new PublicationList([
80
    new Article(1, 'TypedArrays is awesome', 'typed-arrays-is-awesome'),
1 ignored issue
show
Unused Code introduced by
The call to Article::__construct() has too many arguments starting with 'typed-arrays-is-awesome'. ( Ignorable by Annotation )

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

80
    /** @scrutinizer ignore-call */ 
81
    new Article(1, 'TypedArrays is awesome', 'typed-arrays-is-awesome'),

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...
81
    new YouTubeVideo('dQw4w9WgXcQ', 'Lil cute kittens'),
82
    new Article(2, 'Indeterminate graviton harmonics chain reaction', 'indeterminate-graviton-harmonics-chain-reaction'),
83
]);
84
85
renderPublicationList($publications);
86
87
function renderPublicationList(PublicationList $publications): void
88
{
89
    print '<ul>' . PHP_EOL;
90
    foreach ($publications as $publication) {
91
        print "<a href=\"{$publication->getPublicationUrl()}\">{$publication->getPublicationName()}</a>" . PHP_EOL;
92
    }
93
}
94