Completed
Push — master ( b58d6f...91dfa3 )
by Alex
03:06
created

ServiceHttpTransport::sessionStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace Mezon\Service\ServiceHttpTransport;
3
4
/**
5
 * Class ServiceHttpTransport
6
 *
7
 * @package Service
8
 * @subpackage ServiceHttpTransport
9
 * @author Dodonov A.A.
10
 * @version v.1.0 (2019/08/13)
11
 * @copyright Copyright (c) 2019, aeon.org
12
 */
13
14
/**
15
 * HTTP transport for all services
16
 *
17
 * @author Dodonov A.A.
18
 */
19
class ServiceHttpTransport extends \Mezon\Service\ServiceTransport
20
{
21
22
    /**
23
     * Method creates session from existing token or fetched from HTTP headers
24
     *
25
     * @param string $token
26
     *            Session token
27
     * @return string Session token
28
     */
29
    public function createSession(string $token): string
30
    {
31
        return $this->getSecurityProvider()->createSession($token);
32
    }
33
34
    /**
35
     * Method creates parameters fetcher
36
     *
37
     * @return \Mezon\Service\ServiceRequestParamsInterface paremeters fetcher
38
     */
39
    public function createFetcher(): \Mezon\Service\ServiceRequestParamsInterface
40
    {
41
        return new \Mezon\Service\ServiceHttpTransport\HttpRequestParams($this->getRouter());
42
    }
43
44
    /**
45
     * Method outputs HTTP header
46
     *
47
     * @param string $header
48
     *            Header name
49
     * @param string $value
50
     *            Header value
51
     * @codeCoverageIgnore
52
     */
53
    protected function header(string $header, string $value)
54
    {
55
        @header($header . ':' . $value);
0 ignored issues
show
Bug introduced by
Are you sure the usage of header($header . ':' . $value) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for header(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

55
        /** @scrutinizer ignore-unhandled */ @header($header . ':' . $value);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
56
    }
57
58
    /**
59
     * Method runs logic functions
60
     *
61
     * @param \Mezon\Service\ServiceBaseLogicInterface $serviceLogic
62
     *            object with all service logic
63
     * @param string $method
64
     *            logic's method to be executed
65
     * @param array $params
66
     *            logic's parameters
67
     * @return mixed Result of the called method
68
     */
69
    public function callLogic(\Mezon\Service\ServiceBaseLogicInterface $serviceLogic, string $method, array $params = [])
70
    {
71
        $this->header('Content-Type', 'text/html; charset=utf-8');
72
73
        return parent::callLogic($serviceLogic, $method, $params);
74
    }
75
76
    /**
77
     * Method runs logic functions
78
     *
79
     * @param \Mezon\Service\ServiceBaseLogicInterface $serviceLogic
80
     *            object with all service logic
81
     * @param string $method
82
     *            logic's method to be executed
83
     * @param array $params
84
     *            logic's parameters
85
     * @return mixed Result of the called method
86
     */
87
    public function callPublicLogic(
88
        \Mezon\Service\ServiceBaseLogicInterface $serviceLogic,
89
        string $method,
90
        array $params = [])
91
    {
92
        $this->header('Content-Type', 'text/html; charset=utf-8');
93
94
        return parent::callPublicLogic($serviceLogic, $method, $params);
95
    }
96
97
    /**
98
     * Method outputs exception data
99
     *
100
     * @param array $e
101
     *            exception data
102
     */
103
    public function outputException(array $e): void
104
    {
105
        $this->header('Content-Type', 'text/html; charset=utf-8');
106
107
        print(json_encode($e));
108
    }
109
}
110