1<?php
2
3/**
4 * Device Detector - The Universal Device Detection library for parsing User Agents
5 *
6 * @link https://matomo.org
7 *
8 * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
9 */
10
11declare(strict_types=1);
12
13namespace DeviceDetector\Parser\Device;
14
15/**
16 * Class ShellTv
17 */
18class ShellTv extends AbstractDeviceParser
19{
20    /**
21     * @var string
22     */
23    protected $fixtureFile = 'regexes/device/shell_tv.yml';
24
25    /**
26     * @var string
27     */
28    protected $parserName = 'shelltv';
29
30    /**
31     * Returns if the parsed UA was identified as ShellTv device
32     *
33     * @return bool
34     *
35     * @throws \Exception
36     */
37    public function isShellTv(): bool
38    {
39        $regex = '[a-z]+[ _]Shell[ _]\w{6}|tclwebkit(\d+[.\d]*)';
40        $match = $this->matchUserAgent($regex);
41
42        return null !== $match;
43    }
44
45    /**
46     * Parses the current UA and checks whether it contains ShellTv information
47     *
48     * @see shell_tv.yml for list of detected televisions
49     *
50     * @return array|null
51     */
52    public function parse(): ?array
53    {
54        // only parse user agents containing fragments: {brand} shell
55        if (false === $this->isShellTv()) {
56            return null;
57        }
58
59        parent::parse();
60
61        // always set device type to tv, even if no model/brand could be found
62        $this->deviceType = self::DEVICE_TYPE_TV;
63
64        return $this->getResult();
65    }
66}
67