Code Duplication    Length = 25-26 lines in 2 locations

src/Repositories/PGTicketRepository.php 1 location

@@ 79-104 (lines=26) @@
76
     * @return PGTicket
77
     * @throws CasException
78
     */
79
    public function applyTicket(UserModel $user, $pgtUrl, $proxies = [])
80
    {
81
        $service = $this->serviceRepository->getServiceByUrl($pgtUrl);
82
        if (!$service || !$service->allow_proxy) {
83
            throw new CasException(CasException::UNAUTHORIZED_SERVICE_PROXY);
84
        }
85
86
        $ticket = $this->getAvailableTicket(config('cas.pg_ticket_len', 64));
87
        if ($ticket === false) {
88
            throw new CasException(CasException::INTERNAL_ERROR, 'apply proxy-granting ticket failed');
89
        }
90
        $record = $this->pgTicket->newInstance(
91
            [
92
                'ticket'     => $ticket,
93
                'expire_at'  => new Carbon(sprintf('+%dsec', config('cas.pg_ticket_expire', 7200))),
94
                'created_at' => new Carbon(),
95
                'pgt_url'    => $pgtUrl,
96
                'proxies'    => $proxies,
97
            ]
98
        );
99
        $record->user()->associate($user->getEloquentModel());
100
        $record->service()->associate($service);
101
        $record->save();
102
103
        return $record;
104
    }
105
106
    /**
107
     * @param string $totalLength

src/Repositories/TicketRepository.php 1 location

@@ 54-78 (lines=25) @@
51
     * @throws CasException
52
     * @return Ticket
53
     */
54
    public function applyTicket(UserModel $user, $serviceUrl, $proxies = [])
55
    {
56
        $service = $this->serviceRepository->getServiceByUrl($serviceUrl);
57
        if (!$service) {
58
            throw new CasException(CasException::INVALID_SERVICE);
59
        }
60
        $ticket = $this->getAvailableTicket(config('cas.ticket_len', 32), empty($proxies) ? 'ST-' : 'PT-');
61
        if ($ticket === false) {
62
            throw new CasException(CasException::INTERNAL_ERROR, 'apply ticket failed');
63
        }
64
        $record = $this->ticket->newInstance(
65
            [
66
                'ticket'      => $ticket,
67
                'expire_at'   => new Carbon(sprintf('+%dsec', config('cas.ticket_expire', 300))),
68
                'created_at'  => new Carbon(),
69
                'service_url' => $serviceUrl,
70
                'proxies'     => $proxies,
71
            ]
72
        );
73
        $record->user()->associate($user->getEloquentModel());
74
        $record->service()->associate($service);
75
        $record->save();
76
77
        return $record;
78
    }
79
80
    /**
81
     * @param string $ticket