| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| 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 |
||
| 111 | public function testCompareResourceRecords(): void |
||
| 112 | { |
||
| 113 | $soa = new ResourceRecord(); |
||
| 114 | $soa->setClass('IN'); |
||
| 115 | $soa->setName('@'); |
||
| 116 | $soa->setRdata(Factory::SOA( |
||
| 117 | 'example.com.', |
||
| 118 | 'postmaster.example.com.', |
||
| 119 | 2015050801, |
||
| 120 | 3600, |
||
| 121 | 14400, |
||
| 122 | 604800, |
||
| 123 | 3600 |
||
| 124 | )); |
||
| 125 | |||
| 126 | $ns1 = new ResourceRecord(); |
||
| 127 | $ns1->setClass(Classes::INTERNET); |
||
| 128 | $ns1->setName('@'); |
||
| 129 | $ns1->setTtl(14400); |
||
| 130 | $ns1->setRdata(Factory::NS('ns1.example.net.au.')); |
||
| 131 | |||
| 132 | $ns2 = new ResourceRecord(); |
||
| 133 | $ns2->setClass('IN'); |
||
| 134 | $ns2->setName('@'); |
||
| 135 | $ns2->setTtl(14400); |
||
| 136 | $ns2->setRdata(Factory::NS('ns2.example.net.au.')); |
||
| 137 | |||
| 138 | $a = new ResourceRecord(); |
||
| 139 | $a->setName('subdomain.au'); |
||
| 140 | $a->setRdata(Factory::A('192.168.1.2')); |
||
| 141 | $a->setComment('This is a local ip.'); |
||
| 142 | |||
| 143 | $cname = new ResourceRecord(); |
||
| 144 | $cname->setName('alias'); |
||
| 145 | $cname->setRdata(Factory::CNAME('subdomain.au.example.com.')); |
||
| 146 | $cname->setClass(Classes::INTERNET); |
||
| 147 | |||
| 148 | $aaaa = ResourceRecord::create('ipv6domain', Factory::AAAA('::1'), 3600); |
||
| 149 | |||
| 150 | $mx1 = new ResourceRecord(); |
||
| 151 | $mx1->setName('@'); |
||
| 152 | $mx1->setRdata(Factory::MX(10, 'mailgw01.example.net.')); |
||
| 153 | |||
| 154 | $mx2 = new ResourceRecord(); |
||
| 155 | $mx2->setName('@'); |
||
| 156 | $mx2->setRdata(Factory::MX(20, 'mailgw02.example.net.')); |
||
| 157 | |||
| 158 | $txt = new ResourceRecord(); |
||
| 159 | $txt->setName('example.net.'); |
||
| 160 | $txt->setRdata(Factory::TXT('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all')); |
||
| 161 | |||
| 162 | $spf = new ResourceRecord(); |
||
| 163 | $spf->setName('example.com.'); |
||
| 164 | $spf->setRdata(Factory::SPF('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all')); |
||
| 165 | |||
| 166 | $rrsig = new ResourceRecord(); |
||
| 167 | $rrsig->setName('example.com.'); |
||
| 168 | $rrsig->setRdata(Factory::RRSIG( |
||
| 169 | 'A', |
||
| 170 | 14, |
||
| 171 | 2, |
||
| 172 | 3600, |
||
| 173 | new \DateTime('2070-01-01 00:00:00'), |
||
| 174 | new \DateTime('1970-01-01 00:00:00'), |
||
| 175 | 65535, |
||
| 176 | 'example.com.', |
||
| 177 | 'aaaaaaaaaaaaaaaaaaaaaaaaa' |
||
| 178 | )); |
||
| 179 | |||
| 180 | $nsec3 = new ResourceRecord(); |
||
| 181 | $nsec3->setName('example.com.'); |
||
| 182 | $nsec3->setRdata(Factory::NSEC3PARAM(1, 0, 5, '9474017E')); |
||
| 183 | |||
| 184 | $rp = new ResourceRecord(); |
||
| 185 | $rp->setRdata(Factory::RP('mail.example.com.', 'example.com.')); |
||
| 186 | |||
| 187 | $spf = new ResourceRecord(); |
||
| 188 | $spf->setRdata(Factory::SPF('skjdfskjasdfjh')); |
||
| 189 | |||
| 190 | $alignedBuilder = new AlignedBuilder(); |
||
| 191 | |||
| 192 | $this->assertTrue($alignedBuilder->compareResourceRecords($soa, $ns1) < 0); |
||
| 193 | $this->assertTrue($alignedBuilder->compareResourceRecords($aaaa, $cname) < 0); |
||
| 194 | $this->assertTrue($alignedBuilder->compareResourceRecords($mx1, $mx2) < 0); |
||
| 195 | $this->assertTrue($alignedBuilder->compareResourceRecords($mx1, $mx2) < 0); |
||
| 196 | $this->assertTrue($alignedBuilder->compareResourceRecords($mx1, $spf) < 0); |
||
| 197 | |||
| 198 | $this->assertTrue($alignedBuilder->compareResourceRecords($mx1, $a) > 0); |
||
| 199 | $this->assertTrue($alignedBuilder->compareResourceRecords($ns2, $ns1) > 0); |
||
| 200 | $this->assertTrue($alignedBuilder->compareResourceRecords($spf, $txt) > 0); |
||
| 201 | |||
| 202 | $this->assertTrue($alignedBuilder->compareResourceRecords($nsec3, $rrsig) < 0); |
||
| 203 | $this->assertTrue($alignedBuilder->compareResourceRecords($rrsig, $nsec3) > 0); |
||
| 204 | |||
| 205 | $this->assertTrue($alignedBuilder->compareResourceRecords($rp, $spf) < 0); |
||
| 206 | } |
||
| 207 | |||
| 227 |