Skip to content

Commit edbe732

Browse files
authored
Merge pull request #1 from bangnokia/analysis-EAVnKv
Apply fixes from StyleCI
2 parents f3c3f74 + a7ca953 commit edbe732

10 files changed

+35
-38
lines changed

config/serve_livereload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
return [
4-
'dirs' => ['/app', '/public', '/config', '/routes', '/resources']
4+
'dirs' => ['/app', '/public', '/config', '/routes', '/resources'],
55
];

src/CommandServiceProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class CommandServiceProvider extends ServiceProvider implements DeferrableProvider
1212
{
13-
1413
public function register()
1514
{
1615
// override serve command
@@ -22,7 +21,7 @@ public function register()
2221
$this->commands([
2322
ServeCommand::class,
2423
ServeHttpCommand::class,
25-
ServeWebSocketsCommand::class
24+
ServeWebSocketsCommand::class,
2625
]);
2726

2827
$this->mergeConfigFrom(__DIR__.'/../config/serve_livereload.php', 'serve_livereload');
@@ -31,7 +30,7 @@ public function register()
3130
public function boot()
3231
{
3332
$this->publishes([
34-
__DIR__.'/../config/serve_livereload.php' => config_path('serve_livereload.php')
33+
__DIR__.'/../config/serve_livereload.php' => config_path('serve_livereload.php'),
3534
]);
3635
}
3736

src/Commands/ServeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function handle()
1919

2020
$processes = [
2121
$httpProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:http']),
22-
$socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets'])
22+
$socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets']),
2323
];
2424

2525
while (count($processes)) {
@@ -46,4 +46,4 @@ public function handle()
4646
sleep(1);
4747
}
4848
}
49-
}
49+
}

src/Commands/ServeHttpCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ServeHttpCommand extends ServeCommand
88
{
99
/**
10-
* The console command name
10+
* The console command name.
1111
*
1212
* @var string
1313
*/
@@ -17,4 +17,4 @@ class ServeHttpCommand extends ServeCommand
1717
* @var bool
1818
*/
1919
protected $hidden = true;
20-
}
20+
}

src/Commands/ServeWebSocketsCommand.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
class ServeWebSocketsCommand extends Command
1919
{
20-
2120
/**
2221
* The console command name.
2322
*
@@ -48,16 +47,16 @@ class ServeWebSocketsCommand extends Command
4847
/**
4948
* Execute the console command.
5049
*
51-
* @return int
52-
*
5350
* @throws \Exception
51+
*
52+
* @return int
5453
*/
5554
public function handle()
5655
{
5756
$this->loop = LoopFactory::create();
5857

5958
$this->loop->futureTick(function () {
60-
$this->line("<info>Websockets server started:</info> ws://127.0.0.1:".self::port());
59+
$this->line('<info>Websockets server started:</info> ws://127.0.0.1:'.self::port());
6160
});
6261

6362
$this->startWatcher();
@@ -80,7 +79,7 @@ protected function startServer()
8079
{
8180
try {
8281
$this->server = new IoServer(
83-
new HttpServer(new WsServer(new Socket)),
82+
new HttpServer(new WsServer(new Socket())),
8483
new Reactor('127.0.0.1:'.self::port(), $this->loop),
8584
$this->loop
8685
);
@@ -105,4 +104,4 @@ public static function port()
105104
{
106105
return self::$port + self::$offset;
107106
}
108-
}
107+
}

src/Injector.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ class Injector
88
{
99
/**
1010
* Append script to html
11-
* I dont care it doesn't place before </body> tag or not
11+
* I dont care it doesn't place before </body> tag or not.
12+
*
13+
* @param string $content
1214
*
13-
* @param string $content
1415
* @return string
1516
*/
1617
public function injectScripts($content)
1718
{
18-
$content = (string)view('serve_livereload::script', [
19-
'host' => '127.0.0.1',
20-
'port' => ServeWebSocketsCommand::port()
21-
]).$content;
19+
$content = (string) view('serve_livereload::script', [
20+
'host' => '127.0.0.1',
21+
'port' => ServeWebSocketsCommand::port(),
22+
]).$content;
2223

2324
return $content;
2425
}

src/Middleware/InjectScriptsMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public function handle(Request $request, Closure $next)
2121
&& !$response instanceof JsonResponse
2222
) {
2323
$response->setContent(
24-
(new Injector)->injectScripts($response->getContent())
24+
(new Injector())->injectScripts($response->getContent())
2525
);
2626
}
2727

2828
return $response;
2929
}
30-
}
30+
}

src/Socket.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace BangNokia\ServeLiveReload;
54

6-
75
use Ratchet\ConnectionInterface;
86
use Ratchet\MessageComponentInterface;
97

@@ -13,24 +11,24 @@ class Socket implements MessageComponentInterface
1311

1412
public function __construct()
1513
{
16-
self::$clients = new \SplObjectStorage;
14+
self::$clients = new \SplObjectStorage();
1715
}
1816

19-
function onOpen(ConnectionInterface $conn)
17+
public function onOpen(ConnectionInterface $conn)
2018
{
2119
self::$clients->attach($conn);
2220
}
2321

24-
function onClose(ConnectionInterface $conn)
22+
public function onClose(ConnectionInterface $conn)
2523
{
2624
self::$clients->detach($conn);
2725
}
2826

29-
function onError(ConnectionInterface $conn, \Exception $e)
27+
public function onError(ConnectionInterface $conn, \Exception $e)
3028
{
3129
}
3230

33-
function onMessage(ConnectionInterface $from, $msg)
31+
public function onMessage(ConnectionInterface $from, $msg)
3432
{
3533
}
36-
}
34+
}

src/Watcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace BangNokia\ServeLiveReload;
44

5+
use Illuminate\Support\Facades\Cache;
56
use React\EventLoop\LoopInterface;
67
use Symfony\Component\Finder\Finder;
78
use Yosymfony\ResourceWatcher\Crc32ContentHash;
89
use Yosymfony\ResourceWatcher\ResourceCacheMemory;
910
use Yosymfony\ResourceWatcher\ResourceWatcher;
10-
use Illuminate\Support\Facades\Cache;
1111

1212
class Watcher
1313
{
@@ -25,9 +25,9 @@ public function __construct(LoopInterface $loop, Finder $finder)
2525
public function startWatching(\Closure $callback)
2626
{
2727
$watcher = new ResourceWatcher(
28-
new ResourceCacheMemory,
28+
new ResourceCacheMemory(),
2929
$this->finder,
30-
new Crc32ContentHash
30+
new Crc32ContentHash()
3131
);
3232

3333
$this->loop->addPeriodicTimer(0.5, function () use ($watcher, $callback) {
@@ -37,4 +37,4 @@ public function startWatching(\Closure $callback)
3737
}
3838
});
3939
}
40-
}
40+
}

tests/InjectScriptsToResponseTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function test_it_inject_scripts_to_get_request()
3939
});
4040

4141
$this->get('/_test/html')
42-
->assertSee("ws://127.0.0.1:".ServeWebSocketsCommand::port());
42+
->assertSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port());
4343
}
4444

4545
public function test_it_doesnt_inject_script_to_post_request()
@@ -50,7 +50,7 @@ public function test_it_doesnt_inject_script_to_post_request()
5050

5151
$this->post('/_test/html')
5252
->assertSee('html')
53-
->assertDontSee("ws://127.0.0.1:".ServeWebSocketsCommand::port());
53+
->assertDontSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port());
5454
}
5555

5656
public function test_it_doesnt_inject_scripts_to_json_response()
@@ -77,11 +77,11 @@ public function test_it_doesnt_inject_script_to_ajax_response()
7777

7878
$this->get('/_test/html', ['HTTP_X-Requested-With' => 'XMLHttpRequest'])
7979
->assertSee('html string')
80-
->assertDontSee("ws://127.0.0.1:".ServeWebSocketsCommand::port());
80+
->assertDontSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port());
8181
}
8282

8383
public function tearDown(): void
8484
{
8585
parent::tearDown();
8686
}
87-
}
87+
}

0 commit comments

Comments
 (0)