Passed
Push — master ( ddad46...023bbd )
by Thierry
02:38
created

AjaxSendTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sendResponse() 0 24 4
1
<?php
2
3
/**
4
 * AjaxSendTrait.php
5
 *
6
 * Send Jaxon ajax response.
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Jared White
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
10
 * @author J. Max Wilson
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
11
 * @author Thierry Feuzeu
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
12
 * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
13
 * @copyright 2022 Thierry Feuzeu <[email protected]>
14
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
15
 * @link https://github.com/jaxon-php/jaxon-core
16
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
17
18
namespace Jaxon\App\Traits;
19
20
use Jaxon\Exception\RequestException;
21
22
use function gmdate;
23
use function header;
24
use function headers_sent;
25
26
trait AjaxSendTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AjaxSendTrait
Loading history...
27
{
28
    /**
29
     * Prints the response to the output stream, thus sending the response to the browser
30
     *
31
     * @return void
32
     * @throws RequestException
33
     */
34
    public function sendResponse()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
35
    {
36
        // Check to see if headers have already been sent out, in which case we can't do our job
37
        if(headers_sent($sFilename, $nLineNumber))
38
        {
39
            throw new RequestException($this->xTranslator->trans('errors.output.already-sent',
40
                    ['location' => $sFilename . ':' . $nLineNumber]) . "\n" .
41
                $this->xTranslator->trans('errors.output.advice'));
42
        }
43
        if(empty($sContent = $this->xResponseManager->getOutput()))
0 ignored issues
show
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
44
        {
45
            return;
46
        }
47
48
        if($this->di()->getRequest()->getMethod() === 'GET')
0 ignored issues
show
Bug introduced by
It seems like di() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

48
        if($this->/** @scrutinizer ignore-call */ di()->getRequest()->getMethod() === 'GET')
Loading history...
49
        {
50
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
51
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
52
            header("Cache-Control: no-cache, must-revalidate");
53
            header("Pragma: no-cache");
54
        }
55
        header('content-type: ' . $this->xResponseManager->getContentType());
56
57
        print $sContent;
58
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
59
}
60