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 | use function floor; |
||
6 | use function stristr; |
||
7 | use function strlen; |
||
8 | use function strpos; |
||
9 | use function strtolower; |
||
10 | use function substr; |
||
11 | |||
12 | /** |
||
13 | * abstract class to create a client class |
||
14 | * |
||
15 | * @since 2.4.0 |
||
16 | * |
||
17 | * @package Redaxscript |
||
18 | * @category Client |
||
19 | * @author Henry Ruhs |
||
20 | * |
||
21 | * @method protected autorun() |
||
22 | */ |
||
23 | |||
24 | abstract class ClientAbstract implements ClientInterface |
||
25 | { |
||
26 | /** |
||
27 | * instance of the request class |
||
28 | * |
||
29 | * @var Request |
||
30 | */ |
||
31 | |||
32 | protected $_request; |
||
33 | |||
34 | /** |
||
35 | * output of the client |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | |||
40 | protected $_output; |
||
41 | |||
42 | /** |
||
43 | * constructor of the class |
||
44 | * |
||
45 | * @since 2.4.0 |
||
46 | * |
||
47 | * @param Request $request instance of the request class |
||
48 | */ |
||
49 | |||
50 | 78 | public function __construct(Request $request) |
|
51 | { |
||
52 | 78 | $this->_request = $request; |
|
53 | 78 | $this->autorun(); |
|
54 | 78 | } |
|
55 | |||
56 | /** |
||
57 | * get the output |
||
58 | * |
||
59 | * @since 2.4.0 |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | |||
64 | 78 | public function getOutput() : ?string |
|
65 | { |
||
66 | 78 | return $this->_output; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * detect the required type |
||
71 | * |
||
72 | * @since 2.4.0 |
||
73 | * |
||
74 | * @param array $setupArray array of client setup |
||
75 | * @param string $type type of the client |
||
76 | */ |
||
77 | |||
78 | 78 | protected function _detect(array $setupArray = [], string $type = null) : void |
|
79 | { |
||
80 | 78 | $userAgent = strtolower($this->_request->getServer('HTTP_USER_AGENT')); |
|
81 | |||
82 | /* process setup */ |
||
83 | |||
84 | 78 | foreach ($setupArray as $value) |
|
85 | { |
||
86 | 78 | if (stristr($userAgent, $value)) |
|
87 | { |
||
88 | /* general */ |
||
89 | |||
90 | 55 | $this->_output = $value; |
|
91 | |||
92 | /* version */ |
||
93 | |||
94 | 55 | if ($type === 'version') |
|
95 | { |
||
96 | 13 | $this->_output = floor(substr($userAgent, strpos($userAgent, $value) + strlen($value) + 1, 3)); |
|
0 ignored issues
–
show
|
|||
97 | } |
||
98 | } |
||
99 | } |
||
100 | 78 | } |
|
101 | } |
||
102 |
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.