<commit_before><?php
namespace SimplyTestable\ApiBundle\Services;


class ApplicationStateService {
    
    const STATE_ACTIVE = 'active';
    const STATE_MAINTENANCE_READ_ONLY = 'maintenance-read-only';
    const DEFAULT_STATE = self::STATE_ACTIVE;
    
    private $allowedStates = array(
        self::STATE_ACTIVE,
        self::STATE_MAINTENANCE_READ_ONLY
    );
    
    /**
     *
     * @var string
     */
    private $stateResourcePath;
    
    
    /**
     *
     * @var string
     */
    private $state;
    
    
    /**
     * 
     * @return boolean
     */
    public function isInActiveState() {
        return $this->getState() == self::STATE_ACTIVE;
    }
    
    
    /**
     * 
     * @return boolean
     */
    public function isInMaintenanceReadOnlyState() {
        return $this->getState() == self::STATE_MAINTENANCE_READ_ONLY;
    }
    
    
    /**
     * 
     * @param string $state
     * @return boolean
     */
    public function setState($state) {
        if (!$this->isAllowedState($state)) {
            return false;
        }
        
        return file_put_contents($this->stateResourcePath, $state) > 0;
    }
    
    
    /**
     * 
     * @return string
     */
    public function getState() {       
        if (is_null($this->state)) {            
            if (file_exists($this->stateResourcePath)) {
                $this->state = trim(file_get_contents($this->stateResourcePath));
            }
            
            if (!$this->isAllowedState($this->state)) {
                $this->state = self::DEFAULT_STATE;
            }
        }
        
        return $this->state;        
    }
    
    
    /**
     * 
     * @param string $stateResourcePath
     */
    public function setStateResourcePath($stateResourcePath) {
        $this->stateResourcePath = $stateResourcePath;
    }<commit_msg>Update internal cache of state when setting state<commit_after><?php
namespace SimplyTestable\ApiBundle\Services;


class ApplicationStateService {
    
    const STATE_ACTIVE = 'active';
    const STATE_MAINTENANCE_READ_ONLY = 'maintenance-read-only';
    const DEFAULT_STATE = self::STATE_ACTIVE;
    
    private $allowedStates = array(
        self::STATE_ACTIVE,
        self::STATE_MAINTENANCE_READ_ONLY
    );
    
    /**
     *
     * @var string
     */
    private $stateResourcePath;
    
    
    /**
     *
     * @var string
     */
    private $state;
    
    
    /**
     * 
     * @return boolean
     */
    public function isInActiveState() {
        return $this->getState() == self::STATE_ACTIVE;
    }
    
    
    /**
     * 
     * @return boolean
     */
    public function isInMaintenanceReadOnlyState() {
        return $this->getState() == self::STATE_MAINTENANCE_READ_ONLY;
    }
    
    
    /**
     * 
     * @param string $state
     * @return boolean
     */
    public function setState($state) {
        if (!$this->isAllowedState($state)) {
            return false;
        }
        
        if (file_put_contents($this->stateResourcePath, $state) > 0) {
            $this->state = null;
            return true;
        }
        
        return false;
    }
    
    
    /**
     * 
     * @return string
     */
    public function getState() {       
        if (is_null($this->state)) { 
            if (file_exists($this->stateResourcePath)) {
                $this->state = trim(file_get_contents($this->stateResourcePath));
            }
            
            if (!$this->isAllowedState($this->state)) {
                $this->state = self::DEFAULT_STATE;
            }
        }
        
        return $this->state;        
    }
    
    
    /**
     * 
     * @param string $stateResourcePath
     */
    public function setStateResourcePath($stateResourcePath) {
        $this->stateResourcePath = $stateResourcePath;
    }
{'fraction_non_alphanumeric': 0.11691348402182385, 'fraction_numerical': 0.0005196154845414394, 'mean_word_length': 1.6478679504814306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '2276274', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1125, 'n_words': 181}