Completed
Push — master ( c47c32...e13eeb )
by Mateusz
06:05 queued 03:00
created

DNDeploymentHandlers::sendEmailToApprover()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 9.2
cc 3
eloc 17
nc 2
nop 1
1
<?php
2
3
use \Finite\Event\TransitionEvent;
4
5
class DNDeploymentHandlers extends Object {
6
7
	public function onSubmit(TransitionEvent $e) {
8
		$deployment = $e->getStateMachine()->getObject();
9
		$this->sendEmailToApprover($deployment);
10
	}
11
12
	protected function sendEmailToApprover(DNDeployment $deployment) {
13
		$deployer = $deployment->Deployer();
14
		$approver = $deployment->Approver();
0 ignored issues
show
Documentation Bug introduced by
The method Approver does not exist on object<DNDeployment>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
15
		if (!$approver || !$approver->exists()) {
16
			return false;
17
		}
18
19
		$email = new Email();
20
		$email->setTo(sprintf('%s <%s>', $approver->Name, $approver->Email));
21
		$email->replyTo(sprintf('%s <%s>', $deployer->Name, $deployer->Email));
0 ignored issues
show
Deprecated Code introduced by
The method Email::replyTo() has been deprecated with message: 4.0 Use the "setReplyTo" method instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
		$email->setSubject('Deployment has been submitted');
23
		$email->setTemplate('DeploymentNotificationSubmitted');
24
		$email->populateTemplate($deployment);
25
		$email->send();
26
27
		$log = $deployment->log();
28
		$log->write(sprintf(
29
			'Deployment submitted email sent to approver %s <%s>',
30
			$approver->Name,
31
			$approver->Email
32
		));
33
	}
34
35
	public function onQueue(TransitionEvent $e) {
36
		$deployment = $e->getStateMachine()->getObject();
37
38
		$token = $deployment->enqueueDeployment();
39
		$deployment->ResqueToken = $token;
40
		$deployment->write();
41
42
		$log = $deployment->log();
43
		$log->write(sprintf(
44
			'Deploy queued as job %s (sigFile is %s)',
45
			$token,
46
			DeployJob::sig_file_for_data_object($obj)
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
		));
48
	}
49
50
	public function onAbort(TransitionEvent $e) {
51
		$deployment = $e->getStateMachine()->getObject();
52
53
		// 2 is SIGINT - we can't use SIGINT constant in the mod_apache context.
54
		DeployJob::set_signal($deployment, 2);
55
	}
56
}
57