command($enterprise, $input, 'code'); } public function bind(int $enterprise, array $input): array { return $this->command($enterprise, $input, 'bind'); } private function command(int $enterprise, array $input, string $action): array { $this->access->enterprise($enterprise, true); Fields::only($input, $action === 'code' ? ['request_key'] : ['request_key', 'invite_code']); $key = Fields::text($input, 'request_key', 80); $code = $action === 'bind' ? strtoupper(Fields::text($input, 'invite_code', 24)) : ''; return Commands::run($this->access->actor, $key, 'promotion.' . $action . ':' . $enterprise, $input, function () use ($enterprise, $action, $code) { $this->access->enterprise($enterprise, true); $service = new PromotionReferrals(); return $action === 'code' ? $service->code($enterprise) : $service->bind($enterprise, $code, (int) $this->access->actor->userId); }, fn () => $this->access->enterprise($enterprise, true)); } }