Completed
Push — master ( 8aed6d...e71704 )
by Brad
02:25
created
src/Protocol/WebSocket/MessageQueue.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
     }
22 22
     public function add($data)
23 23
     {
24
-        $this->data.=$data;
24
+        $this->data .= $data;
25 25
     }
26 26
 
27 27
     public function __toString()
Please login to merge, or discard this patch.
src/Protocol/WebSocket/Frame.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
     public function appendData($data)
112 112
     {
113
-        $this->data.=$data;
113
+        $this->data .= $data;
114 114
         $this->updatePayloadLength($this->data, $this->secondByte, $this->extendedPayload);
115 115
     }
116 116
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         }
153 153
         $maskingKey = $this->generateMaskingKey();
154 154
 
155
-        return $maskingKey . $this->applyMask($maskingKey, $payload);
155
+        return $maskingKey.$this->applyMask($maskingKey, $payload);
156 156
     }
157 157
 
158 158
     public function getPayloadLength($encodedData)
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     {
250 250
         $this->isCoalesced = true;
251 251
 
252
-        return pack('CC', $this->firstByte, $this->secondByte) . $this->extendedPayload . $this->maskPayload($this->data);
252
+        return pack('CC', $this->firstByte, $this->secondByte).$this->extendedPayload.$this->maskPayload($this->data);
253 253
     }
254 254
 
255 255
     protected function updatePayloadLength($data, &$secondByte, &$extendedPayload)
Please login to merge, or discard this patch.
src/Protocol/WebSocket/WebSocket.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@
 block discarded – undo
33 33
     public function handshake($request)
34 34
     {
35 35
         $key = $request->headers->get('Sec-WebSocket-Key');
36
-        if(
36
+        if (
37 37
             strtolower($request->headers->get('Upgrade')) != 'websocket' ||
38 38
             !$this->checkProtocolVrsion($request) ||
39 39
             !$this->checkSecKey($key)
40
-          ){
40
+          ) {
41 41
             return false;
42 42
         }
43 43
         $acceptKey = $this->generateAcceptKey($key);
Please login to merge, or discard this patch.
src/Protocol/WebSocketProtocol.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     protected function initEvent()
36 36
     {
37 37
         $this->websocket = new WebSocket\WebSocket();
38
-        $this->conn->on('data', function($data){
38
+        $this->conn->on('data', function($data) {
39 39
             $this->onData($data);
40 40
         });
41 41
     }
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
     protected function onData($data)
44 44
     {
45 45
         $frame = $this->websocket->onMessage($data);
46
-        if(!($frame instanceof WebSocket\Frame)) {
46
+        if (!($frame instanceof WebSocket\Frame)) {
47 47
             return;
48 48
         }
49
-        if(($command = json_decode($frame->getData(), true)) === null){
49
+        if (($command = json_decode($frame->getData(), true)) === null) {
50 50
             return;
51 51
         }
52 52
         $this->conn->emit('command', array($command));
Please login to merge, or discard this patch.
src/Protocol/HttpProtocol.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
     protected function initEvent(SocketServer $socket)
22 22
     {
23
-        $socket->on('connection', function(SocketConnection $conn){
23
+        $socket->on('connection', function(SocketConnection $conn) {
24 24
             $this->onConnect($conn);
25 25
         });
26 26
     }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
     protected function handleRequest(SocketConnection $conn, Request $request)
42 42
     {
43
-        switch($request->getPathInfo()){
43
+        switch ($request->getPathInfo()) {
44 44
             case '/livereload':
45 45
                 $this->initWebSocket($conn, $request);
46 46
                 break;
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
     protected function initWebSocket(SocketConnection $conn, Request $request)
59 59
     {
60 60
         $conn->removeAllListeners('data');
61
-        return new WebSocketProtocol($conn,  $this->app, $request);
61
+        return new WebSocketProtocol($conn, $this->app, $request);
62 62
     }
63 63
 
64 64
     protected function getRequestChangedFiles(Request $request)
65 65
     {
66
-        if(($files = $request->query->get('files')) != null){
66
+        if (($files = $request->query->get('files')) != null) {
67 67
             return explode(',', $files);
68 68
         }
69 69
         $requestJson = json_decode($request->getContent(), true);
70
-        return isset($requestJson['files'])?(is_array($requestJson['files'])?$requestJson['files']:[$requestJson['files']]):[];
70
+        return isset($requestJson['files']) ? (is_array($requestJson['files']) ? $requestJson['files'] : [$requestJson['files']]) : [];
71 71
     }
72 72
 
73 73
     protected function notifyChanged(SocketConnection $conn, Request $request)
74 74
     {
75
-        foreach($this->getRequestChangedFiles($request) as $file){
75
+        foreach ($this->getRequestChangedFiles($request) as $file) {
76 76
             $this->app->getOutput()->writeln(strftime('%T')." - info - Receive request reload $file", OutputInterface::VERBOSITY_VERBOSE);
77 77
             $this->app->reloadFile($file);
78 78
         }
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 
83 83
     protected function serveFile(SocketConnection $conn, $file)
84 84
     {
85
-        if(($path = realpath($file)) === null){
86
-            return ;
85
+        if (($path = realpath($file)) === null) {
86
+            return;
87 87
         }
88 88
         $content = file_get_contents($file);
89 89
         $response = new Response($content);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     protected function doHttpHandshake($data)
102 102
     {
103 103
         $pos = strpos($data, "\r\n\r\n");
104
-        if($pos === false){
104
+        if ($pos === false) {
105 105
             return false;
106 106
         }
107 107
         $body = substr($data, $pos + 4);
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     protected function parseHeaders($rawHeaders)
120 120
     {
121 121
         $headers = array();
122
-        foreach($rawHeaders as $headerLine){
123
-            if(($pos = strpos($headerLine, ':')) === false){
122
+        foreach ($rawHeaders as $headerLine) {
123
+            if (($pos = strpos($headerLine, ':')) === false) {
124 124
                 continue;
125 125
             }
126 126
             $headers['HTTP_'.str_replace('-', '_', trim(strtoupper(substr($headerLine, 0, $pos))))] = trim(substr($headerLine, $pos + 1));
Please login to merge, or discard this patch.
src/Protocol/LivereloadProtocol.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 
42 42
     protected function initEvent()
43 43
     {
44
-        $this->conn->on('command', function($command){
44
+        $this->conn->on('command', function($command) {
45 45
             $this->dispatchCommand($command);
46 46
         });
47
-        $this->conn->on('close', function(){
47
+        $this->conn->on('close', function() {
48 48
             $this->shutdown();
49 49
         });
50 50
     }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     protected function dispatchCommand($command)
64 64
     {
65
-        switch($command['command']){
65
+        switch ($command['command']) {
66 66
             case 'hello':
67 67
                 $this->processCommandHello($command);
68 68
                 break;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
     protected function processCommandHello($command)
75 75
     {
76
-        if($this->connected){
76
+        if ($this->connected) {
77 77
            return;
78 78
         }
79 79
         $this->app->getOutput()->writeln(strftime('%T')." - info - Livereload protocol initialized.", OutputInterface::VERBOSITY_VERBOSE);
Please login to merge, or discard this patch.
src/Command/RunCommand.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         $output->writeln('Quit the server with CONTROL-C.');
31 31
         $output->writeln('');
32 32
         $app = new ServerApplication($host, $port);
33
-        if(!$noWatching){
33
+        if (!$noWatching) {
34 34
             $config = $this->loadConfig($input, $output);
35 35
             $app->watching($config['period'], $config);
36 36
         }
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
     protected function loadConfig(InputInterface $input, OutputInterface $output)
42 42
     {
43 43
         $configFile = $input->getOption('config');
44
-        if($configFile === null){
44
+        if ($configFile === null) {
45 45
             $configFile = 'livereload.json';
46 46
         }
47
-        if(!file_exists($configFile)){
47
+        if (!file_exists($configFile)) {
48 48
             throw new \Exception("$configFile not found.");
49 49
         }
50 50
 
Please login to merge, or discard this patch.
src/Command/InitCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
     protected function execute(InputInterface $input, OutputInterface $output)
23 23
     {
24 24
         $forceRewrite = $input->getOption('force');
25
-        if(!$forceRewrite && file_exists('livereload.json')){
25
+        if (!$forceRewrite && file_exists('livereload.json')) {
26 26
             $output->writeln("<error>livereload.json file exists.\nplease use --force to overwrite.</error>");
27 27
             return;
28 28
         }
Please login to merge, or discard this patch.
src/Application/ServerApplication.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
     {
53 53
         $this->watchConfig = $config;
54 54
         $this->scanFiles();
55
-        $this->loop->addPeriodicTimer($time, function(){
55
+        $this->loop->addPeriodicTimer($time, function() {
56 56
             $this->watchingFileChange();
57 57
         });
58 58
     }
59 59
 
60 60
     protected function scanFiles($scanNewFile = true)
61 61
     {
62
-        foreach($this->watchConfig['watch'] as $path => $file){
62
+        foreach ($this->watchConfig['watch'] as $path => $file) {
63 63
             $finder = new Finder();
64
-            try{
65
-                foreach($finder->in($path)->name($file)->followLinks() as $file){
66
-                    if($file->getRealPath() && !isset($this->watchingFiles[$file->getRealpath()])){
67
-                        $this->watchingFiles[$file->getRealpath()] = $scanNewFile?$file->getMTime():0;
64
+            try {
65
+                foreach ($finder->in($path)->name($file)->followLinks() as $file) {
66
+                    if ($file->getRealPath() && !isset($this->watchingFiles[$file->getRealpath()])) {
67
+                        $this->watchingFiles[$file->getRealpath()] = $scanNewFile ? $file->getMTime() : 0;
68 68
                     }
69 69
                 }
70 70
             }
71
-            catch(\InvalidArgumentException $e){
71
+            catch (\InvalidArgumentException $e) {
72 72
                 continue;
73 73
             }
74 74
         }
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
     protected function watchingFileChange()
78 78
     {
79 79
         $this->scanFiles(false);
80
-        foreach($this->watchingFiles as $file => $time){
80
+        foreach ($this->watchingFiles as $file => $time) {
81 81
             $mtime = @filemtime($file);
82
-            if($mtime && $mtime > $time){
82
+            if ($mtime && $mtime > $time) {
83 83
                 $this->watchingFiles[$file] = $mtime;
84 84
                 $this->reloadFile($file);
85 85
             }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
     public function addClient(Protocol\LivereloadProtocol $client)
102 102
     {
103
-        if(!in_array($client, $this->clients)){
103
+        if (!in_array($client, $this->clients)) {
104 104
             $this->clients[] = $client;
105 105
         }
106 106
     }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     public function removeClient(Protocol\LivereloadProtocol $client)
109 109
     {
110 110
         $index = array_search($client, $this->clients, true);
111
-        if($index === false){
111
+        if ($index === false) {
112 112
             return;
113 113
         }
114 114
         unset($this->clients[$index]);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
     public function reloadFile($file)
118 118
     {
119
-        foreach($this->clients as $client){
119
+        foreach ($this->clients as $client) {
120 120
             $client->reload($file, $this->config);
121 121
         }
122 122
     }
Please login to merge, or discard this patch.