Swiftriver\Core\StateTransition\StateController::IsValidInacurateReason PHP Method

IsValidInacurateReason() public static method

Given a string, this function checks if it is a valid reason for marking a content item as inaccurate.
public static IsValidInacurateReason ( string $reason ) : boolean
$reason string
return boolean
    public static function IsValidInacurateReason($reason)
    {
        return $reason == "falsehood" || $reason == "inaccuracy" || $reason == "biased";
    }

Usage Example

 public function ParseJSONToInacurateReason($json)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [Method invoked]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [START: Decoding the JSON]", \PEAR_LOG_DEBUG);
     //call json decode on the json
     $object = json_decode($json);
     //check that the decode worked ok
     if (!$object || $object == null) {
         throw new \InvalidArgumentException("The JSON supplied did not descode.");
     }
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [END: Decoding the JSON]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [START: Extracting required data]", \PEAR_LOG_DEBUG);
     //Extract the required field ID
     $reason = $object->reason;
     //Check that the id is set and is a string
     if (!$reason || !isset($reason) || $reason == null || !is_string($reason)) {
         throw new \InvalidArgumentException("The JSON supplied did not containt the required string field 'reason'.");
     }
     //check that this is a recognised reason
     if (!\Swiftriver\Core\StateTransition\StateController::IsValidInacurateReason($reason)) {
         throw new \InvalidArgumentException("The JSON supplied did not containt a valid 'reason'.");
     }
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [END: Extracting required data]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::ContentServicesBase::ParseJSONToInacurateReason [Method finished]", \PEAR_LOG_DEBUG);
     //return the id
     return $reason;
 }