<commit_before><?php
/**
 * SugarCRM Tools
 *
 * PHP Version 5.3 -> 5.6
 * SugarCRM Versions 6.5 - 7.6
 *
 * @author <NAME>
 * @copyright 2005-2015 iNet Process
 * @package inetprocess/sugarcrm
 * @license GNU General Public License v2.0
 * @link http://www.inetprocess.com
 */

namespace Inet\SugarCRM;

use Psr\Log\LoggerInterface;

/**
 * SugarCRM EntryPoint: Enters SugarCRM and set the current_user + all needed variables
 */
class EntryPoint
{
    /**
     * Prefix that should be set by each class to identify it in logs
     * @var    string
     */
    protected $logPrefix;

    /**
     * SugarCRM Application
     * @var    string
     */
    protected $sugarApp;
    /**
     * Last Current working directory before changing to getPath()
     * @var    string
     */
    protected $lastCwd;
    /**
     * SugarCRM User Id to connect with
     * @var    string
     */
    protected $sugarUserId;
    /**
     * SugarCRM User Bean
     * @var    \User
     */
    protected $currentUser;

    /**
     * SugarCRM DB Object
     * @var    \MySQLi
     */
    private $sugarDb;

    /**
     * List of Beans from SugarCRM as "$key [singular] => $value [plural]"
     * @var    array
     */
    private $beanList = array();

    /**
     * Globals variables defined (save it because it's lost sometimes)
     * @var    array
     */
    private $globals = array();

    /**
     * Singleton pattern instance
     * @var Inet\SugarCrm\EntryPoint
     */
    private static $instance = null;

    /**
     * Constructor, to get the Container, then the log and config
     * @param        LoggerInterface    $log             Allow any logger extended from PSR\Log
     * @param        Application        $sugarApp
     * @param        string             $sugarUserId
     */
    private function __construct(Application $sugarApp, $sugarUserId)
    {
        $this->logPrefix = __CLASS__ . ': ';

        $this->sugarApp = $sugarApp;
        $this->sugarUserId = $sugarUserId;
    }

    /**
     * @return true if the EntryPoint instances is already created.
     */
    public static function isCreated()
    {
        return !is_null(self::$instance);
    }

    /**
     * Create the singleton instance only if it doesn't exists already.
     * @param        LoggerInterface    $log             Allow any logger extended from PSR\Log
     * @param        Application        $sugarApp
     * @param        string             $sugarUserId
     * @throws      \RuntimeException
     */
    public static function createInstance(Application $sugarApp, $sugarUserId)
    {
        if (!is_null(self::$instance)) {
            throw new \RuntimeException('Unable to create a SugarCRM\EntryPoint more than once.');
        }
        $instance = new EntryPoint($sugarApp, $sugarUserId);
        $instance->initSugar();
        self::$instance = $instance;
    }

    /**
     * Returns EntryPoint singleton instance.
     * @throws \RuntimeException if the instance is not initiated.
     * @return    LoggerInterface
     */
    public static function getInstance()
    {
        if (is_null(self::$instance)) {
            throw new \RuntimeException('You must first create the singleton instance with createInstance().');
        }
        self::$instance->setGlobalsFromSugar();
        self::$instance->chdirToSugarDir();
        return self::$instance;
    }

    /**
     * Alias for $this->getApplication()->getLogger()
     * @return    LoggerInterface
     */
    public function getLogger()
    {<commit_msg>createInstance now returns the instance<commit_after><?php
/**
 * SugarCRM Tools
 *
 * PHP Version 5.3 -> 5.6
 * SugarCRM Versions 6.5 - 7.6
 *
 * @author <NAME>
 * @copyright 2005-2015 iNet Process
 * @package inetprocess/sugarcrm
 * @license GNU General Public License v2.0
 * @link http://www.inetprocess.com
 */

namespace Inet\SugarCRM;

use Psr\Log\LoggerInterface;

/**
 * SugarCRM EntryPoint: Enters SugarCRM and set the current_user + all needed variables
 */
class EntryPoint
{
    /**
     * Prefix that should be set by each class to identify it in logs
     * @var    string
     */
    protected $logPrefix;

    /**
     * SugarCRM Application
     * @var    string
     */
    protected $sugarApp;
    /**
     * Last Current working directory before changing to getPath()
     * @var    string
     */
    protected $lastCwd;
    /**
     * SugarCRM User Id to connect with
     * @var    string
     */
    protected $sugarUserId;
    /**
     * SugarCRM User Bean
     * @var    \User
     */
    protected $currentUser;

    /**
     * SugarCRM DB Object
     * @var    \MySQLi
     */
    private $sugarDb;

    /**
     * List of Beans from SugarCRM as "$key [singular] => $value [plural]"
     * @var    array
     */
    private $beanList = array();

    /**
     * Globals variables defined (save it because it's lost sometimes)
     * @var    array
     */
    private $globals = array();

    /**
     * Singleton pattern instance
     * @var Inet\SugarCrm\EntryPoint
     */
    private static $instance = null;

    /**
     * Constructor, to get the Container, then the log and config
     * @param        LoggerInterface    $log             Allow any logger extended from PSR\Log
     * @param        Application        $sugarApp
     * @param        string             $sugarUserId
     */
    private function __construct(Application $sugarApp, $sugarUserId)
    {
        $this->logPrefix = __CLASS__ . ': ';

        $this->sugarApp = $sugarApp;
        $this->sugarUserId = $sugarUserId;
    }

    /**
     * @return true if the EntryPoint instances is already created.
     */
    public static function isCreated()
    {
        return !is_null(self::$instance);
    }

    /**
     * Create the singleton instance only if it doesn't exists already.
     * @param        LoggerInterface    $log             Allow any logger extended from PSR\Log
     * @param        Application        $sugarApp
     * @param        string             $sugarUserId
     * @throws      \RuntimeException
     */
    public static function createInstance(Application $sugarApp, $sugarUserId)
    {
        if (!is_null(self::$instance)) {
            throw new \RuntimeException('Unable to create a SugarCRM\EntryPoint more than once.');
        }
        $instance = new EntryPoint($sugarApp, $sugarUserId);
        $instance->initSugar();
        self::$instance = $instance;

        return self::$instance;
    }

    /**
     * Returns EntryPoint singleton instance.
     * @throws \RuntimeException if the instance is not initiated.
     * @return    LoggerInterface
     */
    public static function getInstance()
    {
        if (is_null(self::$instance)) {
            throw new \RuntimeException('You must first create the singleton instance with createInstance().');
        }
        self::$instance->setGlobalsFromSugar();
        self::$instance->chdirToSugarDir();
        return self::$instance;
    }

    /**
     * Alias for $this->getApplication()->getLogger()
     * @return    LoggerInterface
     */
    public function getLogger()
    {
{'fraction_non_alphanumeric': 0.10693682285071057, 'fraction_numerical': 0.005065428450823132, 'mean_word_length': 2.0532646048109964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, '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': '2712952', 'n_tokens_mistral': 2050, 'n_tokens_neox': 2021, 'n_words': 580}