These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Client; |
||
3 | |||
4 | use Redaxscript\Request; |
||
5 | |||
6 | /** |
||
7 | * abstract class to create a client class |
||
8 | * |
||
9 | * @since 2.4.0 |
||
10 | * |
||
11 | * @package Redaxscript |
||
12 | * @category Client |
||
13 | * @author Henry Ruhs |
||
14 | * |
||
15 | * @method protected _autorun() |
||
16 | */ |
||
17 | |||
18 | abstract class ClientAbstract |
||
19 | { |
||
20 | /** |
||
21 | * instance of the request class |
||
22 | * |
||
23 | * @var Request |
||
24 | */ |
||
25 | |||
26 | protected $_request; |
||
27 | |||
28 | /** |
||
29 | * output of the client |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | |||
34 | protected $_output; |
||
35 | |||
36 | /** |
||
37 | * constructor of the class |
||
38 | * |
||
39 | * @since 2.4.0 |
||
40 | * |
||
41 | * @param Request $request instance of the request class |
||
42 | */ |
||
43 | |||
44 | 78 | public function __construct(Request $request) |
|
45 | { |
||
46 | 78 | $this->_request = $request; |
|
47 | 78 | $this->_autorun(); |
|
48 | 78 | } |
|
49 | |||
50 | /** |
||
51 | * get the output |
||
52 | * |
||
53 | * @since 2.4.0 |
||
54 | * |
||
55 | * @return string|null |
||
56 | */ |
||
57 | |||
58 | 78 | public function getOutput() : ?string |
|
59 | { |
||
60 | 78 | return $this->_output; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * detect the required type |
||
65 | * |
||
66 | * @since 2.4.0 |
||
67 | * |
||
68 | * @param array $setupArray array of client setup |
||
69 | * @param string $type type of the client |
||
70 | */ |
||
71 | |||
72 | 78 | protected function _detect(array $setupArray = [], string $type = null) |
|
73 | { |
||
74 | 78 | $userAgent = strtolower($this->_request->getServer('HTTP_USER_AGENT')); |
|
75 | |||
76 | /* process setup */ |
||
77 | |||
78 | 78 | foreach ($setupArray as $value) |
|
79 | { |
||
80 | 78 | if (stristr($userAgent, $value)) |
|
81 | { |
||
82 | /* general */ |
||
83 | |||
84 | 55 | $this->_output = $value; |
|
85 | |||
86 | /* version */ |
||
87 | |||
88 | 55 | if ($type === 'version') |
|
89 | { |
||
90 | 78 | $this->_output = floor(substr($userAgent, strpos($userAgent, $value) + strlen($value) + 1, 3)); |
|
0 ignored issues
–
show
|
|||
91 | } |
||
92 | } |
||
93 | } |
||
94 | 78 | } |
|
95 | } |
||
96 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.