Receiver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A receiverLoad() 0 24 2
1
<?php
2
/**
3
 * Receiver Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
15
require_once dirname(__DIR__).'/vendor/autoload.php';
16
use ChatApp\User;
17
use ChatApp\Conversation;
18
use mysqli;
19
use Dotenv\Dotenv;
20
$dotenv = new Dotenv(dirname(__DIR__));
21
$dotenv->load();
22
23
/**
24
 * Send message to other user
25
 *
26
 * @category PHP
27
 * @package  OpenChat
28
 * @author   Ankit Jain <[email protected]>
29
 * @license  The MIT License (MIT)
30
 * @link     https://github.com/ankitjain28may/openchat
31
 */
32
class Receiver
33
{
34
    /*
35
    |--------------------------------------------------------------------------
36
    | Receiver Class
37
    |--------------------------------------------------------------------------
38
    |
39
    | Send message to other user.
40
    |
41
    */
42
43
    protected $obUser;
44
    protected $conversation;
45
    protected $messages;
46
47
    /**
48
     * Create a new class instance.
49
     *
50
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
51
     */
52
    public function __construct()
53
    {
54
        $this->obUser = new User();
55
        $this->conversation = new Conversation();
56
    }
57
58
    /**
59
     * Swaping value of conversation class to modify them for receiver
60
     *
61
     * @param string  $msg  To store message
62
     * @param boolean $para To store True/False
63
     *
64
     * @return string
65
     */
66
    public function receiverLoad($msg, $para)
67
    {
68
        $msg = json_decode($msg);
69
        $id2 = $msg->userId;
70
        $this->messages = $this->obUser->userDetails($id2, $para);
0 ignored issues
show
Documentation introduced by
$para is of type boolean, but the function expects a object<ChatApp\boollen>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
        $username = $this->messages['username'];
72
        $name = $this->messages['name'];
73
        $id1 = $msg->details;
74
        $msg->details = bin2hex(convert_uuencode($msg->details));
75
        $msg = json_encode($msg);
76
        $this->messages = json_decode(
77
            $this->conversation->conversationLoad($msg, $para)
78
        );
79
        // $id1 = json_decode($msg)->details;
80
        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...
81
            $this->messages[$i]->start = $id1;
82
        }
83
        $id2 = bin2hex(convert_uuencode($id2));
84
85
        $this->messages[0]->username = $username;
86
        $this->messages[0]->name = $name;
87
        $this->messages[0]->id = $id2;
88
        return json_encode($this->messages);
89
    }
90
}
91