1 | <?php |
||
16 | final class Browscap implements BrowscapInterface |
||
17 | { |
||
18 | /** |
||
19 | * Parser to use |
||
20 | * |
||
21 | * @var \BrowscapPHP\Parser\ParserInterface|null |
||
22 | */ |
||
23 | private $parser; |
||
24 | |||
25 | /** |
||
26 | * Formatter to use |
||
27 | * |
||
28 | * @var \BrowscapPHP\Formatter\FormatterInterface|null |
||
29 | */ |
||
30 | private $formatter; |
||
31 | |||
32 | /** |
||
33 | * The cache instance |
||
34 | * |
||
35 | * @var \BrowscapPHP\Cache\BrowscapCacheInterface |
||
36 | */ |
||
37 | private $cache; |
||
38 | |||
39 | /** |
||
40 | * @var \Psr\Log\LoggerInterface|null |
||
41 | */ |
||
42 | private $logger; |
||
43 | |||
44 | /** |
||
45 | * Browscap constructor. |
||
46 | * |
||
47 | * @param \Psr\SimpleCache\CacheInterface $cache |
||
48 | * @param LoggerInterface $logger |
||
49 | */ |
||
50 | 7 | public function __construct(CacheInterface $cache, LoggerInterface $logger) |
|
55 | |||
56 | /** |
||
57 | * Set theformatter instance to use for the getBrowser() result |
||
58 | * |
||
59 | * @param \BrowscapPHP\Formatter\FormatterInterface $formatter |
||
60 | */ |
||
61 | 5 | public function setFormatter(Formatter\FormatterInterface $formatter) : void |
|
65 | |||
66 | /** |
||
67 | * @return \BrowscapPHP\Formatter\FormatterInterface |
||
68 | */ |
||
69 | 3 | public function getFormatter() : FormatterInterface |
|
77 | |||
78 | /** |
||
79 | * Sets the parser instance to use |
||
80 | * |
||
81 | * @param \BrowscapPHP\Parser\ParserInterface $parser |
||
82 | */ |
||
83 | 4 | public function setParser(ParserInterface $parser) : void |
|
87 | |||
88 | /** |
||
89 | * returns an instance of the used parser class |
||
90 | * |
||
91 | * @return \BrowscapPHP\Parser\ParserInterface |
||
92 | */ |
||
93 | 5 | public function getParser() : ParserInterface |
|
104 | |||
105 | /** |
||
106 | * parses the given user agent to get the information about the browser |
||
107 | * |
||
108 | * if no user agent is given, it uses {@see \BrowscapPHP\Helper\Support} to get it |
||
109 | * |
||
110 | * @param string $userAgent the user agent string |
||
111 | * |
||
112 | * @throws \BrowscapPHP\Exception |
||
113 | * @return \stdClass the object containing the browsers details. Array if |
||
114 | * $return_array is set to true. |
||
115 | */ |
||
116 | 4 | public function getBrowser(string $userAgent = null) : \stdClass |
|
140 | } |
||
141 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: