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

waterfalls/ContactController.class.inc.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?
2
3
Loader::load('controller', 'waterfalls/DefaultPageController');
4
5
final class ContactController extends DefaultPageController
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type ContactController has been defined more than once; this definition is ignored, only the first definition in controller/home/ContactController.class.inc.php (L5-77) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
6
{
7
8
	private static $TITLE = 'Contact Jacob Emerick | Waterfalls of the Keweenaw';
9
	private static $DESCRIPTION = 'Contact page to reach Jacob Emerick by email or social networks';
10
11
	private static $KEYWORD_ARRAY = array(
12
		'contact',
13
		'email',
14
		'waterfalls',
15
		'Jacob Emerick');
16
17
	protected function set_head_data()
18
	{
19
		$this->set_title(self::$TITLE);
20
		$this->set_description(self::$DESCRIPTION);
21
		$this->set_keywords(self::$KEYWORD_ARRAY);
22
		
23
		parent::set_head_data();
24
	}
25
26
	protected function set_body_data()
27
	{
28
		$this->set_body('form_container', $this->process_form());
29
		$this->set_body('view', 'Contact');
30
		
31
		parent::set_body_data();
32
	}
33
34
	private function process_form()
35
	{
36
		if(!Request::hasPost() || Request::getPost('submit') != 'Send Message!')
37
			return (object) array('display' => 'normal');
38
		
39
		Loader::load('utility', 'Validate');
40
		$error_result = array();
41
		if(!Validate::checkRequest('post', 'name', 'string'))
42
			$error_result['name'] = 'please enter your name';
43
		if(!Validate::checkRequest('post', 'email', 'string'))
44
			$error_result['email'] = 'please enter a valid email';
45
		if(!Validate::checkRequest('post', 'message', 'string'))
46
			$error_result['message'] = 'please write a message';
47
		
48
		$values = (object) array(
49
			'name' => Request::getPost('name'),
50
			'email' => Request::getPost('email'),
51
			'message' => Request::getPost('message'));
52
		
53
		if(count($error_result) > 0)
54
		{
55
			return (object) array(
56
				'display' => 'error',
57
				'messages' => $error_result,
58
				'values' => $values);
59
		}
60
61
    global $container;
62
    $sent = $container['mail']
0 ignored issues
show
$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...
63
      ->addTo($container['config']->admin_email)
64
      ->setSubject('Waterfall Site Contact')
65
      ->setPlainMessage(
66
        "Name: {$values->name}\n" .
67
        "Email: {$values->email}\n" .
68
        "Message: {$values->message}"
69
      )
70
      ->send();
71
72
		return (object) array('display' => 'success');
73
	}
74
75
}
76