Skip to content

Commit 9906971

Browse files
committed
Fix issues reported by PHPStan
PHPStan found a bug for subtitles (the language was not applied). Also applied PSR12 code styling.
1 parent 8c38695 commit 9906971

File tree

11 files changed

+45
-48
lines changed

11 files changed

+45
-48
lines changed

spec/XmlTv/XmlTvSpec.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ function it_generates_an_xml_file()
6767
$programme->premiere = new Tv\Elements\Premiere('Premiered on PHPTV');
6868
$programme->lastChance = new Tv\Elements\LastChance('Get it while it is hot!', 'en');
6969
$programme->new = new Tv\Elements\NewProgramme();
70-
$programme->addSubtitles(new Tv\Elements\Subtitles('en', Tv\Elements\Subtitles\Type::ONSCREEN));
70+
$subtitles = new Tv\Elements\Subtitles(Tv\Elements\Subtitles\Type::ONSCREEN);
71+
$subtitles->language = new Tv\Elements\Language('en');
72+
$programme->addSubtitles($subtitles);
7173
$rating = new Tv\Elements\Rating('Good');
7274
$rating->addIcon(new Tv\Elements\Icon('http://foo.bar/icon.png', '500', '400'));
7375
$programme->addRating($rating);

spec/epg.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
<premiere>Premiered on PHPTV</premiere>
4848
<last-chance lang="en">Get it while it is hot!</last-chance>
4949
<new/>
50-
<subtitles type="onscreen"/>
50+
<subtitles type="onscreen">
51+
<language>en</language>
52+
</subtitles>
5153
<rating>
5254
<value>Good</value>
5355
<icon src="http://foo.bar/icon.png" width="500" height="400"/>

src/Tv.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(string $date = '', string $sourceInfoUrl = '', strin
6161
/**
6262
* @param Channel $channel
6363
*/
64-
public function addChannel(Channel $channel)
64+
public function addChannel(Channel $channel): void
6565
{
6666
array_push($this->channel, $channel);
6767
}
@@ -77,7 +77,7 @@ public function getChannels(): array
7777
/**
7878
* @param Programme $programme
7979
*/
80-
public function addProgramme(Programme $programme)
80+
public function addProgramme(Programme $programme): void
8181
{
8282
array_push($this->programme, $programme);
8383
}

src/Tv/Channel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(string $id)
4545
*
4646
* @param DisplayName $displayName
4747
*/
48-
public function addDisplayName(DisplayName $displayName)
48+
public function addDisplayName(DisplayName $displayName): void
4949
{
5050
array_push($this->displayName, $displayName);
5151
}
@@ -65,7 +65,7 @@ public function getDisplayName(): array
6565
*
6666
* @param Icon $icon
6767
*/
68-
public function addIcon(Icon $icon)
68+
public function addIcon(Icon $icon): void
6969
{
7070
array_push($this->icon, $icon);
7171
}
@@ -75,7 +75,7 @@ public function addIcon(Icon $icon)
7575
*
7676
* @param Url $url
7777
*/
78-
public function addUrl(Url $url)
78+
public function addUrl(Url $url): void
7979
{
8080
array_push($this->url, $url);
8181
}

src/Tv/Elements/Length.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Length implements XmlSerializable
1919

2020
/**
2121
* Length constructor.
22+
*
2223
* @param string $value
2324
* @param string $units Use one of the constants defined in `Tv\Elements\Length\Unit`.
2425
*/

src/Tv/Elements/PreviouslyShown.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ class PreviouslyShown implements XmlSerializable
1717
*/
1818
public $channel;
1919

20-
/**
21-
* PreviouslyShown constructor.
22-
*
23-
* @param string $start
24-
* @param string $channel
25-
*/
2620
public function __construct(string $start = '', string $channel = '')
2721
{
2822
$this->start = $start;

src/Tv/Elements/Rating.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ class Rating implements XmlSerializable
2222
*/
2323
private $icon = [];
2424

25-
/**
26-
* Length constructor.
27-
*
28-
* @param string $value
29-
* @param string $system
30-
*/
3125
public function __construct(string $value, string $system = '')
3226
{
3327
$this->value = $value;
3428
$this->system = $system;
3529
}
3630

37-
public function addIcon(Icon $icon)
31+
/**
32+
* @param Icon $icon
33+
*/
34+
public function addIcon(Icon $icon): void
3835
{
3936
array_push($this->icon, $icon);
4037
}
4138

39+
/**
40+
* @return Icon[]
41+
*/
4242
public function getIcon(): array
4343
{
4444
return $this->icon;

src/Tv/Elements/Subtitles.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@
88
class Subtitles implements XmlSerializable
99
{
1010
/**
11-
* @var Language
11+
* @var string
1212
*/
13-
public $language;
13+
public $type;
1414

1515
/**
16-
* @var string
16+
* @var Language|null
1717
*/
18-
public $type;
18+
public $language;
1919

2020
/**
2121
* Subtitles constructor.
2222
*
23-
* @param string $language
2423
* @param string $type Legal values are `teletext`, `onscreen` or `deaf-signed`.
2524
*/
26-
public function __construct(string $language = '', string $type = '')
25+
public function __construct(string $type = '')
2726
{
28-
$this->language = $language;
2927
$this->type = $type;
3028
}
3129

src/Tv/Programme.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function __construct(
228228
*
229229
* @param Title $title
230230
*/
231-
public function addTitle(Title $title)
231+
public function addTitle(Title $title): void
232232
{
233233
array_push($this->title, $title);
234234
}
@@ -248,7 +248,7 @@ public function getTitle(): array
248248
*
249249
* @param SubTitle $subTitle
250250
*/
251-
public function addSubTitle(SubTitle $subTitle)
251+
public function addSubTitle(SubTitle $subTitle): void
252252
{
253253
array_push($this->subTitle, $subTitle);
254254
}
@@ -268,7 +268,7 @@ public function getSubTitle(): array
268268
*
269269
* @param Desc $desc
270270
*/
271-
public function addDescription(Desc $desc)
271+
public function addDescription(Desc $desc): void
272272
{
273273
array_push($this->desc, $desc);
274274
}
@@ -288,7 +288,7 @@ public function getDescription(): array
288288
*
289289
* @param Credits $credits
290290
*/
291-
public function addCredits(Credits $credits)
291+
public function addCredits(Credits $credits): void
292292
{
293293
array_push($this->credits, $credits);
294294
}
@@ -308,7 +308,7 @@ public function getCredits(): array
308308
*
309309
* @param Category $category
310310
*/
311-
public function addCategory(Category $category)
311+
public function addCategory(Category $category): void
312312
{
313313
array_push($this->category, $category);
314314
}
@@ -328,7 +328,7 @@ public function getCategory(): array
328328
*
329329
* @param Keyword $keyword
330330
*/
331-
public function addKeyword(Keyword $keyword)
331+
public function addKeyword(Keyword $keyword): void
332332
{
333333
array_push($this->keyword, $keyword);
334334
}
@@ -348,7 +348,7 @@ public function getKeyword(): array
348348
*
349349
* @param Icon $icon
350350
*/
351-
public function addIcon(Icon $icon)
351+
public function addIcon(Icon $icon): void
352352
{
353353
array_push($this->icon, $icon);
354354
}
@@ -368,7 +368,7 @@ public function getIcon(): array
368368
*
369369
* @param Url $url
370370
*/
371-
public function addUrl(Url $url)
371+
public function addUrl(Url $url): void
372372
{
373373
array_push($this->url, $url);
374374
}
@@ -388,7 +388,7 @@ public function getUrl(): array
388388
*
389389
* @param Country $country
390390
*/
391-
public function addCountry(Country $country)
391+
public function addCountry(Country $country): void
392392
{
393393
array_push($this->country, $country);
394394
}
@@ -408,7 +408,7 @@ public function getCountry(): array
408408
*
409409
* @param EpisodeNum $episodeNum
410410
*/
411-
public function addEpisodeNum(EpisodeNum $episodeNum)
411+
public function addEpisodeNum(EpisodeNum $episodeNum): void
412412
{
413413
array_push($this->episodeNum, $episodeNum);
414414
}
@@ -428,7 +428,7 @@ public function getEpisodeNum(): array
428428
*
429429
* @param Subtitles $subtitles
430430
*/
431-
public function addSubtitles(Subtitles $subtitles)
431+
public function addSubtitles(Subtitles $subtitles): void
432432
{
433433
array_push($this->subtitles, $subtitles);
434434
}
@@ -448,7 +448,7 @@ public function getSubtitles(): array
448448
*
449449
* @param Rating $rating
450450
*/
451-
public function addRating(Rating $rating)
451+
public function addRating(Rating $rating): void
452452
{
453453
array_push($this->rating, $rating);
454454
}
@@ -467,7 +467,7 @@ public function getRating(): array
467467
*
468468
* @param StarRating $rating
469469
*/
470-
public function addStarRating(StarRating $rating)
470+
public function addStarRating(StarRating $rating): void
471471
{
472472
array_push($this->starRating, $rating);
473473
}
@@ -487,7 +487,7 @@ public function getStarRating(): array
487487
*
488488
* @param Review $review
489489
*/
490-
public function addReview(Review $review)
490+
public function addReview(Review $review): void
491491
{
492492
array_push($this->review, $review);
493493
}

src/XmlElement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class XmlElement implements XmlSerializable
1313
private $name;
1414

1515
/**
16-
* @var string
16+
* @var string|null
1717
*/
1818
private $value;
1919

@@ -37,8 +37,6 @@ public function __construct(string $name, string $value = null)
3737
{
3838
$this->name = $name;
3939
$this->value = $value;
40-
41-
return $this;
4240
}
4341

4442
/**

0 commit comments

Comments
 (0)