diff --git a/config/serve_livereload.php b/config/serve_livereload.php index 050dbec..b8bdcde 100644 --- a/config/serve_livereload.php +++ b/config/serve_livereload.php @@ -1,5 +1,5 @@ ['/app', '/public', '/config', '/routes', '/resources'] + 'dirs' => ['/app', '/public', '/config', '/routes', '/resources'], ]; diff --git a/src/CommandServiceProvider.php b/src/CommandServiceProvider.php index 6539ca7..bac14be 100644 --- a/src/CommandServiceProvider.php +++ b/src/CommandServiceProvider.php @@ -10,7 +10,6 @@ class CommandServiceProvider extends ServiceProvider implements DeferrableProvider { - public function register() { // override serve command @@ -22,7 +21,7 @@ public function register() $this->commands([ ServeCommand::class, ServeHttpCommand::class, - ServeWebSocketsCommand::class + ServeWebSocketsCommand::class, ]); $this->mergeConfigFrom(__DIR__.'/../config/serve_livereload.php', 'serve_livereload'); @@ -31,7 +30,7 @@ public function register() public function boot() { $this->publishes([ - __DIR__.'/../config/serve_livereload.php' => config_path('serve_livereload.php') + __DIR__.'/../config/serve_livereload.php' => config_path('serve_livereload.php'), ]); } diff --git a/src/Commands/ServeCommand.php b/src/Commands/ServeCommand.php index 5919a03..84ae111 100644 --- a/src/Commands/ServeCommand.php +++ b/src/Commands/ServeCommand.php @@ -19,7 +19,7 @@ public function handle() $processes = [ $httpProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:http']), - $socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets']) + $socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets']), ]; while (count($processes)) { @@ -46,4 +46,4 @@ public function handle() sleep(1); } } -} \ No newline at end of file +} diff --git a/src/Commands/ServeHttpCommand.php b/src/Commands/ServeHttpCommand.php index 83b0ef3..0cbb690 100644 --- a/src/Commands/ServeHttpCommand.php +++ b/src/Commands/ServeHttpCommand.php @@ -7,7 +7,7 @@ class ServeHttpCommand extends ServeCommand { /** - * The console command name + * The console command name. * * @var string */ @@ -17,4 +17,4 @@ class ServeHttpCommand extends ServeCommand * @var bool */ protected $hidden = true; -} \ No newline at end of file +} diff --git a/src/Commands/ServeWebSocketsCommand.php b/src/Commands/ServeWebSocketsCommand.php index 2f54377..372df7d 100644 --- a/src/Commands/ServeWebSocketsCommand.php +++ b/src/Commands/ServeWebSocketsCommand.php @@ -17,7 +17,6 @@ class ServeWebSocketsCommand extends Command { - /** * The console command name. * @@ -48,16 +47,16 @@ class ServeWebSocketsCommand extends Command /** * Execute the console command. * - * @return int - * * @throws \Exception + * + * @return int */ public function handle() { $this->loop = LoopFactory::create(); $this->loop->futureTick(function () { - $this->line("Websockets server started: ws://127.0.0.1:".self::port()); + $this->line('Websockets server started: ws://127.0.0.1:'.self::port()); }); $this->startWatcher(); @@ -80,7 +79,7 @@ protected function startServer() { try { $this->server = new IoServer( - new HttpServer(new WsServer(new Socket)), + new HttpServer(new WsServer(new Socket())), new Reactor('127.0.0.1:'.self::port(), $this->loop), $this->loop ); @@ -105,4 +104,4 @@ public static function port() { return self::$port + self::$offset; } -} \ No newline at end of file +} diff --git a/src/Injector.php b/src/Injector.php index 5cbca05..be9ec27 100644 --- a/src/Injector.php +++ b/src/Injector.php @@ -8,17 +8,18 @@ class Injector { /** * Append script to html - * I dont care it doesn't place before tag or not + * I dont care it doesn't place before tag or not. + * + * @param string $content * - * @param string $content * @return string */ public function injectScripts($content) { - $content = (string)view('serve_livereload::script', [ - 'host' => '127.0.0.1', - 'port' => ServeWebSocketsCommand::port() - ]).$content; + $content = (string) view('serve_livereload::script', [ + 'host' => '127.0.0.1', + 'port' => ServeWebSocketsCommand::port(), + ]).$content; return $content; } diff --git a/src/Middleware/InjectScriptsMiddleware.php b/src/Middleware/InjectScriptsMiddleware.php index 6cfe37e..5c6f35b 100644 --- a/src/Middleware/InjectScriptsMiddleware.php +++ b/src/Middleware/InjectScriptsMiddleware.php @@ -21,10 +21,10 @@ public function handle(Request $request, Closure $next) && !$response instanceof JsonResponse ) { $response->setContent( - (new Injector)->injectScripts($response->getContent()) + (new Injector())->injectScripts($response->getContent()) ); } return $response; } -} \ No newline at end of file +} diff --git a/src/Socket.php b/src/Socket.php index 0795881..140127c 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -1,9 +1,7 @@ attach($conn); } - function onClose(ConnectionInterface $conn) + public function onClose(ConnectionInterface $conn) { self::$clients->detach($conn); } - function onError(ConnectionInterface $conn, \Exception $e) + public function onError(ConnectionInterface $conn, \Exception $e) { } - function onMessage(ConnectionInterface $from, $msg) + public function onMessage(ConnectionInterface $from, $msg) { } -} \ No newline at end of file +} diff --git a/src/Watcher.php b/src/Watcher.php index 05a921b..8dbc153 100644 --- a/src/Watcher.php +++ b/src/Watcher.php @@ -2,12 +2,12 @@ namespace BangNokia\ServeLiveReload; +use Illuminate\Support\Facades\Cache; use React\EventLoop\LoopInterface; use Symfony\Component\Finder\Finder; use Yosymfony\ResourceWatcher\Crc32ContentHash; use Yosymfony\ResourceWatcher\ResourceCacheMemory; use Yosymfony\ResourceWatcher\ResourceWatcher; -use Illuminate\Support\Facades\Cache; class Watcher { @@ -25,9 +25,9 @@ public function __construct(LoopInterface $loop, Finder $finder) public function startWatching(\Closure $callback) { $watcher = new ResourceWatcher( - new ResourceCacheMemory, + new ResourceCacheMemory(), $this->finder, - new Crc32ContentHash + new Crc32ContentHash() ); $this->loop->addPeriodicTimer(0.5, function () use ($watcher, $callback) { @@ -37,4 +37,4 @@ public function startWatching(\Closure $callback) } }); } -} \ No newline at end of file +} diff --git a/tests/InjectScriptsToResponseTest.php b/tests/InjectScriptsToResponseTest.php index cb8377c..d4b5d5b 100644 --- a/tests/InjectScriptsToResponseTest.php +++ b/tests/InjectScriptsToResponseTest.php @@ -39,7 +39,7 @@ public function test_it_inject_scripts_to_get_request() }); $this->get('/_test/html') - ->assertSee("ws://127.0.0.1:".ServeWebSocketsCommand::port()); + ->assertSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port()); } public function test_it_doesnt_inject_script_to_post_request() @@ -50,7 +50,7 @@ public function test_it_doesnt_inject_script_to_post_request() $this->post('/_test/html') ->assertSee('html') - ->assertDontSee("ws://127.0.0.1:".ServeWebSocketsCommand::port()); + ->assertDontSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port()); } public function test_it_doesnt_inject_scripts_to_json_response() @@ -77,11 +77,11 @@ public function test_it_doesnt_inject_script_to_ajax_response() $this->get('/_test/html', ['HTTP_X-Requested-With' => 'XMLHttpRequest']) ->assertSee('html string') - ->assertDontSee("ws://127.0.0.1:".ServeWebSocketsCommand::port()); + ->assertDontSee('ws://127.0.0.1:'.ServeWebSocketsCommand::port()); } public function tearDown(): void { parent::tearDown(); } -} \ No newline at end of file +}