chrisyue /
php-m3u8
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Chrisyue\PhpM3u8\Stream; |
||
| 4 | |||
| 5 | abstract class AbstractStream implements StreamInterface |
||
| 6 | { |
||
| 7 | public function read() |
||
| 8 | { |
||
| 9 | static $line; |
||
| 10 | static $lineInfo; |
||
| 11 | if ($this->getLine() !== $line) { |
||
| 12 | $line = $this->getLine(); |
||
| 13 | $lineInfo = $this->getLineInfo($line); |
||
| 14 | } |
||
| 15 | |||
| 16 | return $lineInfo; |
||
| 17 | } |
||
| 18 | |||
| 19 | public function write(array $lineInfo) |
||
| 20 | { |
||
| 21 | if (empty($lineInfo['tag'])) { |
||
| 22 | $this->putLine($lineInfo['value']); |
||
| 23 | |||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | if (empty($lineInfo['value'])) { |
||
| 28 | $this->putLine($lineInfo['tag']); |
||
| 29 | |||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | $this->putLine(sprintf('%s:%s', $lineInfo['tag'], $lineInfo['value'])); |
||
| 34 | } |
||
| 35 | |||
| 36 | abstract protected function getLine(); |
||
| 37 | |||
| 38 | abstract protected function putLine($line); |
||
| 39 | |||
| 40 | View Code Duplication | private function getLineInfo($line) |
|
|
0 ignored issues
–
show
|
|||
| 41 | { |
||
| 42 | $line = trim($line); |
||
| 43 | if (empty($line)) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | if ('#' !== $line[0]) { |
||
| 48 | return ['value' => $line]; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (strlen($line) < 2) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | list($tag, $value) = array_pad(explode(':', $line, 2), 2, ''); |
||
| 56 | |||
| 57 | return compact('tag', 'value'); |
||
| 58 | } |
||
| 59 | } |
||
| 60 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.