Completed
Push — master ( 5c8fbd...2c9aff )
by Jacob
03:19
created

ContactController::set_head_data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?
0 ignored issues
show
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
2
3
Loader::load('controller', 'home/DefaultPageController');
4
5
final class ContactController extends DefaultPageController
6
{
7
8
	private static $TITLE = 'Contact | Jacob Emerick';
9
	private static $DESCRIPTION = 'Contact page to reach Jacob Emerick by email or social networks';
10
11
	private static $KEYWORD_ARRAY = array(
12
		'Jacob Emerick',
13
		'jacobemerick',
14
		'jpemeric',
15
		'contact',
16
		'email',
17
		'connect');
18
19
	protected function set_head_data()
20
	{
21
		$this->set_title(self::$TITLE);
22
		$this->set_description(self::$DESCRIPTION);
23
		$this->set_keywords(self::$KEYWORD_ARRAY);
24
		
25
		parent::set_head_data();
26
	}
27
28
	protected function set_body_data()
29
	{
30
		$this->set_body('form_container', $this->process_form());
31
		$this->set_body_view('Contact');
32
		
33
		parent::set_body_data();
34
	}
35
36
	private function process_form()
37
	{
38
		if(!Request::hasPost() || Request::getPost('submit') != 'Send Message!')
39
			return (object) array('display' => 'normal');
40
		
41
		Loader::load('utility', 'Validate');
42
		$error_result = array();
43
		if(!Validate::checkRequest('post', 'name', 'string'))
44
			$error_result['name'] = 'please enter your name';
45
		if(!Validate::checkRequest('post', 'email', 'string'))
46
			$error_result['email'] = 'please enter a valid email';
47
		if(!Validate::checkRequest('post', 'message', 'string'))
48
			$error_result['message'] = 'please write a message';
49
		
50
		$values = (object) array(
51
			'name' => Request::getPost('name'),
52
			'email' => Request::getPost('email'),
53
			'message' => Request::getPost('message'));
54
		
55
		if(count($error_result) > 0)
56
		{
57
			return (object) array(
58
				'display' => 'error',
59
				'messages' => $error_result,
60
				'values' => $values);
61
		}
62
63
    global $container;
64
    $sent = $container['mail']
0 ignored issues
show
Unused Code introduced by
$sent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
      ->addTo($container['config']->admin_email)
66
      ->setSubject('Home Page Contact')
67
      ->setPlainMessage(
68
        "Name: {$values->name}\n" .
69
        "Email: {$values->email}\n" .
70
        "Message: {$values->message}"
71
      )
72
      ->send();		
73
74
		return (object) array('display' => 'success');
75
	}
76
77
}
78