<commit_before><?php

/**
 * Widget Framework
 *
 * @copyright   Copyright (c) 2008-2013 <NAME>
 * @license     http://www.opensource.org/licenses/apache2.0.php Apache License
 */

namespace Widget;

/**
 * Browser
 *
 * @package     Widget
 * @author      <NAME> <<EMAIL>>
 * @property \Widget\Server $server The server widget
 */
class Browser extends WidgetProvider
{
    /**
     * Whether in chrome browser
     *
     * @var bool
     */
    public $chrome = false;

    /**
     * Whether in webkit browser
     *
     * @var bool
     */
    public $webkit = false;

    /**
     * Whether in opera browser
     *
     * @var bool
     */
    public $opera = false;

    /**
     * Whether in internet explorer browser
     *
     * @var bool
     */
    public $msie = false;

    /**
     * Whether in firefox browser
     *
     * @var bool
     */
    public $mozilla = false;

    /**
     * Whether in safari browser
     *
     * @var bool
     */
    public $safari = false;

    /**
     * The name of browser
     *
     * @var type
     */
    public $name;

    /**
     * The version of browser
     *
     * @var string
     */
    public $version;

    /**
     * Constructor
     *
     * @param array $options
     */
    public function __construct(array $options = array())
    {
        parent::__construct($options);

        $this->detect();
    }

    /**
     * Get the name of browser
     *
     * @return string
     */
    public function __invoke()
    {
        return $this->name;
    }

    /**
     * Detect the browser name and version
     *
     * @link http://api.jquery.com/jQuery.browser
     * @copyright Copyright 2012 jQuery Foundation and other contributors
     * @license http://jquery.org/license
     */
    protected function detect()
    {
        $ua = strtolower($this->server['HTTP_USER_AGENT']);
        $matches = array();

        preg_match('/(chrome)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(webkit)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(opera)(?:.*version|)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(msie) ([\w.]+)/', $ua, $matches) ||
            false === strpos($ua, 'compatible') && preg_match('/(mozilla)(?:.*? rv:([\w.]+)|)/', $ua, $matches) ||
            array('', '', 0);

        // Ignore the first element
        list(, $this->name, $this->version) = $matches;

        $this->{$this->name} = true;

        // Chrome is Webkit, but Webkit is also Safari.
        if ($this->chrome) {
            $this->webkit = true;
        } elseif ($this->webkit) {
            $this->safari = true;
        }
    }<commit_msg>added detect for browser, avoid error when the name property is empty<commit_after><?php

/**
 * Widget Framework
 *
 * @copyright   Copyright (c) 2008-2013 <NAME>
 * @license     http://www.opensource.org/licenses/apache2.0.php Apache License
 */

namespace Widget;

/**
 * Browser
 *
 * @package     Widget
 * @author      <NAME> <<EMAIL>>
 * @property \Widget\Server $server The server widget
 */
class Browser extends WidgetProvider
{
    /**
     * Whether in chrome browser
     *
     * @var bool
     */
    public $chrome = false;

    /**
     * Whether in webkit browser
     *
     * @var bool
     */
    public $webkit = false;

    /**
     * Whether in opera browser
     *
     * @var bool
     */
    public $opera = false;

    /**
     * Whether in internet explorer browser
     *
     * @var bool
     */
    public $msie = false;

    /**
     * Whether in firefox browser
     *
     * @var bool
     */
    public $mozilla = false;

    /**
     * Whether in safari browser
     *
     * @var bool
     */
    public $safari = false;

    /**
     * The name of browser
     *
     * @var type
     */
    public $name;

    /**
     * The version of browser
     *
     * @var string
     */
    public $version;

    /**
     * Constructor
     *
     * @param array $options
     */
    public function __construct(array $options = array())
    {
        parent::__construct($options);

        $this->detect();
    }

    /**
     * Get the name of browser
     *
     * @return string
     */
    public function __invoke()
    {
        return $this->name;
    }

    /**
     * Detect the browser name and version
     *
     * @link http://api.jquery.com/jQuery.browser
     * @copyright Copyright 2012 jQuery Foundation and other contributors
     * @license http://jquery.org/license
     */
    protected function detect()
    {
        $ua = strtolower($this->server['HTTP_USER_AGENT']);
        $matches = array();

        preg_match('/(chrome)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(webkit)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(opera)(?:.*version|)[ \/]([\w.]+)/', $ua, $matches) ||
            preg_match('/(msie) ([\w.]+)/', $ua, $matches) ||
            false === strpos($ua, 'compatible') && preg_match('/(mozilla)(?:.*? rv:([\w.]+)|)/', $ua, $matches) ||
            array('', '', 0);

        // Ignore the first element
        list(, $this->name, $this->version) = $matches;

        $this->name && $this->{$this->name} = true;

        // Chrome is Webkit, but Webkit is also Safari.
        if ($this->chrome) {
            $this->webkit = true;
        } elseif ($this->webkit) {
            $this->safari = true;
        }
    }
{'fraction_non_alphanumeric': 0.16737957969127767, 'fraction_numerical': 0.0055793193230425885, 'mean_word_length': 1.7565351101998974, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1642931', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1632, 'n_words': 412}