<commit_before><?php

namespace SSRS\Soap;

class NTLM extends \SoapClient {

    protected $_uri;
    protected $_username;
    protected $_passwd;
    protected $_cachePath;
    protected $_cacheExpiry;
    protected $_lastRequest;
    protected $_lastResponse;

    function __construct($wsdl, $options = array()) {
        if (empty($options['cache_wsdl_path'])) {
            $options['cache_wsdl_path'] = '/tmp/' . md5($wsdl) . '.wsdl';
        }

        if (array_key_exists('username', $options)) {
            $this->setUsername($options['username']);
        }

        if (array_key_exists('password', $options)) {
            $this->setPassword($options['password']);
        }

        $this->setUri($wsdl);
        $this->setCachePath($options['cache_wsdl_path']);
    }

    public function init() {
        $this->fetchWSDL();

        $options['cache_wsdl'] = WSDL_CACHE_MEMORY;
        $options['login'] = $this->_username;
        $options['password'] = $<PASSWORD>->_<PASSWORD>;

        parent::__construct($this->_cachePath, $options);
        return $this;
    }

    public function setUri($uri) {
        $this->_uri = $uri;
        return $this;
    }

    public function getUri() {
        return $this->_uri;
    }

    public function setCacheExpiry($cacheExpiry = 86400) {
        $this->_cacheExpiry = $cacheExpiry;
        return $this;
    }

    public function getCacheExpiry() {
        return $this->_cacheExpiry;
    }

    public function isCacheValid() {
        $checkTime = time() - $this->getCacheExpiry();
        return (file_exists($this->getCachePath()) && filemtime($this->getCachePath()) > $checkTime);
    }

    public function setUsername($username) {
        $this->_username = (string) $username;
        return $this;
    }

    public function setPassword($password) {
        $this->_passwd = (string) $password;
        return $this;
    }

    public function setCachePath($path) {
        $folder = dirname($path);

        if (!is_dir($folder)) {
            throw new Exception('WSDL cache path is not valid');
        }

        if (!is_writeable($folder)) {
            throw new Exception('WSDL cache path not writeable');
        }

        $this->_cachePath = $path;
        return $this;
    }

    public function getCachePath() {
        return $this->_cachePath;
    }

    public function cacheWSDL($fileContents) {
        $result = file_put_contents($this->_cachePath, $fileContents);
        if ($result) {
            $this->setCacheWSDLPermission(0666);
        }<commit_msg>Better error handling for invalid cache path<commit_after><?php

namespace SSRS\Soap;

use RuntimeException;

class NTLM extends \SoapClient {

    protected $_uri;
    protected $_username;
    protected $_passwd;
    protected $_cachePath;
    protected $_cacheExpiry;
    protected $_lastRequest;
    protected $_lastResponse;

    function __construct($wsdl, $options = array()) {
        if (empty($options['cache_wsdl_path'])) {
            $options['cache_wsdl_path'] = '/tmp/' . md5($wsdl) . '.wsdl';
        }

        if (array_key_exists('username', $options)) {
            $this->setUsername($options['username']);
        }

        if (array_key_exists('password', $options)) {
            $this->setPassword($options['password']);
        }

        $this->setUri($wsdl);
        $this->setCachePath($options['cache_wsdl_path']);
    }

    public function init() {
        $this->fetchWSDL();

        $options['cache_wsdl'] = WSDL_CACHE_MEMORY;
        $options['login'] = $this->_username;
        $options['password'] = $this->_<PASSWORD>;

        parent::__construct($this->_cachePath, $options);
        return $this;
    }

    public function setUri($uri) {
        $this->_uri = $uri;
        return $this;
    }

    public function getUri() {
        return $this->_uri;
    }

    public function setCacheExpiry($cacheExpiry = 86400) {
        $this->_cacheExpiry = $cacheExpiry;
        return $this;
    }

    public function getCacheExpiry() {
        return $this->_cacheExpiry;
    }

    public function isCacheValid() {
        $checkTime = time() - $this->getCacheExpiry();
        return (file_exists($this->getCachePath()) && filemtime($this->getCachePath()) > $checkTime);
    }

    public function setUsername($username) {
        $this->_username = (string) $username;
        return $this;
    }

    public function setPassword($password) {
        $this->_passwd = (string) $password;
        return $this;
    }

    public function setCachePath($file) {
        $folder = dirname($file);

        if (file_exists($file) && false === is_writable($file)) {
            throw new RuntimeException("WSDL cache file not writeable");
        } elseif (false === is_dir($folder)) {
            throw new RuntimeException("WSDL cache parent folder does not exist");
        } elseif (false === is_writeable($folder)) {
            throw new RuntimeException("WSDL cache parent folder not writeable");
        }

        $this->_cachePath = $file;
        return $this;
    }

    public function getCachePath() {
        return $this->_cachePath;
    }

    public function cacheWSDL($fileContents) {
        $result = file_put_contents($this->_cachePath, $fileContents);
        if ($result) {
            $this->setCacheWSDLPermission(0666);
        }
{'fraction_non_alphanumeric': 0.1400523560209424, 'fraction_numerical': 0.0037397157816005983, 'mean_word_length': 2.5052424639580604, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2853725', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1544, 'n_words': 319}