Issues (48)

library/Trapdirector/Rest/RestAPI.php (1 issue)

1
<?php
2
3
4
5
namespace Icinga\Module\Trapdirector\Rest;
6
7
use Icinga\Module\Trapdirector\TrapsController;
8
9
use RuntimeException;
10
use Exception;
11
use Icinga\Web\Request;
12
use Icinga\Web\Response;
13
14
15
class RestAPI
16
{
17
    public $version=1;
18
    
19
    /**
20
     * @var TrapsController $trapController
21
     */
22
    protected $trapController=null;
23
    
24
    public function __construct(TrapsController $trapCtrl)
25
    {
26
        $this->trapController=$trapCtrl;
27
    }
28
    
29
    public function sendJson($object)
30
    {
31
        $this->trapController->getResponse()->setHeader('Content-Type', 'application/json', true);        
32
        $this->trapController->getResponse()->sendHeaders();
33
        $this->trapController->helper_ret(json_encode($object, JSON_PRETTY_PRINT));
34
        //$this->trapController->_helper->json($object);
35
        //echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
36
    }
37
    
38
    protected function sendJsonError(string $error, int $retCode = 200)
0 ignored issues
show
The parameter $retCode is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

38
    protected function sendJsonError(string $error, /** @scrutinizer ignore-unused */ int $retCode = 200)

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

Loading history...
39
    {
40
        //TODO
41
        $this->sendJson('{"Error":"'.$error.'"}');
42
    }
43
    
44
    public function last_modified()
45
    {
46
        try 
47
        {
48
            $query = $this->trapController->getUIDatabase()->lastModification();
49
            return array('lastModified' => $query);
50
        } 
51
        catch (\ErrorException $e) 
52
        {
53
            return array('Error' =>  $e->getMessage());
54
        }
55
    }
56
}