<commit_before><?php
/**
 * PHPSikuliBrowser is an extension to PHPSikuli.
 *
 * @category  PHP
 * @package   php-sikuli
 * @copyright 2013 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/php-sikuli/blob/master/licence.txt BSD Licence
 * @link      https://github.com/squizlabs/php-sikuli
 */

require_once 'PHPSikuli.php';

class PHPSikuliBrowser extends PHPSikuli
{

    /**
     * Browser window range object.
     *
     * @var string
     */
    private $_window = NULL;

    /**
     * Size of the browser window.
     *
     * @var array
     */
    private $_windowSize = NULL;

    /**
     * The browserid.
     *
     * @var string
     */
    private $_browserid = NULL;

    /**
     * The location of the top left corner of the page on the screen.
     *
     * @var array
     */
    private $_pageTopLeft = NULL;

    /**
     * Temporary directory used during script execution.
     *
     * @var string
     */
    private $_tmpDir = NULL;

    /**
     * List of supported browsers.
     *
     * @var array
     */
    private $_supportedBrowsers = array(
                                   'firefox' => 'Firefox',
                                   'chrome'  => 'Google Chrome',
                                   'safari'  => 'Safari',
                                   'ie8'     => 'Internet Explorer 8',
                                   'ie9'     => 'Internet Explorer 9',
                                   'ie10'    => 'Internet Explorer 10',
                                   'ie11'    => 'Internet Explorer 11',
                                  );

    /**
     * Default size of the browser window.
     *
     * @var array
     */
    private $_defaultWindowSize = array(
                                   'w' => 1270,
                                   'h' => 1100,
                                  );

    /**
     * The delay after a mouse click in milliseconds.
     *
     * @var integer
     */
    private $_clickDelay = 0;


    /**
     * Constructor.
     *
     * @param string $browser  The browser to use.
     * @param array  $settings Settings for PHPSikuliBrowser.
     */
    public function __construct($browser, array $settings=array())
    {
        $this->_tmpDir = dirname(__FILE__).'/tmp';
        if (file_exists($this->_tmpDir) === FALSE) {
            mkdir($this->_tmpDir, 0777, TRUE);
        } else {
            $cmd = 'rm -rf '.$this->_tmpDir.'/*';
            exec($cmd);
        }

        chmod($this->_tmpDir, 0777);

        parent::__construct();

        $this->_handleSettings($settings);

        $this->_setBrowser($browser);

    }//end __construct()


    /**
     * Resets the Sikuli connection.
     *
     * @return void
     */
    public function resetConnection()
    {
        $this->stopJSPolling();

        parent::resetConnection();
        $this->_windowSize = NULL;
        $this->_setBrowser($this->_browserid);

    }//end resetConnection()


    /**
     * Reloads the page.
     *
     * @return void
     */
    public function reloadPage()
    {
        $this->stopJSPolling();
        $this->keyDown('Key.CMD + r');

    }//end reloadPage()


    /**
     * Sets the browser URL to the specified URL.
     *
     * @param string $url The new URL.
     *
     * @return void
     */
    public function goToURL($url)
    {
        $this->stopJSPolling();
        $this->keyDown('Key.CMD+l');
        $this->type($url);
        $this->keyDown('Key.ENTER');
        $this->keyDown('Key.ENTER');
        sleep(1);

    }//end goToURL()


    /**
     * Type the text at the current focused input field or at a click point specified by PSMRL.
     *
     * @param string $text      The text to type.
     * @param string $modifiers Key modifiers.
     * @param string $psmrl     PSMRL variable.
     *
     * @return integer
     */
    public function type($text, $modifiers=NULL, $psmrl=NULL)
    {
        // We may need to increase the timeout when typing. It takes about 5s to
        // type 100 characters.
        $length  = strlen($text);
        $timeout = (int) (($length * 5) / 100);

        $currentTimeout = NULL;
        if ($timeout > 10) {
            $timeout       += 5;
            $currentTimeout = $this->sikuli->setSikuliCMDTimeout($timeout);
        }

        $result = parent::type($text, $modifiers, $psmrl);

        if ($timeout > 10) {
            $this->sikuli->setSikuliCMDTimeout($currentTimeout);
        }

        return $result;

    }//end type()


    /**
     * Returns the rectangle for a DOM element found using the specified selector.
     *
     * @param string  $selector The jQuery selector to use for finding the element.
     * @param integer $index    The element index of the resulting array.<commit_msg>Fixed incorrect ref to Sikuli<commit_after><?php
/**
 * PHPSikuliBrowser is an extension to PHPSikuli.
 *
 * @category  PHP
 * @package   php-sikuli
 * @copyright 2013 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/squizlabs/php-sikuli/blob/master/licence.txt BSD Licence
 * @link      https://github.com/squizlabs/php-sikuli
 */

require_once 'PHPSikuli.php';

class PHPSikuliBrowser extends PHPSikuli
{

    /**
     * Browser window range object.
     *
     * @var string
     */
    private $_window = NULL;

    /**
     * Size of the browser window.
     *
     * @var array
     */
    private $_windowSize = NULL;

    /**
     * The browserid.
     *
     * @var string
     */
    private $_browserid = NULL;

    /**
     * The location of the top left corner of the page on the screen.
     *
     * @var array
     */
    private $_pageTopLeft = NULL;

    /**
     * Temporary directory used during script execution.
     *
     * @var string
     */
    private $_tmpDir = NULL;

    /**
     * List of supported browsers.
     *
     * @var array
     */
    private $_supportedBrowsers = array(
                                   'firefox' => 'Firefox',
                                   'chrome'  => 'Google Chrome',
                                   'safari'  => 'Safari',
                                   'ie8'     => 'Internet Explorer 8',
                                   'ie9'     => 'Internet Explorer 9',
                                   'ie10'    => 'Internet Explorer 10',
                                   'ie11'    => 'Internet Explorer 11',
                                  );

    /**
     * Default size of the browser window.
     *
     * @var array
     */
    private $_defaultWindowSize = array(
                                   'w' => 1270,
                                   'h' => 1100,
                                  );

    /**
     * The delay after a mouse click in milliseconds.
     *
     * @var integer
     */
    private $_clickDelay = 0;


    /**
     * Constructor.
     *
     * @param string $browser  The browser to use.
     * @param array  $settings Settings for PHPSikuliBrowser.
     */
    public function __construct($browser, array $settings=array())
    {
        $this->_tmpDir = dirname(__FILE__).'/tmp';
        if (file_exists($this->_tmpDir) === FALSE) {
            mkdir($this->_tmpDir, 0777, TRUE);
        } else {
            $cmd = 'rm -rf '.$this->_tmpDir.'/*';
            exec($cmd);
        }

        chmod($this->_tmpDir, 0777);

        parent::__construct();

        $this->_handleSettings($settings);

        $this->_setBrowser($browser);

    }//end __construct()


    /**
     * Resets the Sikuli connection.
     *
     * @return void
     */
    public function resetConnection()
    {
        $this->stopJSPolling();

        parent::resetConnection();
        $this->_windowSize = NULL;
        $this->_setBrowser($this->_browserid);

    }//end resetConnection()


    /**
     * Reloads the page.
     *
     * @return void
     */
    public function reloadPage()
    {
        $this->stopJSPolling();
        $this->keyDown('Key.CMD + r');

    }//end reloadPage()


    /**
     * Sets the browser URL to the specified URL.
     *
     * @param string $url The new URL.
     *
     * @return void
     */
    public function goToURL($url)
    {
        $this->stopJSPolling();
        $this->keyDown('Key.CMD+l');
        $this->type($url);
        $this->keyDown('Key.ENTER');
        $this->keyDown('Key.ENTER');
        sleep(1);

    }//end goToURL()


    /**
     * Type the text at the current focused input field or at a click point specified by PSMRL.
     *
     * @param string $text      The text to type.
     * @param string $modifiers Key modifiers.
     * @param string $psmrl     PSMRL variable.
     *
     * @return integer
     */
    public function type($text, $modifiers=NULL, $psmrl=NULL)
    {
        // We may need to increase the timeout when typing. It takes about 5s to
        // type 100 characters.
        $length  = strlen($text);
        $timeout = (int) (($length * 5) / 100);

        $currentTimeout = NULL;
        if ($timeout > 10) {
            $timeout       += 5;
            $currentTimeout = $this->setSikuliCMDTimeout($timeout);
        }

        $result = parent::type($text, $modifiers, $psmrl);

        if ($timeout > 10) {
            $this->setSikuliCMDTimeout($currentTimeout);
        }

        return $result;

    }//end type()


    /**
     * Returns the rectangle for a DOM element found using the specified selector.
     *
     * @param string  $selector The jQuery selector to use for finding the element.
     * @param integer $index    The element index of the resulting array.
{'fraction_non_alphanumeric': 0.12468619246861924, 'fraction_numerical': 0.012133891213389121, 'mean_word_length': 1.5462050599201065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '71998', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2703, 'n_words': 731}