Scalr\Api\Service\Account\V1beta0\Adapter\EnvironmentTeamAdapter::validateEntity PHP Метод

validateEntity() публичный Метод

См. также: ApiEntityAdapter::validateEntity()
public validateEntity ( $entity )
    public function validateEntity($entity)
    {
        if (!$entity instanceof TeamEnvs) {
            throw new InvalidArgumentException(sprintf("First argument must be instance of %s", Team::class));
        }
        if (empty($entity->teamId)) {
            throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property team.id");
        }
        $teamId = $entity->teamId;
        if (!is_numeric($teamId)) {
            throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid team identifier");
        }
        /* @var $team Team */
        $team = Team::findOne([['id' => $teamId], ['accountId' => $this->controller->getUser()->accountId]]);
        if (empty($team)) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf("Requested team %s do not exist in this account", $teamId));
        }
        if (!empty(TeamEnvs::findOne([['envId' => $entity->envId], ['teamId' => $teamId]]))) {
            throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, sprintf("Team %s already exists in this environment", $teamId));
        }
        /* @var  $teamAdapter TeamAdapter */
        $teamAdapter = $this->controller->adapter('team');
        $teamAdapter->validateTeamName($team->name);
    }