MessageType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 70
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 12 1
B store() 0 43 3
1
<?php
2
3
class MessageType extends \BaseController {
4
5
    /**
6
     * Display a listing of messages.
7
     *
8
     * @return Response
9
     */
10
    public function index() {
11
$message='typing';
12
       $data = array(
13
            'room'        => Input::get('conversation'),
0 ignored issues
show
Bug introduced by
The type Input was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
            'message'  => array( 'body' => Str::words($message, 5), 'user_id' => '')
0 ignored issues
show
Bug introduced by
The type Str was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
        );
16
17
        Event::fire(ChatMessagesEventHandler::EVENT, array(json_encode($data)));
18
19
        return Response::json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return Response::json(ar... 'result' => $message)) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Response.
Loading history...
20
            'success' => true,
21
            'result' => $message
22
        ]);
23
    }
24
25
    /**
26
     * Store a newly created message in storage.
27
     *
28
     * @return Response
29
     */
30
    public function store() {
31
32
        $rules     = array('body' => 'required');
33
        $validator = Validator::make(Input::all(), $rules);
34
35
        if($validator->fails()) {
36
            return Response::json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return Response::json(ar...validator->messages())) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Response.
Loading history...
37
                'success' => false,
38
                'result' => $validator->messages()
39
            ]);
40
        }
41
42
        $conversation = Conversation::where('name', Input::get('conversation'))->first();
43
44
        $params = array(
45
            'conversation_id' => $conversation->id,
46
            'body'               => Input::get('body'),
47
            'user_id'           => Input::get('user_id'),
48
            'created_at'      => new DateTime
49
        );
50
51
        $message = Message::create($params);
52
53
        // Create Message Notifications
54
        $messages_notifications = array();
55
56
        foreach($conversation->users()->get() as $user) {
57
            array_push($messages_notifications, new MessageNotification(array('user_id' => $user->id, 'conversation_id' => $conversation->id, 'read' => false)));
0 ignored issues
show
Bug introduced by
The type MessageNotification was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
        }
59
60
        $message->messages_notifications()->saveMany($messages_notifications);
61
62
        // Publish Data To Redis
63
        $data = array(
64
            'room'        => Input::get('conversation'),
65
            'message'  => array( 'body' => Str::words($message->body, 5), 'user_id' => Input::get('user_id'))
66
        );
67
68
        Event::fire(ChatMessagesEventHandler::EVENT, array(json_encode($data)));
69
70
        return Response::json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return Response::json(ar... 'result' => $message)) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Response.
Loading history...
71
            'success' => true,
72
            'result' => $message
73
        ]);
74
    }
75
}
76