Completed
Push — master ( 3bdd73...3b96a7 )
by Ankit
02:28
created

Receiver::receiverLoad()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace ChatApp;
4
require_once (dirname(__DIR__) . '/vendor/autoload.php');
5
use ChatApp\User;
6
use ChatApp\Session;
7
use ChatApp\Conversation;
8
use Dotenv\Dotenv;
9
$dotenv = new Dotenv(dirname(__DIR__));
10
$dotenv->load();
11
12
13
/**
14
*
15
*/
16
class Receiver
17
{
18
    protected $ob;
19
    protected $conversation;
20
    protected $messages;
21
22
    public function __construct($sessionId)
23
    {
24
        session_id($sessionId);
25
        @session_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
26
        session_write_close();
27
        $this->ob = new User();
28
        $this->conversation = new Conversation($sessionId);
29
    }
30
31
    public function receiverLoad($msg)
32
    {
33
        $id2 = Session::get('start');
34
        $this->messages = $this->ob->userDetails($id2, True);
35
        $username = $this->messages['username'];
36
        $name = $this->messages['name'];
37
        $this->messages = json_decode($this->conversation->conversationLoad($msg, True));
38
        $id = json_decode($msg)->username;
39
        for ($i=1 ; $i < count($this->messages); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
40
            $this->messages[$i]->start = $id;
41
        }
42
        $this->messages[0]->username = $username;
43
        $this->messages[0]->name = $name;
44
        $this->messages[0]->id = $id2;
45
        return json_encode($this->messages);
46
    }
47
}
48