| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| 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 |
||
| 37 | public function testFillOut() |
||
| 38 | { |
||
| 39 | $zone = new Zone('example.com.'); |
||
| 40 | $zone->setDefaultTtl(3600); |
||
| 41 | |||
| 42 | $soa = new ResourceRecord(); |
||
| 43 | $soa->setName('@'); |
||
| 44 | $soa->setRdata(Factory::Soa( |
||
| 45 | '@', |
||
| 46 | 'post', |
||
| 47 | '2014110501', |
||
| 48 | 3600, |
||
| 49 | 14400, |
||
| 50 | 604800, |
||
| 51 | 3600 |
||
| 52 | )); |
||
| 53 | |||
| 54 | $soa->setClass(\Badcow\DNS\Classes::INTERNET); |
||
| 55 | |||
| 56 | $ns1 = new ResourceRecord(); |
||
| 57 | $ns1->setName('@'); |
||
| 58 | $ns1->setRdata(Factory::Ns('ns1.nameserver.com.')); |
||
| 59 | |||
| 60 | $ns2 = new ResourceRecord(); |
||
| 61 | $ns2->setName('@'); |
||
| 62 | $ns2->setRdata(Factory::Ns('ns2.nameserver.com.')); |
||
| 63 | |||
| 64 | $a = new ResourceRecord(); |
||
| 65 | $a->setName('sub.domain'); |
||
| 66 | $a->setRdata(Factory::A('192.168.1.42')); |
||
| 67 | $a->setComment('This is a local ip.'); |
||
| 68 | |||
| 69 | $a6 = new ResourceRecord(); |
||
| 70 | $a6->setName('ipv6.domain'); |
||
| 71 | $a6->setRdata(Factory::Aaaa('::1')); |
||
| 72 | $a6->setComment('This is an IPv6 domain.'); |
||
| 73 | |||
| 74 | $mx1 = new ResourceRecord(); |
||
| 75 | $mx1->setName('@'); |
||
| 76 | $mx1->setRdata(Factory::Mx(10, 'mail-gw1.example.net.')); |
||
| 77 | |||
| 78 | $mx2 = new ResourceRecord(); |
||
| 79 | $mx2->setName('@'); |
||
| 80 | $mx2->setRdata(Factory::Mx(20, 'mail-gw2.example.net.')); |
||
| 81 | |||
| 82 | $mx3 = new ResourceRecord(); |
||
| 83 | $mx3->setName('@'); |
||
| 84 | $mx3->setRdata(Factory::Mx(30, 'mail-gw3.example.net.')); |
||
| 85 | |||
| 86 | $loc = new ResourceRecord(); |
||
| 87 | $loc->setName('canberra'); |
||
| 88 | $loc->setRdata(Factory::Loc( |
||
| 89 | -35.3075, //Lat |
||
| 90 | 149.1244, //Lon |
||
| 91 | 500, //Alt |
||
| 92 | 20.12, //Size |
||
| 93 | 200.3, //HP |
||
| 94 | 300.1 //VP |
||
| 95 | )); |
||
| 96 | $loc->setComment('This is Canberra'); |
||
| 97 | |||
| 98 | $zone->fromList($loc, $mx2); |
||
| 99 | $zone->addResourceRecord($soa); |
||
| 100 | $zone->addResourceRecord($ns1); |
||
| 101 | $zone->addResourceRecord($mx3); |
||
| 102 | $zone->addResourceRecord($a); |
||
| 103 | $zone->addResourceRecord($a6); |
||
| 104 | $zone->addResourceRecord($ns2); |
||
| 105 | $zone->addResourceRecord($mx1); |
||
| 106 | |||
| 107 | $apl = new \Badcow\DNS\Rdata\APL(); |
||
| 108 | $apl->addAddressRange(\IPBlock::create('192.168.0.0/23')); |
||
| 109 | $apl->addAddressRange(\IPBlock::create('192.168.1.64/28'), false); |
||
| 110 | $apl->addAddressRange(\IPBlock::create('2001:acad:1::/112'), true); |
||
| 111 | $apl->addAddressRange(\IPBlock::create('2001:acad:1::8/128'), false); |
||
| 112 | |||
| 113 | $multicast = new ResourceRecord('multicast', $apl); |
||
| 114 | |||
| 115 | $zone->addResourceRecord($multicast); |
||
| 116 | |||
| 117 | ZoneBuilder::fillOutZone($zone); |
||
| 118 | $expectation = file_get_contents(__DIR__.'/Resources/example.com_filled-out.txt'); |
||
| 119 | |||
| 120 | $this->assertEquals($expectation, AlignedBuilder::build($zone)); |
||
| 121 | } |
||
| 122 | |||
| 151 |