Passed
Push — master ( 6a9eaa...94fc61 )
by
unknown
01:27 queued 11s
created

YouTubeVideo::getPublicationUrl()   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
13
    public function getPublicationUrl(): string;
14
}
15
16
final class Article implements InterfacePublication
17
{
18
    private int $id;
19
    private string $name;
20
    private string $slug;
21
22
    public function __construct(int $id, string $name, string $slug)
23
    {
24
        $this->id = $id;
25
        $this->name = $name;
26
        $this->slug = $slug;
27
    }
28
29
    public function getPublicationName(): string
30
    {
31
        return $this->name;
32
    }
33
34
    public function getPublicationUrl(): string
35
    {
36
        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...
37
    }
38
}
39
40
final class YouTubeVideo implements InterfacePublication
41
{
42
    private string $id;
43
    private string $name;
44
45
    public function __construct(string $id, string $name)
46
    {
47
        $this->id = $id;
48
        $this->name = $name;
49
    }
50
51
    public function getPublicationName(): string
52
    {
53
        return $this->name;
54
    }
55
56
    public function getPublicationUrl(): string
57
    {
58
        return "https://www.youtube.com/watch?v={$this->id}";
59
    }
60
}
61
62
final class PublicationList extends AbstractTypedArray
63
{
64
    protected function typeToEnforce(): string
65
    {
66
        return InterfacePublication::class;
67
    }
68
69
    protected function isMutable(): bool
70
    {
71
        return false;
72
    }
73
74
    protected function collectionType(): string
75
    {
76
        return self::COLLECTION_TYPE_LIST;
77
    }
78
}
79
80
$publications = new PublicationList([
81
    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

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