| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 44 |
| 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 |
||
| 28 | public function testObjects() |
||
| 29 | { |
||
| 30 | $doc = new DOMDocument(); |
||
| 31 | $doc->load(__DIR__ . '/xml/test1.xml'); |
||
| 32 | |||
| 33 | $mapper = new ClassMapper( |
||
| 34 | [ |
||
| 35 | 'Root' => TestRoot::class, |
||
| 36 | 'Person' => TestPerson::class, |
||
| 37 | 'Car' => TestCar::class, |
||
| 38 | 'Phone' => TestPhone::class, |
||
| 39 | 'Address' => TestAddress::class |
||
| 40 | ] |
||
| 41 | ); |
||
| 42 | $mapper->appendPattern('/^(?:soap\-?)?env(?:elope)?/iS', 'Root'); |
||
| 43 | |||
| 44 | $hydrator = new Hydrator($mapper); |
||
| 45 | $objects = $hydrator->hydrateDocument($doc); |
||
| 46 | |||
| 47 | $this->assertCount(1, $objects); |
||
| 48 | |||
| 49 | /** @var TestRoot $root */ |
||
| 50 | $root = $objects[0]; |
||
| 51 | |||
| 52 | $this->assertNotNull($root); |
||
| 53 | $this->assertInstanceOf(TestRoot::class, $root); |
||
| 54 | |||
| 55 | $persons = $root->getPersons(); |
||
| 56 | $this->assertCount(2, $persons); |
||
| 57 | |||
| 58 | $this->assertInstanceOf(TestPerson::class, $persons[0]); |
||
| 59 | $this->assertEquals('Max Musterman', $persons[0]->getName()); |
||
| 60 | $this->assertInstanceOf(TestCar::class, $persons[0]->getCar()); |
||
| 61 | $this->assertEquals('BMW', $persons[0]->getCar()->getMarke()); |
||
| 62 | $this->assertNotEmpty($persons[0]->getCar()->kennung); |
||
| 63 | $this->assertEquals('i8', $persons[0]->getCar()->kennung); |
||
| 64 | $this->assertInstanceOf(TestPhone::class, $persons[0]->getPhone()); |
||
| 65 | $this->assertEquals('iPhone', $persons[0]->getPhone()->getName()); |
||
| 66 | $this->assertEquals(9, $persons[0]->getPhone()->getValue()); |
||
| 67 | $this->assertEquals('Hamburg', $persons[0]->getBirthplace()); |
||
| 68 | $this->assertInstanceOf(TestAddress::class, $persons[0]->getAddress()); |
||
| 69 | $this->assertEquals('Hauptstraße 1', $persons[0]->getAddress()->getStreet()); |
||
| 70 | $this->assertEquals(245698, $persons[0]->getAddress()->getPlz()); |
||
| 71 | |||
| 72 | $this->assertInstanceOf(TestPerson::class, $persons[1]); |
||
| 73 | $this->assertEquals('Dr. Dolittle', $persons[1]->getName()); |
||
| 74 | $this->assertInstanceOf(TestCar::class, $persons[1]->getCar()); |
||
| 75 | $this->assertEquals('Audi', $persons[1]->getCar()->getMarke()); |
||
| 76 | $this->assertNotEmpty($persons[0]->getCar()->kennung); |
||
| 77 | $this->assertEquals('A3', $persons[1]->getCar()->kennung); |
||
| 78 | $this->assertInstanceOf(TestPhone::class, $persons[1]->getPhone()); |
||
| 79 | $this->assertEquals('Sony', $persons[1]->getPhone()->getName()); |
||
| 80 | $this->assertEquals('Xperia Z3', $persons[1]->getPhone()->getValue()); |
||
| 81 | $this->assertEquals('München', $persons[1]->getBirthplace()); |
||
| 82 | $this->assertInstanceOf(TestAddress::class, $persons[1]->getAddress()); |
||
| 83 | $this->assertEquals('Partkstraße', $persons[1]->getAddress()->getStreet()); |
||
| 84 | $this->assertEquals(365494, $persons[1]->getAddress()->getPlz()); |
||
| 85 | } |
||
| 86 | |||
| 219 | } |