Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
[PHP-CS] Fix files according to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
clem committed Mar 25, 2020
1 parent 7b2d69b commit 5d6dfa9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/AppBundle/AppBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use AppBundle\DependencyInjection\AfsyChatExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @inheritdoc
* {@inheritdoc}
*/
class AppBundle extends Bundle
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getContainerExtension()
{
Expand Down
12 changes: 5 additions & 7 deletions src/AppBundle/Command/ChatServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use AppBundle\Server\Chat;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;

use AppBundle\Server\Chat;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Chat Server Command
* Chat Server Command.
*/
class ChatServerCommand extends ContainerAwareCommand
{
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function indexAction()

// Check if it's Christmas Time
// Only on december and before the 26th
if (date('m') === '12' && (int) date('d') < 26) {
if ('12' === date('m') && (int) date('d') < 26) {
// Set Christmas
$itsChristmas = true;

// Get christmas link
// Get Christmas link
$christmasLinks = $this->container->getParameter('xmas_links');
$xmasLink = $christmasLinks[rand(0, count($christmasLinks) - 1)];
$xmasLink = $christmasLinks[rand(0, \count($christmasLinks) - 1)];
}

// Render template
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/DependencyInjection/AfsyChatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace AppBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* @inheritdoc
* {@inheritdoc}
*/
class AfsyChatExtension extends Extension
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand Down
4 changes: 2 additions & 2 deletions src/AppBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* @inheritdoc
* {@inheritdoc}
*/
class Configuration implements ConfigurationInterface
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
Expand Down
44 changes: 23 additions & 21 deletions src/AppBundle/Server/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Ratchet\MessageComponentInterface;

/**
* Chat Server
* Chat Server.
*/
class Chat implements MessageComponentInterface
{
Expand All @@ -31,7 +31,7 @@ class Chat implements MessageComponentInterface
private $defaultChannel = 'general';

/**
* Chat constructor
* Chat constructor.
*/
public function __construct()
{
Expand All @@ -41,7 +41,7 @@ public function __construct()
}

/**
* A new websocket connection
* A new websocket connection.
*
* @param ConnectionInterface $conn
*/
Expand All @@ -52,23 +52,23 @@ public function onOpen(ConnectionInterface $conn)
$this->users[$conn->resourceId] = [
'connection' => $conn,
'user' => '',
'channels' => []
'channels' => [],
];

// Send hello message
$conn->send(json_encode([
'action' => 'message',
'action' => 'message',
'channel' => $this->defaultChannel,
'user' => $this->botName,
'user' => $this->botName,
'message' => sprintf('Connection established. Welcome #%d!', $conn->resourceId),
'messageClass' => 'success',
]));
}

/**
* A connection is closed
*
* @param ConnectionInterface $closedConnection
* A connection is closed.
*/
public function onClose(ConnectionInterface $closedConnection)
{
Expand All @@ -89,37 +89,37 @@ public function onClose(ConnectionInterface $closedConnection)
}

/**
* Error handling
* Error handling.
*
* @param ConnectionInterface $conn
* @param \Exception $e
*/
public function onError(ConnectionInterface $conn, \Exception $e)
{
$conn->send(json_encode([
'action' => 'message',
'action' => 'message',
'channel' => $this->defaultChannel,
'user' => $this->botName,
'message' => 'An error has occurred: '.$e->getMessage()
'user' => $this->botName,
'message' => 'An error has occurred: '.$e->getMessage(),
]));
$conn->close();
}

/**
* Handle message sending
* Handle message sending.
*
* @param ConnectionInterface $conn
* @param string $message
*
* @return boolean - False if message is not a valid JSON or action is invalid
* @return bool - False if message is not a valid JSON or action is invalid
*/
public function onMessage(ConnectionInterface $conn, $message)
{
// Initialize
$messageData = json_decode($message);

// Check message data
if ($messageData === null) {
if (null === $messageData) {
return false;
}

Expand All @@ -138,9 +138,11 @@ public function onMessage(ConnectionInterface $conn, $message)
switch ($action) {
case 'subscribe':
$this->subscribeToChannel($conn, $channel, $user);

return true;
case 'unsubscribe':
$this->unsubscribeFromChannel($conn, $channel, $user);

return true;
case 'message':
return $this->sendMessageToChannel($conn, $channel, $user, $message);
Expand All @@ -154,7 +156,7 @@ public function onMessage(ConnectionInterface $conn, $message)
}

/**
* Subscribe connection to a given channel
* Subscribe connection to a given channel.
*
* @param ConnectionInterface $conn - Active connection
* @param $channel - Channel to subscribe to
Expand All @@ -175,7 +177,7 @@ private function subscribeToChannel(ConnectionInterface $conn, $channel, $user)
}

/**
* Unsubscribe connection to a given channel
* Unsubscribe connection to a given channel.
*
* @param ConnectionInterface $conn - Active connection
* @param $channel - Channel to unsubscribe from
Expand All @@ -184,7 +186,7 @@ private function subscribeToChannel(ConnectionInterface $conn, $channel, $user)
private function unsubscribeFromChannel(ConnectionInterface $conn, $channel, $user)
{
// Check connection
if (array_key_exists($channel, $this->users[$conn->resourceId]['channels'])) {
if (\array_key_exists($channel, $this->users[$conn->resourceId]['channels'])) {
// Delete connection
unset($this->users[$conn->resourceId]['channels']);
}
Expand All @@ -199,14 +201,14 @@ private function unsubscribeFromChannel(ConnectionInterface $conn, $channel, $us
}

/**
* Send message to all connections of a given channel
* Send message to all connections of a given channel.
*
* @param ConnectionInterface $conn - Active connection
* @param $channel - Channel to send message to
* @param $user - User's username
* @param $message - User's message
*
* @return boolean - False if channel doesn't exists
* @return bool - False if channel doesn't exists
*/
private function sendMessageToChannel(ConnectionInterface $conn, $channel, $user, $message)
{
Expand All @@ -219,12 +221,12 @@ private function sendMessageToChannel(ConnectionInterface $conn, $channel, $user
// Loop to send message to all users
foreach ($this->users as $connectionId => $userConnection) {
// Check if user has subscribe to channel
if (array_key_exists($channel, $userConnection['channels'])) {
if (\array_key_exists($channel, $userConnection['channels'])) {
$userConnection['connection']->send(json_encode([
'action' => 'message',
'channel' => $channel,
'user' => $user,
'message' => $message
'message' => $message,
]));
}
}
Expand Down

0 comments on commit 5d6dfa9

Please sign in to comment.