1 | <?php |
||
5 | class SegmentedExporter extends MediaExporter |
||
6 | { |
||
7 | protected $filter; |
||
8 | |||
9 | protected $playlistPath; |
||
10 | |||
11 | protected $segmentLength = 10; |
||
12 | |||
13 | protected $saveMethod = 'saveStream'; |
||
14 | |||
15 | public function setPlaylistPath(string $playlistPath): MediaExporter |
||
21 | |||
22 | public function setSegmentLength(int $segmentLength): MediaExporter |
||
28 | |||
29 | public function getFilter(): SegmentedFilter |
||
40 | |||
41 | public function saveStream(string $playlistPath): MediaExporter |
||
56 | |||
57 | private function getFullPathForFilename(string $filename) |
||
58 | { |
||
59 | return implode(DIRECTORY_SEPARATOR, [ |
||
60 | pathinfo($this->playlistPath, PATHINFO_DIRNAME), $filename, |
||
61 | ]); |
||
62 | } |
||
63 | |||
64 | public function getPlaylistFullPath(): string |
||
65 | { |
||
66 | return $this->getFullPathForFilename( |
||
67 | $this->getPlaylistFilename() |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | public function getSegmentFullPath(): string |
||
72 | { |
||
73 | return $this->getFullPathForFilename( |
||
74 | $this->getSegmentFilename() |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | public function getPlaylistName(): string |
||
82 | |||
83 | public function getPlaylistFilename(): string |
||
87 | |||
88 | public function getSegmentFilename(): string |
||
92 | |||
93 | protected function getFormattedFilename(string $suffix = ''): string |
||
101 | } |
||
102 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: