Scalr\Api\Service\Account\V1beta0\Adapter\EnvironmentAdapter::validateEntity PHP Method

validateEntity() public method

See also: ApiEntityAdapter::validateEntity()
public validateEntity ( $entity )
    public function validateEntity($entity)
    {
        /* @var $entity Environment */
        if (empty($entity->name)) {
            throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property name");
        }
        if (Environment::findOne([['accountId' => $entity->accountId], ['name' => $entity->name], ['id' => ['$ne' => $entity->id]]])) {
            throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Environment with name '{$entity->name}' already exists in this account");
        }
        if (empty($entity->getProperty(EnvironmentProperty::SETTING_CC_ID))) {
            throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property costCenter");
        }
    }