Conditions | 1 |
Paths | 1 |
Total Lines | 72 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
49 | public function testParse() |
||
50 | { |
||
51 | $document = $this->getDocumentInstance(); |
||
52 | |||
53 | // Only_values = false. |
||
54 | $content = '/NameType /FlateDecode |
||
55 | /Contents[4 0 R 42]/Fonts<</F1 41/F2 43>>/NullType |
||
56 | null/StringType(hello)/DateType(D:20130901235555+02\'00\')/XRefType 2 0 R |
||
57 | /NumericType 8/HexaType<0020>/BooleanType false'; |
||
58 | $offset = 0; |
||
59 | |||
60 | $elements = Element::parse($content, $document, $offset, false); |
||
61 | |||
62 | $this->assertTrue(\array_key_exists('NameType', $elements)); |
||
63 | $this->assertTrue($elements['NameType'] instanceof ElementName); |
||
64 | $this->assertEquals('FlateDecode', $elements['NameType']->getContent()); |
||
65 | |||
66 | $this->assertTrue(\array_key_exists('Contents', $elements)); |
||
67 | $this->assertTrue($elements['Contents'] instanceof ElementArray); |
||
68 | $this->assertTrue($elements['Contents']->contains(42)); |
||
69 | |||
70 | $this->assertTrue(\array_key_exists('Fonts', $elements)); |
||
71 | $this->assertTrue($elements['Fonts'] instanceof Header); |
||
72 | |||
73 | $this->assertTrue(\array_key_exists('NullType', $elements)); |
||
74 | $this->assertTrue($elements['NullType'] instanceof ElementNull); |
||
75 | $this->assertEquals('null', (string) $elements['NullType']); |
||
76 | |||
77 | $this->assertTrue(\array_key_exists('StringType', $elements)); |
||
78 | $this->assertTrue($elements['StringType'] instanceof ElementString); |
||
79 | $this->assertEquals('hello', $elements['StringType']->getContent()); |
||
80 | |||
81 | $this->assertTrue(\array_key_exists('DateType', $elements)); |
||
82 | $this->assertTrue($elements['DateType'] instanceof ElementDate); |
||
83 | |||
84 | $this->assertTrue(\array_key_exists('XRefType', $elements)); |
||
85 | $this->assertTrue($elements['XRefType'] instanceof ElementXRef); |
||
86 | $this->assertEquals('2_0', $elements['XRefType']->getId()); |
||
87 | |||
88 | $this->assertTrue(\array_key_exists('NumericType', $elements)); |
||
89 | $this->assertTrue($elements['NumericType'] instanceof ElementNumeric); |
||
90 | $this->assertEquals('8', (string) $elements['NumericType']); |
||
91 | |||
92 | $this->assertTrue(\array_key_exists('HexaType', $elements)); |
||
93 | $this->assertTrue($elements['HexaType'] instanceof ElementString); |
||
94 | $this->assertEquals(' ', (string) $elements['HexaType']); |
||
95 | |||
96 | $this->assertTrue(\array_key_exists('BooleanType', $elements)); |
||
97 | $this->assertTrue($elements['BooleanType'] instanceof ElementBoolean); |
||
98 | $this->assertFalse($elements['BooleanType']->getContent()); |
||
99 | |||
100 | // Only_values = true. |
||
101 | $content = '/NameType /FlateDecode'; |
||
102 | $offset = 0; |
||
103 | $elements = Element::parse($content, $document, $offset, true); |
||
104 | $this->assertEquals(2, \count($elements)); |
||
105 | $this->assertEquals(22, $offset); |
||
106 | |||
107 | // Test error. |
||
108 | $content = '/NameType /FlateDecode $$$'; |
||
109 | $offset = 0; |
||
110 | $elements = Element::parse($content, $document, $offset, false); |
||
111 | $this->assertEquals(1, \count($elements)); |
||
112 | $this->assertEquals(22, $offset); |
||
113 | $this->assertEquals('NameType', key($elements)); |
||
114 | $this->assertTrue(current($elements) instanceof ElementName); |
||
115 | |||
116 | $content = '/NameType $$$'; |
||
117 | $offset = 0; |
||
118 | $elements = Element::parse($content, $document, $offset, false); |
||
119 | $this->assertEquals(0, $offset); |
||
120 | $this->assertEquals(0, \count($elements)); |
||
121 | } |
||
153 |