Conditions | 4 |
Paths | 5 |
Total Lines | 52 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
43 | protected function execute(InputInterface $input, OutputInterface $output) |
||
44 | { |
||
45 | // Make sure that websockets are enabled in the config so that the proper |
||
46 | // session storage handler is used |
||
47 | if (!$this->getContainer()->getParameter('bzion.features.websocket.enabled')) { |
||
48 | $message = "You need to enable websockets in your config before using the push server"; |
||
49 | $output->writeln("<bg=red;options=bold>\n\n [ERROR] $message\n</>"); |
||
50 | |||
51 | return; |
||
52 | } |
||
53 | |||
54 | $loop = EventLoopFactory::create(); |
||
55 | $pusher = new EventPusher($loop, $output); |
||
56 | |||
57 | $pushPort = ($input->getOption('push')) ?: $this->getContainer() |
||
58 | ->getParameter('bzion.features.websocket.push_port'); |
||
59 | |||
60 | $pullPort = ($input->getOption('pull')) ?: $this->getContainer() |
||
61 | ->getParameter('bzion.features.websocket.pull_port'); |
||
62 | |||
63 | $pullSocket = new Server($loop); |
||
64 | $pullSocket->on('connection', function ($conn) use ($pusher) { |
||
65 | $conn->on('data', function ($data) use ($pusher) { |
||
66 | $pusher->onServerEvent(json_decode($data)); |
||
67 | }); |
||
68 | }); |
||
69 | |||
70 | // Bind to 127.0.0.1, so that only the server can send messages to the socket |
||
71 | $pullSocket->listen($pullPort, '127.0.0.1'); |
||
72 | $output->writeln(" <fg=green>Running pull service on port $pullPort</>"); |
||
73 | |||
74 | $session = new SessionProvider( |
||
75 | $pusher, |
||
76 | new DatabaseSessionHandler() |
||
77 | ); |
||
78 | |||
79 | $pushSocket = new Server($loop); |
||
80 | |||
81 | $webServer = new IoServer( |
||
|
|||
82 | new WsServer( |
||
83 | $session |
||
84 | ), |
||
85 | $pushSocket |
||
86 | ); |
||
87 | |||
88 | // Binding to 0.0.0.0 means remotes can connect |
||
89 | $pushSocket->listen($pushPort, '0.0.0.0'); |
||
90 | $output->writeln(" <fg=green>Running push service on port $pushPort</>"); |
||
91 | |||
92 | $output->writeln("\n <bg=green;options=bold>Welcome to the BZiON live notification server!</>"); |
||
93 | $loop->run(); |
||
94 | } |
||
95 | } |
||
96 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.