diff --git a/src/Centrifugo.php b/src/Centrifugo.php index be4365f657a9bd46c6ffcd74909d27c3bdb98864..3b598e12c45e80238897d5d7d299b953cff6cc49 100644 --- a/src/Centrifugo.php +++ b/src/Centrifugo.php @@ -42,7 +42,7 @@ class Centrifugo implements CentrifugoInterface * * @return array */ - protected function initConfiguration(array $config) : array + protected function initConfiguration(array $config): array { $defaults = [ 'url' => 'http://localhost:8000', @@ -70,7 +70,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function publish(string $channel, array $data, bool $skipHistory = false) : array + public function publish(string $channel, array $data, bool $skipHistory = false): array { return $this->send('publish', [ 'channel' => $channel, @@ -88,7 +88,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function broadcast(array $channels, array $data, bool $skipHistory = false) : array + public function broadcast(array $channels, array $data, bool $skipHistory = false): array { $params = [ 'channels' => $channels, @@ -106,7 +106,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function presence(string $channel) : array + public function presence(string $channel): array { return $this->send('presence', ['channel' => $channel]); } @@ -118,7 +118,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function presenceStats(string $channel) : array + public function presenceStats(string $channel): array { return $this->send('presence_stats', ['channel' => $channel]); } @@ -133,7 +133,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function history(string $channel, $limit = 0, array $since = [], bool $reverse = false) : array + public function history(string $channel, $limit = 0, array $since = [], bool $reverse = false): array { $params = [ 'channel' => $channel, @@ -154,7 +154,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function historyRemove(string $channel) : array + public function historyRemove(string $channel): array { return $this->send('history_remove', [ 'channel' => $channel, @@ -170,7 +170,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function subscribe($channel, $user, $client = '') : array + public function subscribe($channel, $user, $client = ''): array { return $this->send('subscribe', [ 'channel' => $channel, @@ -188,7 +188,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function unsubscribe(string $channel, string $user, string $client = '') : array + public function unsubscribe(string $channel, string $user, string $client = ''): array { return $this->send('unsubscribe', [ 'channel' => $channel, @@ -204,7 +204,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function disconnect(string $user_id, string $client = '') : array + public function disconnect(string $user_id, string $client = ''): array { return $this->send('disconnect', [ 'user' => $user_id, @@ -219,7 +219,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function channels(string $pattern = '') : array + public function channels(string $pattern = ''): array { return $this->send('channels', ['pattern' => $pattern]); } @@ -229,7 +229,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function info() : array + public function info(): array { return $this->send('info'); } @@ -325,26 +325,27 @@ class Centrifugo implements CentrifugoInterface * @param string $method * @param array $params * - * @return mixed * @throws GuzzleException + * + * @return mixed */ - protected function send(string $method, array $params = []) : array + protected function send(string $method, array $params = []): array { $url = $this->prepareUrl(); - $config =[ - 'base_uri' => $url, + $config = [ + 'base_uri' => $url, 'headers' => [ 'Content-type' => 'application/json', - 'X-API-Key' => $this->getApiKey(), + 'X-API-Key' => $this->getApiKey(), ], 'json' => $params, 'http_errors' => true, - 'verify' => $this->config['verify'], - 'ssl_key' => $this->config['ssl_key'] + 'verify' => $this->config['verify'], + 'ssl_key' => $this->config['ssl_key'], ]; - try { + try { $response = $this->httpClient->post($method, $config); $result = json_decode((string) $response->getBody(), true); @@ -356,7 +357,6 @@ class Centrifugo implements CentrifugoInterface ]; } - return $result; } diff --git a/src/CentrifugoServiceProvider.php b/src/CentrifugoServiceProvider.php index 55f7183feb3d961d4e8f0f4533fb01f8e374355c..bbc99f96f202e2f651edf6236b244f29513c2740 100644 --- a/src/CentrifugoServiceProvider.php +++ b/src/CentrifugoServiceProvider.php @@ -22,7 +22,6 @@ class CentrifugoServiceProvider extends ServiceProvider $this->commands(InstallCommand::class); } - $broadcastManager->extend('centrifugo', function ($app) { return new CentrifugoBroadcaster($app->make('centrifugo')); }); @@ -35,7 +34,6 @@ class CentrifugoServiceProvider extends ServiceProvider */ public function register(): void { - $this->app->singleton('centrifugo', function ($app) { $config = $app->make('config')->get('broadcasting.connections.centrifugo'); $http = new HttpClient(); diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 19095c962a5531cc280c7bb8daaf04e43472472e..d62a88d8f353ce7ae168f85e6e0c497d9f7f13ca 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -49,16 +49,15 @@ class InstallCommand extends Command } $contents = File::get($env); - $token_hmac_secret_key=Str::uuid()->toString(); - $api_key=Str::uuid()->toString(); - + $token_hmac_secret_key = Str::uuid()->toString(); + $api_key = Str::uuid()->toString(); $variables = Arr::where([ 'CENTRIFUGO_TOKEN_HMAC_SECRET_KEY' => "CENTRIFUGO_TOKEN_HMAC_SECRET_KEY={$token_hmac_secret_key}", - 'CENTRIFUGO_API_KEY' => "CENTRIFUGO_API_KEY={$api_key}", - 'CENTRIFUGO_URL' => 'CENTRIFUGO_URL="http://localhost:8000"' + 'CENTRIFUGO_API_KEY' => "CENTRIFUGO_API_KEY={$api_key}", + 'CENTRIFUGO_URL' => 'CENTRIFUGO_URL="http://localhost:8000"', ], function ($value, $key) use ($contents) { - return ! Str::contains($contents, PHP_EOL.$key); + return !Str::contains($contents, PHP_EOL.$key); }); $variables = trim(implode(PHP_EOL, $variables)); @@ -81,7 +80,7 @@ class InstallCommand extends Command return; $this->callSilently('vendor:publish', [ '--provider' => 'App\Providers\BroadcastServiceProvider', - '--tag' => 'centrifuge-config', + '--tag' => 'centrifuge-config', ]); } @@ -94,7 +93,6 @@ class InstallCommand extends Command return; } - File::replaceInFile( "'connections' => [\n", <<<'CONFIG' @@ -128,7 +126,7 @@ class InstallCommand extends Command $enable = confirm('Would you like to enable event broadcasting?', default: true); - if (! $enable) { + if (!$enable) { return; } @@ -158,8 +156,7 @@ class InstallCommand extends Command */ protected function updateBroadcastingDriver(): void { - - if ( File::missing($env = app()->environmentFile())) { + if (File::missing($env = app()->environmentFile())) { return; } diff --git a/tests/TestCase.php b/tests/TestCase.php index 845c0ff259031c0d5923151b40cbfcde4b66789a..dbd071b36aea0e128dd42cef5d601d89579b734c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,13 +28,12 @@ class TestCase extends \Orchestra\Testbench\TestCase protected function getEnvironmentSetUp($app) { - $app['config']->set('broadcasting.default', 'centrifugo'); $app['config']->set('broadcasting.connections.centrifugo', [ - 'driver' => 'centrifugo', + 'driver' => 'centrifugo', 'token_hmac_secret_key' => 'secret', - 'api_key' => 'api-key', - 'url' => 'http://localhost:8000', + 'api_key' => 'api-key', + 'url' => 'http://localhost:8000', ]); } } diff --git a/tests/Unit/CentrifugoTest.php b/tests/Unit/CentrifugoTest.php index cb4ac75750a8e07d1bb4bab05733502b6e791462..96e0fcc5b158406af16bc78de5aab4fe8fe303ca 100644 --- a/tests/Unit/CentrifugoTest.php +++ b/tests/Unit/CentrifugoTest.php @@ -1,5 +1,6 @@ "Tristian", - 'last_name' => "Ruecker", + 'first_name' => 'Tristian', + 'last_name' => 'Ruecker', ]; - $clientId = "f2527b6a-6705-45b7-a1d9-d0029943dc20"; + $clientId = 'f2527b6a-6705-45b7-a1d9-d0029943dc20'; $clientToken1 = $this->centrifuge->generateConnectionToken(userId:$clientId); @@ -62,7 +55,6 @@ class CentrifugoTest extends TestCase $this->assertArrayHasKey('result', $broadcast['result']['responses'][1]); } - public function testCentrifugoApiPresence(): void { $presence = $this->centrifuge->presence('test-channel'); @@ -104,10 +96,9 @@ class CentrifugoTest extends TestCase $this->assertEquals([ 'result' => [ 'num_clients' => 0, - 'num_users' => 0, + 'num_users' => 0, ], ], $stats); - } public function testTimeoutFunction(): void @@ -117,13 +108,13 @@ class CentrifugoTest extends TestCase $badCentrifugo = new Centrifugo( [ - 'driver' => 'centrifugo', + 'driver' => 'centrifugo', 'token_hmac_secret_key' => '', - 'api_key' => '', - 'api_path' => '', - 'url' => 'http://localhost:3999', - 'timeout' => $timeout, - 'tries' => 1, + 'api_key' => '', + 'api_path' => '', + 'url' => 'http://localhost:3999', + 'timeout' => $timeout, + 'tries' => 1, ], new Client() ); @@ -150,13 +141,13 @@ class CentrifugoTest extends TestCase $badCentrifugo = new Centrifugo( [ - 'driver' => 'centrifugo', + 'driver' => 'centrifugo', 'token_hmac_secret_key' => '', - 'api_key' => '', - 'api_path' => '', - 'url' => 'http://localhost:3999', - 'timeout' => $timeout, - 'tries' => $tries, + 'api_key' => '', + 'api_path' => '', + 'url' => 'http://localhost:3999', + 'timeout' => $timeout, + 'tries' => $tries, ], new Client() );