| Conditions | 3 |
| Paths | 4 |
| Total Lines | 56 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 22 | public function testRead() |
||
| 23 | { |
||
| 24 | $content = DummyM3u8Factory::createMediaPlaylistContent(2); |
||
| 25 | |||
| 26 | $parser = new Parser(new PlaylistBuilder(new PlaylistComponentFactory())); |
||
| 27 | foreach (explode("\n", $content) as $line) { |
||
| 28 | $parser->parseLine($line); |
||
| 29 | } |
||
| 30 | |||
| 31 | $playlist = $parser->getPlaylist(); |
||
| 32 | $this->assertEquals(2, $playlist->getVersion()); |
||
| 33 | $this->assertEquals(12, $playlist->getTargetduration()); |
||
| 34 | $this->assertEquals(33, $playlist->getMediaSequence()); |
||
| 35 | $this->assertEquals(3, $playlist->getDiscontinuitySequence()); |
||
| 36 | |||
| 37 | $segment = $playlist->getSegments()->offsetGet(0); |
||
| 38 | $this->assertEquals('AES-128', $segment->getKeys()[0]->getMethod()); |
||
| 39 | $this->assertEquals('com.apple', $segment->getKeys()[1]->getKeyformat()); |
||
| 40 | $this->assertEquals('1', $segment->getKeys()[1]->getKeyformatversions()); |
||
| 41 | $this->assertEquals(12, $segment->getInf()->getDuration()); |
||
| 42 | $this->assertEquals('hello world', $segment->getInf()->getTitle()); |
||
| 43 | $this->assertEquals('stream33.ts', $segment->getUri()); |
||
| 44 | $this->assertEquals(10000, $segment->getByterange()->getLength()); |
||
| 45 | $this->assertEquals(100, $segment->getByterange()->getOffset()); |
||
| 46 | $this->assertFalse($segment->isDiscontinuity()); |
||
| 47 | |||
| 48 | $segment = $playlist->getSegments()->offsetGet(1); |
||
| 49 | $this->assertEquals(10, $segment->getInf()->getDuration()); |
||
| 50 | $this->assertEquals('video01.ts', $segment->getUri()); |
||
| 51 | $this->assertTrue($segment->isDiscontinuity()); |
||
| 52 | |||
| 53 | $this->assertEquals(22, $playlist->getDuration()); |
||
| 54 | |||
| 55 | $content = DummyM3u8Factory::createMasterPlaylistContent(); |
||
| 56 | $parser = new Parser(new PlaylistBuilder(new PlaylistComponentFactory())); |
||
| 57 | foreach (explode("\n", $content) as $line) { |
||
| 58 | $parser->parseLine($line); |
||
| 59 | } |
||
| 60 | |||
| 61 | $playlist = $parser->getPlaylist(); |
||
| 62 | $this->assertEquals(true, $playlist->isIndependentSegments()); |
||
| 63 | $this->assertEquals(1.1, $playlist->getStart()->getTimeOffset()); |
||
| 64 | $this->assertEquals('YES', $playlist->getStart()->getPrecise()); |
||
| 65 | $this->assertEquals('AUDIO', $playlist->getMedias()[0]->getType()); |
||
| 66 | $this->assertEquals('media.uri', $playlist->getMedias()[0]->getUri()); |
||
| 67 | $this->assertEquals('group', $playlist->getMedias()[0]->getGroupId()); |
||
| 68 | $this->assertEquals('zh-Hans', $playlist->getMedias()[0]->getLanguage()); |
||
| 69 | $this->assertEquals('zh-Hans', $playlist->getMedias()[0]->getAssocLanguage()); |
||
| 70 | $this->assertEquals('name', $playlist->getMedias()[0]->getName()); |
||
| 71 | $this->assertEquals('YES', $playlist->getMedias()[0]->getDefault()); |
||
| 72 | $this->assertEquals('YES', $playlist->getMedias()[0]->getAutoselect()); |
||
| 73 | $this->assertEquals('NO', $playlist->getMedias()[0]->getForced()); |
||
| 74 | $this->assertEquals('CC1', $playlist->getMedias()[0]->getInstreamId()); |
||
| 75 | $this->assertEquals('public.easy-to-read', $playlist->getMedias()[0]->getCharacteristics()); |
||
| 76 | $this->assertEquals('6', $playlist->getMedias()[0]->getChannels()); |
||
| 77 | } |
||
| 78 | |||
| 88 |