ServiceValidateController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleRequest() 0 18 4
1
<?php
2
/**
3
 * serviceValidate controller class.
4
 *
5
 * @version 1.2.0
6
 * @since 1.2.0
7
 */
8
9
namespace Cassava\CAS\Controller;
10
11
use Cassava\CAS;
12
use Cassava\Exception\GeneralException;
13
14
/**
15
 * Implements CAS service validation.
16
 *
17
 * `/serviceValidate` checks the validity of a service ticket and does not handle proxy
18
 * authentication. CAS MUST respond with a ticket validation failure response when a proxy
19
 * ticket is passed to `/serviceValidate`.
20
 *
21
 * @since 1.2.0
22
 */
23
class ServiceValidateController extends ValidateController {
24
25
	/**
26
	 * Valid ticket types.
27
	 *
28
	 * @var array
29
	 */
30
	protected $validTicketTypes = array(
31
		CAS\Ticket::TYPE_ST,
32
	);
33
34
	/**
35
	 * Handles ticket validation requests.
36
	 *
37
	 * This method attempts to set a `Content-Type: text/xml` HTTP response header.
38
	 *
39
	 * @param  array  $request Request arguments.
40
	 * @return string          Response XML string.
41
	 *
42
	 * @todo Accept proxy callback URL (pgtUrl) parameter.
43
	 * @todo Accept renew parameter.
44
	 */
45
	public function handleRequest( $request ) {
46
		$service = isset( $request['service'] ) ? $request['service'] : '';
47
		$ticket  = isset( $request['ticket'] )  ? $request['ticket']  : '';
48
49
		$response = new CAS\Response\ValidateResponse;
50
51
		try {
52
			$ticket = $this->validateRequest( $ticket, $service );
53
			$response->setTicket( $ticket );
54
		}
55
		catch ( GeneralException $exception ) {
56
			$response->setError( $exception->getErrorInstance() );
57
		}
58
59
		$this->server->setResponseContentType( 'text/xml' );
60
61
		return $response->prepare();
62
	}
63
}
64