| Conditions | 3 |
| Paths | 4 |
| Total Lines | 101 |
| Code Lines | 77 |
| 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 |
||
| 95 | public function testDocumentTranslation() |
||
| 96 | { |
||
| 97 | $doc = new DOMDocument('1.0'); |
||
| 98 | $doc->load(__DIR__ . '/xml/test1.xml'); |
||
| 99 | |||
| 100 | $translator = new Translator(); |
||
| 101 | $envelope = $translator->translateDocument($doc); |
||
| 102 | |||
| 103 | $this->assertEquals('soap-env', $envelope->getName()); |
||
| 104 | $this->assertCount(2, $envelope->getElements()); |
||
| 105 | |||
| 106 | $child1 = $envelope->getElements()[0]; |
||
| 107 | $child2 = $envelope->getElements()[1]; |
||
| 108 | |||
| 109 | $this->assertInstanceOf(XmlNode::class, $child1); |
||
| 110 | $this->assertInstanceOf(XmlNode::class, $child2); |
||
| 111 | |||
| 112 | $this->assertEquals('person', $child1->getName()); |
||
| 113 | $this->assertTrue($child1->hasElements()); |
||
| 114 | $this->assertCount(4, $child1->getElements()); |
||
| 115 | $this->assertTrue($child1->hasAttributes()); |
||
| 116 | $this->assertCount(1, $child1->getAttributes()); |
||
| 117 | |||
| 118 | $this->assertEquals('name', $child1->getAttributes()[0]->getName()); |
||
| 119 | $this->assertEquals('Max Musterman', $child1->getAttributes()[0]->getValue()); |
||
| 120 | |||
| 121 | $this->assertInstanceOf(XmlElement::class, $child1->getElements()[0]); |
||
| 122 | $this->assertEquals('car', $child1->getElements()[0]->getName()); |
||
| 123 | $this->assertFalse($child1->getElements()[0]->hasValue()); |
||
| 124 | $this->assertCount(2, $child1->getElements()[0]->getAttributes()); |
||
| 125 | $this->assertEquals('marke', $child1->getElements()[0]->getAttributes()[0]->getName()); |
||
| 126 | $this->assertEquals('BMW', $child1->getElements()[0]->getAttributes()[0]->getValue()); |
||
| 127 | |||
| 128 | $this->assertInstanceOf(XmlElement::class, $child1->getElements()[1]); |
||
| 129 | $this->assertEquals('phone', $child1->getElements()[1]->getName()); |
||
| 130 | $this->assertEquals(9, $child1->getElements()[1]->getValue()); |
||
| 131 | $this->assertCount(1, $child1->getElements()[1]->getAttributes()); |
||
| 132 | $this->assertEquals('name', $child1->getElements()[1]->getAttributes()[0]->getName()); |
||
| 133 | $this->assertEquals('iPhone', $child1->getElements()[1]->getAttributes()[0]->getValue()); |
||
| 134 | |||
| 135 | $this->assertInstanceOf(XmlElement::class, $child1->getElements()[2]); |
||
| 136 | $this->assertEquals('birth-place', $child1->getElements()[2]->getName()); |
||
| 137 | $this->assertEquals('Hamburg', $child1->getElements()[2]->getValue()); |
||
| 138 | $this->assertFalse($child1->getElements()[2]->hasAttributes()); |
||
| 139 | |||
| 140 | $this->assertInstanceOf(XmlNode::class, $child1->getElements()[3]); |
||
| 141 | $this->assertEquals('address', $child1->getElements()[3]->getName()); |
||
| 142 | $this->assertFalse($child1->getElements()[3]->hasValue()); |
||
| 143 | $this->assertFalse($child1->getElements()[3]->hasAttributes()); |
||
| 144 | $this->assertCount(2, $child1->getElements()[3]->getElements()); |
||
| 145 | |||
| 146 | $i = 0; |
||
| 147 | foreach (['street' => 'Hauptstraße 1', 'plz' => '245698'] as $name => $value) { |
||
| 148 | $this->assertEquals($name, $child1->getElements()[3]->getElements()[$i]->getName()); |
||
| 149 | $this->assertEquals($value, $child1->getElements()[3]->getElements()[$i]->getValue()); |
||
| 150 | |||
| 151 | $i++; |
||
| 152 | } |
||
| 153 | |||
| 154 | $this->assertEquals('person', $child2->getName()); |
||
| 155 | $this->assertTrue($child2->hasAttributes()); |
||
| 156 | $this->assertCount(1, $child2->getAttributes()); |
||
| 157 | $this->assertTrue($child2->hasElements()); |
||
| 158 | $this->assertCount(4, $child2->getElements()); |
||
| 159 | |||
| 160 | $this->assertEquals('name', $child2->getAttributes()[0]->getName()); |
||
| 161 | $this->assertEquals('Dr. Dolittle', $child2->getAttributes()[0]->getValue()); |
||
| 162 | |||
| 163 | $this->assertInstanceOf(XmlElement::class, $child2->getElements()[0]); |
||
| 164 | $this->assertEquals('car', $child2->getElements()[0]->getName()); |
||
| 165 | $this->assertFalse($child2->getElements()[0]->hasValue()); |
||
| 166 | $this->assertCount(2, $child2->getElements()[0]->getAttributes()); |
||
| 167 | $this->assertEquals('marke', $child2->getElements()[0]->getAttributes()[0]->getName()); |
||
| 168 | $this->assertEquals('Audi', $child2->getElements()[0]->getAttributes()[0]->getValue()); |
||
| 169 | |||
| 170 | $this->assertInstanceOf(XmlElement::class, $child2->getElements()[1]); |
||
| 171 | $this->assertEquals('phone', $child2->getElements()[1]->getName()); |
||
| 172 | $this->assertEquals('Xperia Z3', $child2->getElements()[1]->getValue()); |
||
| 173 | $this->assertCount(1, $child2->getElements()[1]->getAttributes()); |
||
| 174 | $this->assertEquals('name', $child2->getElements()[1]->getAttributes()[0]->getName()); |
||
| 175 | $this->assertEquals('Sony', $child2->getElements()[1]->getAttributes()[0]->getValue()); |
||
| 176 | |||
| 177 | $this->assertInstanceOf(XmlElement::class, $child2->getElements()[2]); |
||
| 178 | $this->assertEquals('birth-place', $child2->getElements()[2]->getName()); |
||
| 179 | $this->assertEquals('München', $child2->getElements()[2]->getValue()); |
||
| 180 | $this->assertFalse($child2->getElements()[2]->hasAttributes()); |
||
| 181 | |||
| 182 | $this->assertInstanceOf(XmlNode::class, $child2->getElements()[3]); |
||
| 183 | $this->assertEquals('address', $child2->getElements()[3]->getName()); |
||
| 184 | $this->assertFalse($child2->getElements()[3]->hasValue()); |
||
| 185 | $this->assertFalse($child2->getElements()[3]->hasAttributes()); |
||
| 186 | $this->assertCount(2, $child2->getElements()[3]->getElements()); |
||
| 187 | |||
| 188 | $i = 0; |
||
| 189 | foreach (['street' => 'Partkstraße', 'plz' => '365494'] as $name => $value) { |
||
| 190 | $this->assertEquals($name, $child2->getElements()[3]->getElements()[$i]->getName()); |
||
| 191 | $this->assertEquals($value, $child2->getElements()[3]->getElements()[$i]->getValue()); |
||
| 192 | |||
| 193 | $i++; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | } |