<commit_before><?php
/**
 * \Pyrus\PackageFile
 *
 * PHP version 5
 *
 * @category  Pyrus
 * @package   Pyrus
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      https://github.com/pyrus/Pyrus
 */

/**
 * Base class for a PEAR2 package file
 *
 * @category  Pyrus
 * @package   Pyrus
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      https://github.com/pyrus/Pyrus
 */
namespace Pyrus;
class PackageFile implements PackageFileInterface
{
    public $info;
    public $path;
    function __construct($package, $class = 'Pyrus\PackageFile\v2', $isString = false)
    {
        if ($package instanceof PackageFileInterface) {
            $this->path = $package->getFilePath();
            return $this->info = $package;
        }

        $this->path = $package;
        $parser = new PackageFile\Parser\v2;
        if ($isString) {
            $data = $package;
        } else {
            $data = file_get_contents($package);
        }

        if ($data === false || empty($data)) {
            throw new PackageFile\Exception('Unable to open package xml file '
                . $package . ' or file was empty.');
        }

        $this->info = $parser->parse($data, $package, $class);
    }

    function __toString()
    {
        return $this->info->__toString();
    }

    function getValidator()
    {
        return $this->info->getValidator();
    }

    function getPackageFileObject()
    {
        return $this->info;
    }

    function __get($var)
    {
        return $this->info->__get($var);
    }

    function __set($var, $value)
    {
        return $this->info->__set($var, $value);
    }<commit_msg>Move the parser instantiation below the error checks as it is not used before it. Would be extra resources if the thing is thrown. Also more the $this->path setting into else since we don't want the whole string to be set as a path if we are passing in a large chunk of data.<commit_after><?php
/**
 * \Pyrus\PackageFile
 *
 * PHP version 5
 *
 * @category  Pyrus
 * @package   Pyrus
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      https://github.com/pyrus/Pyrus
 */

/**
 * Base class for a PEAR2 package file
 *
 * @category  Pyrus
 * @package   Pyrus
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      https://github.com/pyrus/Pyrus
 */
namespace Pyrus;
class PackageFile implements PackageFileInterface
{
    public $info;
    public $path;
    function __construct($package, $class = 'Pyrus\PackageFile\v2', $isString = false)
    {
        if ($package instanceof PackageFileInterface) {
            $this->path = $package->getFilePath();
            return $this->info = $package;
        }

        if ($isString) {
            $data = $package;
        } else {
            $this->path = $package;
            $data = file_get_contents($package);
        }

        if ($data === false || empty($data)) {
            throw new PackageFile\Exception('Unable to open package xml file '
                . $package . ' or file was empty.');
        }

        $parser = new PackageFile\Parser\v2;
        $this->info = $parser->parse($data, $package, $class);
    }

    function __toString()
    {
        return $this->info->__toString();
    }

    function getValidator()
    {
        return $this->info->getValidator();
    }

    function getPackageFileObject()
    {
        return $this->info;
    }

    function __get($var)
    {
        return $this->info->__get($var);
    }

    function __set($var, $value)
    {
        return $this->info->__set($var, $value);
    }
{'fraction_non_alphanumeric': 0.13493670886075948, 'fraction_numerical': 0.0060759493670886075, 'mean_word_length': 2.2706953642384105, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 46, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, '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': '4979427', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1161, 'n_words': 313}