Completed
Push — master ( ecf71f...65af6f )
by Sam
09:47
created
tests/Resolver/JsonResolverTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@
 block discarded – undo
23 23
     public function setUp()
24 24
     {
25 25
         $files = [
26
-            __DIR__.'/../Resources/example.com.json',
27
-            __DIR__.'/../Resources/test_records.json',
26
+            __DIR__ . '/../Resources/example.com.json',
27
+            __DIR__ . '/../Resources/test_records.json',
28 28
         ];
29 29
         $this->resolver = new JsonResolver($files, 300);
30 30
     }
Please login to merge, or discard this patch.
src/Encoder.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
     public static function encodeMessage(Message $message): string
24 24
     {
25 25
         return
26
-            self::encodeHeader($message->getHeader()).
27
-            self::encodeResourceRecords($message->getQuestions()).
28
-            self::encodeResourceRecords($message->getAnswers()).
29
-            self::encodeResourceRecords($message->getAuthoritatives()).
26
+            self::encodeHeader($message->getHeader()) .
27
+            self::encodeResourceRecords($message->getQuestions()) .
28
+            self::encodeResourceRecords($message->getAnswers()) .
29
+            self::encodeResourceRecords($message->getAuthoritatives()) .
30 30
             self::encodeResourceRecords($message->getAdditionals());
31 31
     }
32 32
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
             return chr(0);
44 44
         }
45 45
 
46
-        $domain = rtrim($domain, '.').'.';
46
+        $domain = rtrim($domain, '.') . '.';
47 47
         $res = '';
48 48
 
49 49
         foreach (explode('.', $domain) as $label) {
50
-            $res .= chr(strlen($label)).$label;
50
+            $res .= chr(strlen($label)) . $label;
51 51
         }
52 52
 
53 53
         return $res;
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
     {
79 79
         $encoded = self::encodeDomainName($rr->getName());
80 80
         if ($rr->isQuestion()) {
81
-            return $encoded.pack('nn', $rr->getType(), $rr->getClass());
81
+            return $encoded . pack('nn', $rr->getType(), $rr->getClass());
82 82
         }
83 83
 
84 84
         $data = RdataEncoder::encodeRdata($rr->getType(), $rr->getRdata());
85 85
         $encoded .= pack('nnNn', $rr->getType(), $rr->getClass(), $rr->getTtl(), strlen($data));
86 86
 
87
-        return $encoded.$data;
87
+        return $encoded . $data;
88 88
     }
89 89
 
90 90
     /**
Please login to merge, or discard this patch.
src/Event/Subscriber/EchoLogger.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,19 +44,19 @@
 block discarded – undo
44 44
     public function onQueryReceive(QueryReceiveEvent $event): void
45 45
     {
46 46
         foreach ($event->getMessage()->getQuestions() as $question) {
47
-            $this->log(LogLevel::INFO, 'Query: '.$question);
47
+            $this->log(LogLevel::INFO, 'Query: ' . $question);
48 48
         }
49 49
     }
50 50
 
51 51
     public function onQueryResponse(QueryResponseEvent $event): void
52 52
     {
53 53
         foreach ($event->getMessage()->getAnswers() as $answer) {
54
-            $this->log(LogLevel::INFO, 'Answer: '.$answer);
54
+            $this->log(LogLevel::INFO, 'Answer: ' . $answer);
55 55
         }
56 56
     }
57 57
 
58 58
     public function log($level, $message, array $context = [])
59 59
     {
60
-        echo sprintf('[%s] %s: %s'.PHP_EOL, date('c'), $level, $message);
60
+        echo sprintf('[%s] %s: %s' . PHP_EOL, date('c'), $level, $message);
61 61
     }
62 62
 }
Please login to merge, or discard this patch.
tests/EncoderTest.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
     public function testEncodeDomainName()
25 25
     {
26 26
         $input_1 = 'www.example.com.';
27
-        $expectation_1 = chr(3).'www'.chr(7).'example'.chr(3).'com'."\0";
27
+        $expectation_1 = chr(3) . 'www' . chr(7) . 'example' . chr(3) . 'com' . "\0";
28 28
 
29 29
         $input_2 = '.';
30 30
         $expectation_2 = "\0";
31 31
 
32 32
         $input_3 = 'tld.';
33
-        $expectation_3 = chr(3).'tld'."\0";
33
+        $expectation_3 = chr(3) . 'tld' . "\0";
34 34
 
35 35
         $this->assertEquals($expectation_1, Encoder::encodeDomainName($input_1));
36 36
         $this->assertEquals($expectation_2, Encoder::encodeDomainName($input_2));
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
             ->setQuestion(true);
51 51
 
52 52
         $expectation_1 =
53
-            chr(3).'www'.chr(7).'example'.chr(3).'com'."\0".
53
+            chr(3) . 'www' . chr(7) . 'example' . chr(3) . 'com' . "\0" .
54 54
             pack('nn', 1, 1);
55 55
 
56 56
         $input_2 = [];
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
             ->setQuestion(2);
62 62
 
63 63
         $expectation_2 =
64
-            chr(6).'domain'.chr(3).'com'.chr(2).'au'."\0".
64
+            chr(6) . 'domain' . chr(3) . 'com' . chr(2) . 'au' . "\0" .
65 65
             pack('nn', 15, 1);
66 66
 
67 67
         $input_3 = [$input_1[0], $input_2[0]];
68
-        $expectation_3 = $expectation_1.$expectation_2;
68
+        $expectation_3 = $expectation_1 . $expectation_2;
69 69
 
70 70
         $this->assertEquals($expectation_1, Encoder::encodeResourceRecords($input_1));
71 71
         $this->assertEquals($expectation_2, Encoder::encodeResourceRecords($input_2));
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $type = RecordTypeEnum::TYPE_MX;
88 88
         $ipAddress = '192.163.5.2';
89 89
 
90
-        $rdata = pack('n', $preference).$exchangeEncoded;
90
+        $rdata = pack('n', $preference) . $exchangeEncoded;
91 91
         $rdata2 = inet_pton($ipAddress);
92 92
 
93 93
         $decoded1 = (new ResourceRecord())
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
             ->setType(RecordTypeEnum::TYPE_A)
106 106
             ->setRdata($ipAddress);
107 107
 
108
-        $encoded1 = $nameEncoded.pack('nnNn', $type, $class, $ttl, strlen($rdata)).$rdata;
109
-        $encoded2 = $nameEncoded.pack('nnNn', 1, $class, $ttl, strlen($rdata2)).$rdata2;
108
+        $encoded1 = $nameEncoded . pack('nnNn', $type, $class, $ttl, strlen($rdata)) . $rdata;
109
+        $encoded2 = $nameEncoded . pack('nnNn', 1, $class, $ttl, strlen($rdata2)) . $rdata2;
110 110
 
111 111
         $this->assertEquals($encoded1, Encoder::encodeResourceRecords([$decoded1]));
112 112
         $this->assertEquals($encoded2, Encoder::encodeResourceRecords([$decoded2]));
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         $encoded_2 = inet_pton($decoded_2);
125 125
 
126 126
         $decoded_5 = 'dns1.example.com.';
127
-        $encoded_5 = chr(4).'dns1'.chr(7).'example'.chr(3).'com'."\0";
127
+        $encoded_5 = chr(4) . 'dns1' . chr(7) . 'example' . chr(3) . 'com' . "\0";
128 128
 
129 129
         $decoded_6 = [
130 130
             'mname' => 'example.com.',
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
         ];
138 138
 
139 139
         $encoded_6 =
140
-            chr(7).'example'.chr(3).'com'."\0".
141
-            chr(10).'postmaster'.chr(7).'example'.chr(3).'com'."\0".
140
+            chr(7) . 'example' . chr(3) . 'com' . "\0" .
141
+            chr(10) . 'postmaster' . chr(7) . 'example' . chr(3) . 'com' . "\0" .
142 142
             pack('NNNNN', 1970010188, 1800, 7200, 10800, 3600);
143 143
 
144 144
         $decoded_7 = [
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
             'exchange' => 'mail.example.com.',
147 147
         ];
148 148
 
149
-        $encoded_7 = pack('n', 15).chr(4).'mail'.chr(7).'example'.chr(3).'com'."\0";
149
+        $encoded_7 = pack('n', 15) . chr(4) . 'mail' . chr(7) . 'example' . chr(3) . 'com' . "\0";
150 150
 
151 151
         $decoded_8 = 'This is a comment.';
152
-        $encoded_8 = chr(18).$decoded_8;
152
+        $encoded_8 = chr(18) . $decoded_8;
153 153
 
154 154
         $this->assertEquals($encoded_1, RdataEncoder::encodeRdata(1, $decoded_1));
155 155
         $this->assertEquals($encoded_2, RdataEncoder::encodeRdata(28, $decoded_2));
Please login to merge, or discard this patch.
tests/DecoderTest.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
     public function testDecodeDomainName()
25 25
     {
26 26
         $decoded_1 = 'www.example.com.';
27
-        $encoded_1 = chr(3).'www'.chr(7).'example'.chr(3).'com'."\0";
27
+        $encoded_1 = chr(3) . 'www' . chr(7) . 'example' . chr(3) . 'com' . "\0";
28 28
 
29 29
         $decoded_2 = '.';
30 30
         $encoded_2 = "\0";
31 31
 
32 32
         $decoded_3 = 'tld.';
33
-        $encoded_3 = chr(3).'tld'."\0";
33
+        $encoded_3 = chr(3) . 'tld' . "\0";
34 34
 
35 35
         $offset = 0;
36 36
         $this->assertEquals($decoded_1, Decoder::decodeDomainName($encoded_1, $offset));
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             ->setQuestion(true);
54 54
 
55 55
         $encoded_1 =
56
-            chr(3).'www'.chr(7).'example'.chr(3).'com'."\0".
56
+            chr(3) . 'www' . chr(7) . 'example' . chr(3) . 'com' . "\0" .
57 57
             pack('nn', 1, 1);
58 58
 
59 59
         $decoded_2[] = (new ResourceRecord())
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
             ->setQuestion(true);
63 63
 
64 64
         $encoded_2 =
65
-            chr(6).'domain'.chr(3).'com'.chr(2).'au'."\0".
65
+            chr(6) . 'domain' . chr(3) . 'com' . chr(2) . 'au' . "\0" .
66 66
             pack('nn', 15, 1);
67 67
 
68 68
         $decoded_3 = [$decoded_1[0], $decoded_2[0]];
69
-        $encoded_3 = $encoded_1.$encoded_2;
69
+        $encoded_3 = $encoded_1 . $encoded_2;
70 70
 
71 71
         $offset = 0;
72 72
         $this->assertEquals($decoded_1, Decoder::decodeResourceRecords($encoded_1, 1, $offset, true));
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $type = RecordTypeEnum::TYPE_MX;
92 92
         $ipAddress = '192.163.5.2';
93 93
 
94
-        $rdata = pack('n', $priority).$exchangeEncoded;
94
+        $rdata = pack('n', $priority) . $exchangeEncoded;
95 95
         $rdata2 = inet_pton($ipAddress);
96 96
 
97 97
         $decoded1[] = (new ResourceRecord())
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 
114 114
         $decoded3 = array_merge($decoded1, $decoded2);
115 115
 
116
-        $encoded1 = $nameEncoded.pack('nnNn', $type, $class, $ttl, strlen($rdata)).$rdata;
117
-        $encoded2 = $nameEncoded.pack('nnNn', 1, $class, $ttl, strlen($rdata2)).$rdata2;
118
-        $encoded3 = $encoded1.$encoded2;
116
+        $encoded1 = $nameEncoded . pack('nnNn', $type, $class, $ttl, strlen($rdata)) . $rdata;
117
+        $encoded2 = $nameEncoded . pack('nnNn', 1, $class, $ttl, strlen($rdata2)) . $rdata2;
118
+        $encoded3 = $encoded1 . $encoded2;
119 119
 
120 120
         $this->assertEquals($decoded1, Decoder::decodeResourceRecords($encoded1));
121 121
         $this->assertEquals($decoded2, Decoder::decodeResourceRecords($encoded2));
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $encoded_2 = inet_pton($decoded_2);
135 135
 
136 136
         $decoded_5 = 'dns1.example.com.';
137
-        $encoded_5 = chr(4).'dns1'.chr(7).'example'.chr(3).'com'."\0";
137
+        $encoded_5 = chr(4) . 'dns1' . chr(7) . 'example' . chr(3) . 'com' . "\0";
138 138
 
139 139
         $decoded_6_prime = [
140 140
             'mname' => 'example.com.',
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
         ];
148 148
 
149 149
         $encoded_6 =
150
-            chr(7).'example'.chr(3).'com'."\0".
151
-            chr(10).'postmaster'.chr(7).'example'.chr(3).'com'."\0".
150
+            chr(7) . 'example' . chr(3) . 'com' . "\0" .
151
+            chr(10) . 'postmaster' . chr(7) . 'example' . chr(3) . 'com' . "\0" .
152 152
             pack('NNNNN', 1970010188, 1800, 7200, 10800, 3600);
153 153
 
154
-        $encoded_7 = pack('n', 10).chr(4).'mail'.chr(7).'example'.chr(3).'com'."\0";
154
+        $encoded_7 = pack('n', 10) . chr(4) . 'mail' . chr(7) . 'example' . chr(3) . 'com' . "\0";
155 155
         $decoded_7_prime = [
156 156
             'preference' => 10,
157 157
             'exchange' => 'mail.example.com.',
158 158
         ];
159 159
 
160 160
         $decoded_8 = 'This is a comment.';
161
-        $encoded_8 = chr(strlen($decoded_8)).$decoded_8;
161
+        $encoded_8 = chr(strlen($decoded_8)) . $decoded_8;
162 162
 
163 163
         $this->assertEquals($decoded_1, RdataDecoder::decodeRdata(RecordTypeEnum::TYPE_A, $encoded_1));
164 164
         $this->assertEquals($decoded_2, RdataDecoder::decodeRdata(RecordTypeEnum::TYPE_AAAA, $encoded_2));
Please login to merge, or discard this patch.
src/RdataEncoder.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
     public static function soa(array $rdata): string
84 84
     {
85 85
         return
86
-            Encoder::encodeDomainName($rdata['mname']).
87
-            Encoder::encodeDomainName($rdata['rname']).
86
+            Encoder::encodeDomainName($rdata['mname']) .
87
+            Encoder::encodeDomainName($rdata['rname']) .
88 88
             pack(
89 89
                 'NNNNN',
90 90
                 $rdata['serial'],
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public static function mx(array $rdata): string
106 106
     {
107
-        return pack('n', (int) $rdata['preference']).Encoder::encodeDomainName($rdata['exchange']);
107
+        return pack('n', (int) $rdata['preference']) . Encoder::encodeDomainName($rdata['exchange']);
108 108
     }
109 109
 
110 110
     /**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $rdata = substr($rdata, 0, 255);
120 120
 
121
-        return chr(strlen($rdata)).$rdata;
121
+        return chr(strlen($rdata)) . $rdata;
122 122
     }
123 123
 
124 124
     /**
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public static function srv(array $rdata): string
132 132
     {
133
-        return pack('nnn', (int) $rdata['priority'], (int) $rdata['weight'], (int) $rdata['port']).
133
+        return pack('nnn', (int) $rdata['priority'], (int) $rdata['weight'], (int) $rdata['port']) .
134 134
             Encoder::encodeDomainName($rdata['target']);
135 135
     }
136 136
 }
Please login to merge, or discard this patch.
src/Server.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,10 +74,10 @@
 block discarded – undo
74 74
 
75 75
         $this->loop = \React\EventLoop\Factory::create();
76 76
         $factory = new \React\Datagram\Factory($this->loop);
77
-        $factory->createServer($this->ip.':'.$this->port)->then(function (Socket $server) {
77
+        $factory->createServer($this->ip . ':' . $this->port)->then(function(Socket $server) {
78 78
             $this->dispatch(Events::SERVER_START, new ServerStartEvent($server));
79 79
             $server->on('message', [$this, 'onMessage']);
80
-        })->otherwise(function (\Exception $exception) {
80
+        })->otherwise(function(\Exception $exception) {
81 81
             $this->dispatch(Events::SERVER_START_FAIL, new ServerExceptionEvent($exception));
82 82
         });
83 83
     }
Please login to merge, or discard this patch.
bin/PhpDnsInstaller.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
         // create default config
39 39
         file_put_contents('/etc/phpdns.json', json_encode(getcwd()));
40
-    } catch (\Symfony\Component\Filesystem\Exception\IOException $e){
41
-        die("An error occurred during installation\n".$e->getMessage());
40
+    } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
41
+        die("An error occurred during installation\n" . $e->getMessage());
42 42
     }
43 43
 
44 44
 } else {
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
     try {
55 55
         echo "Creating required directories and config files...\n";
56 56
 
57
-        $filesystem->mkdir(getcwd().'\\zones');
58
-        $filesystem->mkdir(getcwd().'\\logs');
57
+        $filesystem->mkdir(getcwd() . '\\zones');
58
+        $filesystem->mkdir(getcwd() . '\\logs');
59 59
 
60 60
         // create default config
61
-        file_put_contents(getcwd().'\\phpdns.json', json_encode(getcwd()));
62
-    } catch (\Symfony\Component\Filesystem\Exception\IOException $e){
63
-        die("An error occurred during installation\n".$e->getMessage());
61
+        file_put_contents(getcwd() . '\\phpdns.json', json_encode(getcwd()));
62
+    } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
63
+        die("An error occurred during installation\n" . $e->getMessage());
64 64
     }
65 65
 }
66 66
\ No newline at end of file
Please login to merge, or discard this patch.
src/Resolver/JsonFileSystemResolver.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         $this->filesystemManager = $filesystemManager;
51 51
         $this->defaultTtl = $defaultTtl;
52 52
 
53
-        $zones = glob($filesystemManager->zonePath().'/*.json');
53
+        $zones = glob($filesystemManager->zonePath() . '/*.json');
54 54
         foreach ($zones as $file) {
55 55
             $zone = json_decode(file_get_contents($file), true);
56 56
             $resourceRecords = $this->isLegacyFormat($zone) ? $this->processLegacyZone($zone) : $this->processZone($zone);
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     protected function processZone(array $zone): array
97 97
     {
98
-        $parent = rtrim($zone['domain'], '.').'.';
98
+        $parent = rtrim($zone['domain'], '.') . '.';
99 99
         $defaultTtl = $zone['default-ttl'];
100 100
         $rrs = $zone['resource-records'];
101 101
         $resourceRecords = [];
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     protected function isLegacyFormat(array $zone): bool
126 126
     {
127
-        $keys = array_map(function ($value) {
127
+        $keys = array_map(function($value) {
128 128
             return strtolower($value);
129 129
         }, array_keys($zone));
130 130
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         $resourceRecords = [];
144 144
         foreach ($zones as $domain => $types) {
145
-            $domain = rtrim($domain, '.').'.';
145
+            $domain = rtrim($domain, '.') . '.';
146 146
             foreach ($types as $type => $data) {
147 147
                 $data = (array) $data;
148 148
                 $type = RecordTypeEnum::getTypeFromName($type);
Please login to merge, or discard this patch.