<commit_before><?php
/**
 * This file is part of the ua-device-type package.
 *
 * Copyright (c) 2015-2017, <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types = 1);
namespace UaDeviceType;

use BrowserDetector\Loader\LoaderInterface;
use BrowserDetector\Loader\NotFoundException;

/**
 * Browser detection class
 *
 * @category  BrowserDetector
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012-2016 <NAME>
 * @license   http://www.opensource.org/licenses/MIT MIT License
 */
class TypeLoader implements LoaderInterface
{
    /**
     * @var \StdClass[]
     */
    private $types = [];

    /**
     * @var self|null
     */
    private static $instance;

    /**
     * @return self
     */
    private function __construct()
    {
        // nothing to do here
    }

    /**
     * @return self
     */
    public static function getInstance()
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * @return void
     */
    public static function resetInstance(): void
    {
        self::$instance = null;
    }

    /**
     * @param string $key
     *
     * @return bool
     */
    public function has(string $key): bool
    {
        $this->init();

        return array_key_exists($key, $this->types);
    }

    /**
     * @param string $key
     *
     * @throws \BrowserDetector\Loader\NotFoundException
     *
     * @return \UaDeviceType\TypeInterface
     */
    public function load(string $key): TypeInterface
    {
        $this->init();

        if (!$this->has($key)) {
            throw new NotFoundException('the device type with key "' . $key . '" was not found');
        }

        $type = $this->types[$key];

        return new Type(
            $type->type,
            $type->name,
            $type->mobile,
            $type->desktop,
            $type->console,
            $type->tv,
            $type->phone,
            $type->tablet
        );
    }

    /**
     * initializes cache
     *
     * @return void
     */
    private function init(): void
    {
        $this->types = [];

        foreach ($this->getTypes() as $key => $data) {
            $this->types[$key] = $data;
        }
    }

    /**
     * @return \Generator|\stdClass[]
     */
    private function getTypes(): \Generator
    {
        static $types = null;

        if (null === $types) {
            $types = json_decode(file_get_contents(__DIR__ . '/../data/types.json'), false);
        }

        foreach ($types as $key => $data) {
            yield $key => $data;
        }
    }
}
<commit_msg>fix var type<commit_after><?php
/**
 * This file is part of the ua-device-type package.
 *
 * Copyright (c) 2015-2017, <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types = 1);
namespace UaDeviceType;

use BrowserDetector\Loader\LoaderInterface;
use BrowserDetector\Loader\NotFoundException;

/**
 * Browser detection class
 *
 * @category  BrowserDetector
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012-2016 <NAME>
 * @license   http://www.opensource.org/licenses/MIT MIT License
 */
class TypeLoader implements LoaderInterface
{
    /**
     * @var \stdClass[]
     */
    private $types = [];

    /**
     * @var self|null
     */
    private static $instance;

    /**
     * @return self
     */
    private function __construct()
    {
        // nothing to do here
    }

    /**
     * @return self
     */
    public static function getInstance()
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * @return void
     */
    public static function resetInstance(): void
    {
        self::$instance = null;
    }

    /**
     * @param string $key
     *
     * @return bool
     */
    public function has(string $key): bool
    {
        $this->init();

        return array_key_exists($key, $this->types);
    }

    /**
     * @param string $key
     *
     * @throws \BrowserDetector\Loader\NotFoundException
     *
     * @return \UaDeviceType\TypeInterface
     */
    public function load(string $key): TypeInterface
    {
        $this->init();

        if (!$this->has($key)) {
            throw new NotFoundException('the device type with key "' . $key . '" was not found');
        }

        $type = $this->types[$key];

        return new Type(
            $type->type,
            $type->name,
            $type->mobile,
            $type->desktop,
            $type->console,
            $type->tv,
            $type->phone,
            $type->tablet
        );
    }

    /**
     * initializes cache
     *
     * @return void
     */
    private function init(): void
    {
        $this->types = [];

        foreach ($this->getTypes() as $key => $data) {
            $this->types[$key] = $data;
        }
    }

    /**
     * @return \Generator|\stdClass[]
     */
    private function getTypes(): \Generator
    {
        static $types = null;

        if (null === $types) {
            $types = json_decode(file_get_contents(__DIR__ . '/../data/types.json'), false);
        }

        foreach ($types as $key => $data) {
            yield $key => $data;
        }
    }
}

{'fraction_non_alphanumeric': 0.1439795359035264, 'fraction_numerical': 0.006212315000913576, 'mean_word_length': 1.7576826196473552, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 55, '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': '4581870', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1588, 'n_words': 390}