Completed
Push — master ( 541b76...aec89b )
by Henry
05:33
created

includes/Client/ClientAbstract.php (1 issue)

Upgrade to new PHP Analysis Engine

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
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 78
	 *
45
	 * @since 2.4.0
46 78
	 *
47 78
	 * @param Request $request instance of the request class
48 78
	 */
49
50
	public function __construct(Request $request)
51
	{
52
		$this->_request = $request;
53
		$this->_autorun();
54
	}
55
56
	/**
57
	 * get the output
58 78
	 *
59
	 * @since 2.4.0
60 78
	 *
61
	 * @return string|null
62
	 */
63
64
	public function getOutput() : ?string
65
	{
66
		return $this->_output;
67
	}
68
69
	/**
70
	 * detect the required type
71
	 *
72 78
	 * @since 2.4.0
73
	 *
74 78
	 * @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)
79
	{
80 78
		$userAgent = strtolower($this->_request->getServer('HTTP_USER_AGENT'));
81
82
		/* process setup */
83
84 55
		foreach ($setupArray as $value)
85
		{
86
			if (stristr($userAgent, $value))
87
			{
88 55
				/* general */
89
90 78
				$this->_output = $value;
91
92
				/* version */
93
94 78
				if ($type === 'version')
95
				{
96
					$this->_output = floor(substr($userAgent, strpos($userAgent, $value) + strlen($value) + 1, 3));
0 ignored issues
show
Documentation Bug introduced by
The property $_output was declared of type string, but \floor(\substr($userAgen...strlen($value) + 1, 3)) is of type double. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
97
				}
98
			}
99
		}
100
	}
101
}
102