Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 84
StateService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 10
420.00
0.00% covered (danger)
0.00%
0 / 84
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 __clone
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getAllStates
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
 fetchAllStates
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 9
 insertState
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 updateState
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 deleteState
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getStateById
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 11
 getAllStatesForReport
0.00% covered (danger)
0.00%
0 / 1
12.00
0.00% covered (danger)
0.00%
0 / 12
<?php
namespace com\linways\core\ams\professional\service;
use com\linways\core\ams\professional\exception\ProfessionalException;
use phpDocumentor\Reflection\Types\Integer;
class StateService extends BaseService
{
    
    private static $_instance = null;
    
    // /Condition 2 - Locked down the constructor
    private function __construct()
    {}
    
    // Prevent any oustide instantiation of this class
    
    // /Condition 3 - Prevent any object or instance of that class to be cloned
    private function __clone()
    {}
    
    // Prevent any copy of this object
    
    // /Condition 4 - Have a single globally accessible static method
    public static function getInstance()
    {
        if (! is_object(self::$_instance)) // or if( is_null(self::$_instance) ) or if( self::$_instance == null )
            self::$_instance = new self();
            
            return self::$_instance;
    }
    
    /**
     * 
     *
     * @author gadheyan
     * @throws ProfessionalException
     * @return unknown
     */
    public function getAllStates()
    {
        $query = "select id, state_name as name from state";
        try {
            $responseList = $this->executeQueryForList($query);
            if (empty($responseList)) {
                throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY, "No Records Found!");
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $responseList;
    }
     /**
     * 
     *
     * @author diyana
     * @throws ProfessionalException
     * @return unknown
     */
    public function fetchAllStates()
    {
        $query = "select id, state_name as name from state";
        try {
            $responseList = $this->executeQueryForList($query);
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $responseList;
    }
    
    /**
     * 
     * @param unknown 
     * @throws ProfessionalException
     * @return unknown
     */
    public function insertState($state)
    {
        $state=$this->realEscapeObject($state);
       
        $query = "insert into state (state_name) values ('$state->name')";
        try{
            $response=$this->executeQueryForObject($query,true);
        }catch(\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return $response;
    }
    /**
     * 
     * @param  $nationality
     * @throws ProfessionalException
     * @return string
     */
    public function updateState($state)
    {
        $state=$this->realEscapeObject($state);
        $query = "update state set state_name='$state->name' where id='$state->id'";
        try{
            $this->executeQuery($query);
        }catch(\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return "success";
    }
    
    /**
     * 
     * @param integer $id
     * @throws ProfessionalException
     * @return string
     */
    public function deleteState($id)
    {
        $id=$this->realEscapeString($id);
        $query = "delete from state where id='$id'";
        try{
           
           $this->executeQuery($query);
        }catch(\Exception $e)
        {
            throw new ProfessionalException($e->getCode(),$e->getMessage());
        }
        return "success";
    }
    
    /**
     * 
     * @param integer $id
     * @throws ProfessionalException
     * @return object|NULL|\com\linways\base\util\$objectList[]
     */
    public function getStateById($id)
    {
        $id = $this->realEscapeString($id);
        
        $query = "select id, state_name as name from state where id = '$id'";
        
        try{
            $response=$this->executeQueryForObject($query);
            return $response;
        }catch (\Exception $e)
        {
            throw new ProfessionalException(ProfessionalException::QUERY_EXECUTION_FAILED,"No Record found for this id");
        }
    }
    /**
     * 
     *
     * @author gadheyan
     * @throws ProfessionalException
     * @return unknown
     */
    public function getAllStatesForReport()
    {
        $query = "SELECT id, state_name as name from state where isHidden = 0";
        try {
            $responseList = $this->executeQueryForList($query);
            if (empty($responseList)) {
                throw new ProfessionalException(ProfessionalException::ARRAY_EMPTY, "No Records Found!");
            }
        } catch (\Exception $e) {
            throw new ProfessionalException($e->getCode(), $e->getMessage());
        }
        return $responseList;
    }
}