Completed
Push — master ( f2feb8...f0d71d )
by Mehmet
02:58
created

doc.delete.php ➔ app_content()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 26
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 31
c 1
b 0
f 0
nc 12
nop 2
dl 0
loc 26
rs 8.439
1
<?php
2
3
function app_content($request, $args) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
4
5
    global $ES;
6
7
    $index  = $args['index'];
8
    $type   = $args['type'];
9
    $id     = $args['id'];
10
    $params = [];
11
    $params['index'] = $index;
12
    $params['type'] = $type;
13
    $params['id'] = $id;
14
    try {
15
        $result = $ES->delete($params);
16
    } catch (Exception $e) {
17
        /*
18
        If you try to delete a document with an _id that does not exist, $ES->delete throws an Exception.
19
        B/c of default behaviour of reformo/rslim, it bypasses all Exceptions and it returns Exception message.
20
        In this case it returns this message as a plain text json that elasticsearch-php returns.
21
        */
22
        $result = json_decode($e->getMessage(), true);
23
    }
24
    $found = ($result['found'] === true) ? 1 : 0;
25
    sleep(1);
26
    header("location:" . BASE_HREF . "/" . $index . "/" . $type . "?res=success&req=delete&f=".$found);
27
    exit;
28
}