Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 42 |
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 | /** @var TestRoot $root */ |
||
46 | $root = $hydrator->hydrateDocument($doc); |
||
47 | |||
48 | $this->assertNotNull($root); |
||
49 | $this->assertInstanceOf(TestRoot::class, $root); |
||
50 | |||
51 | /** @var TestPerson[] $persons */ |
||
52 | $persons = $root->getPersons(); |
||
53 | $this->assertCount(2, $persons); |
||
54 | |||
55 | $this->assertInstanceOf(TestPerson::class, $persons[0]); |
||
56 | $this->assertEquals('Max Musterman', $persons[0]->getName()); |
||
57 | $this->assertInstanceOf(TestCar::class, $persons[0]->getCar()); |
||
58 | $this->assertEquals('BMW', $persons[0]->getCar()->getMarke()); |
||
59 | $this->assertNotEmpty($persons[0]->getCar()->kennung); |
||
60 | $this->assertEquals('i8', $persons[0]->getCar()->kennung); |
||
61 | $this->assertInstanceOf(TestPhone::class, $persons[0]->getPhone()); |
||
62 | $this->assertEquals('iPhone', $persons[0]->getPhone()->getName()); |
||
63 | $this->assertEquals(9, $persons[0]->getPhone()->getValue()); |
||
64 | $this->assertEquals('Hamburg', $persons[0]->getBirthplace()); |
||
65 | $this->assertInstanceOf(TestAddress::class, $persons[0]->getAddress()); |
||
66 | $this->assertEquals('Hauptstraße 1', $persons[0]->getAddress()->getStreet()); |
||
67 | $this->assertEquals(245698, $persons[0]->getAddress()->getPlz()); |
||
68 | |||
69 | $this->assertInstanceOf(TestPerson::class, $persons[1]); |
||
70 | $this->assertEquals('Dr. Dolittle', $persons[1]->getName()); |
||
71 | $this->assertInstanceOf(TestCar::class, $persons[1]->getCar()); |
||
72 | $this->assertEquals('Audi', $persons[1]->getCar()->getMarke()); |
||
73 | $this->assertNotEmpty($persons[0]->getCar()->kennung); |
||
74 | $this->assertEquals('A3', $persons[1]->getCar()->kennung); |
||
75 | $this->assertInstanceOf(TestPhone::class, $persons[1]->getPhone()); |
||
76 | $this->assertEquals('Sony', $persons[1]->getPhone()->getName()); |
||
77 | $this->assertEquals('Xperia Z3', $persons[1]->getPhone()->getValue()); |
||
78 | $this->assertEquals('München', $persons[1]->getBirthplace()); |
||
79 | $this->assertInstanceOf(TestAddress::class, $persons[1]->getAddress()); |
||
80 | $this->assertEquals('Partkstraße', $persons[1]->getAddress()->getStreet()); |
||
81 | $this->assertEquals(365494, $persons[1]->getAddress()->getPlz()); |
||
82 | } |
||
83 | |||
179 | } |