ServiceHttpTransport::createSession()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Service\ServiceHttpTransport;
3
4
use Mezon\Service\Transport;
5
use Mezon\Transport\RequestParamsInterface;
6
use Mezon\Transport\HttpRequestParams;
7
use Mezon\Service\ServiceBaseLogicInterface;
8
9
/**
10
 * Class ServiceHttpTransport
11
 *
12
 * @package Service
13
 * @subpackage ServiceHttpTransport
14
 * @author Dodonov A.A.
15
 * @version v.1.0 (2019/08/13)
16
 * @copyright Copyright (c) 2019, aeon.org
17
 */
18
19
/**
20
 * HTTP transport for all services
21
 *
22
 * @author Dodonov A.A.
23
 */
24
class ServiceHttpTransport extends Transport
25
{
26
27
    /**
28
     * Method creates session from existing token or fetched from HTTP headers
29
     *
30
     * @param string $token
31
     *            session token
32
     * @return string session token
33
     */
34
    public function createSession(string $token): string
35
    {
36
        return $this->getSecurityProvider()->createSession($token);
37
    }
38
39
    /**
40
     * Method creates parameters fetcher
41
     *
42
     * @return RequestParamsInterface paremeters fetcher
43
     */
44
    public function createFetcher(): RequestParamsInterface
45
    {
46
        return new HttpRequestParams($this->getRouter());
47
    }
48
49
    /**
50
     * Method outputs HTTP header
51
     *
52
     * @param string $header
53
     *            header name
54
     * @param string $value
55
     *            header value
56
     * @codeCoverageIgnore
57
     */
58
    protected function header(string $header, string $value): void
59
    {
60
        @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

60
        /** @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...
61
    }
62
63
    /**
64
     * Method runs logic functions
65
     *
66
     * @param ServiceBaseLogicInterface $serviceLogic
67
     *            object with all service logic
68
     * @param string $method
69
     *            logic's method to be executed
70
     * @param array $params
71
     *            logic's parameters
72
     * @return mixed Result of the called method
73
     */
74
    public function callLogic(ServiceBaseLogicInterface $serviceLogic, string $method, array $params = [])
75
    {
76
        $this->header('Content-Type', 'text/html; charset=utf-8');
77
78
        return parent::callLogic($serviceLogic, $method, $params);
79
    }
80
81
    /**
82
     * Method runs logic functions
83
     *
84
     * @param ServiceBaseLogicInterface $serviceLogic
85
     *            object with all service logic
86
     * @param string $method
87
     *            logic's method to be executed
88
     * @param array $params
89
     *            logic's parameters
90
     * @return mixed Result of the called method
91
     */
92
    public function callPublicLogic(
93
        ServiceBaseLogicInterface $serviceLogic,
94
        string $method,
95
        array $params = [])
96
    {
97
        $this->header('Content-Type', 'text/html; charset=utf-8');
98
99
        return parent::callPublicLogic($serviceLogic, $method, $params);
100
    }
101
102
    /**
103
     * Method outputs exception data
104
     *
105
     * @param array $e
106
     *            exception data
107
     */
108
    public function outputException(array $e): void
109
    {
110
        $this->header('Content-Type', 'text/html; charset=utf-8');
111
112
        print(json_encode($e));
113
    }
114
}
115