Skip to content

Commit

Permalink
Merge pull request #1 from bangnokia/analysis-EAVnKv
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
bangnokia authored Aug 4, 2020
2 parents f3c3f74 + a7ca953 commit edbe732
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion config/serve_livereload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return [
'dirs' => ['/app', '/public', '/config', '/routes', '/resources']
'dirs' => ['/app', '/public', '/config', '/routes', '/resources'],
];
5 changes: 2 additions & 3 deletions src/CommandServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class CommandServiceProvider extends ServiceProvider implements DeferrableProvider
{

public function register()
{
// override serve command
Expand All @@ -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');
Expand All @@ -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'),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -46,4 +46,4 @@ public function handle()
sleep(1);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Commands/ServeHttpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ServeHttpCommand extends ServeCommand
{
/**
* The console command name
* The console command name.
*
* @var string
*/
Expand All @@ -17,4 +17,4 @@ class ServeHttpCommand extends ServeCommand
* @var bool
*/
protected $hidden = true;
}
}
11 changes: 5 additions & 6 deletions src/Commands/ServeWebSocketsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class ServeWebSocketsCommand extends Command
{

/**
* The console command name.
*
Expand Down Expand Up @@ -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("<info>Websockets server started:</info> ws://127.0.0.1:".self::port());
$this->line('<info>Websockets server started:</info> ws://127.0.0.1:'.self::port());
});

$this->startWatcher();
Expand All @@ -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
);
Expand All @@ -105,4 +104,4 @@ public static function port()
{
return self::$port + self::$offset;
}
}
}
13 changes: 7 additions & 6 deletions src/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ class Injector
{
/**
* Append script to html
* I dont care it doesn't place before </body> tag or not
* I dont care it doesn't place before </body> 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/InjectScriptsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
14 changes: 6 additions & 8 deletions src/Socket.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace BangNokia\ServeLiveReload;


use Ratchet\ConnectionInterface;
use Ratchet\MessageComponentInterface;

Expand All @@ -13,24 +11,24 @@ class Socket implements MessageComponentInterface

public function __construct()
{
self::$clients = new \SplObjectStorage;
self::$clients = new \SplObjectStorage();
}

function onOpen(ConnectionInterface $conn)
public function onOpen(ConnectionInterface $conn)
{
self::$clients->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)
{
}
}
}
8 changes: 4 additions & 4 deletions src/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) {
Expand All @@ -37,4 +37,4 @@ public function startWatching(\Closure $callback)
}
});
}
}
}
8 changes: 4 additions & 4 deletions tests/InjectScriptsToResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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();
}
}
}

0 comments on commit edbe732

Please sign in to comment.