Completed
Pull Request — master (#588)
by Mateusz
11:08
created
code/control/DNDeploymentDispatcher.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use Finite\StateMachine\StateMachine;
4
-
5 3
 class DNDeploymentDispatcher extends Dispatcher {
6 4
 
7 5
 	const ALLOW_DNDEPLOYMENT_APPROVE = 'ALLOW_DNDEPLOYMENT_APPROVE';
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 	public function getModel($name) {
21 21
 		$deployment = $this->getDeployment();
22
-		if (!$deployment) {
22
+		if(!$deployment) {
23 23
 			return [];
24 24
 		}
25 25
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	public function getDeployment() {
32 32
 		$id = $this->request->param('Id');
33 33
 		$deployment = DNDeployment::get()->byId($id);
34
-		if (!$deployment || !$deployment->exists()) {
34
+		if(!$deployment || !$deployment->exists()) {
35 35
 			return false;
36 36
 		}
37 37
 		return $deployment;
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function apply(SS_HTTPRequest $request) {
41 41
 		$this->checkSecurityToken();
42 42
 		$response = $this->checkRequest();
43
-		if ($response instanceof SS_HTTPResponse) {
43
+		if($response instanceof SS_HTTPResponse) {
44 44
 			return $response;
45 45
 		}
46 46
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	public function canApply(SS_HTTPRequest $request) {
55 55
 		$this->checkSecurityToken();
56 56
 		$response = $this->checkRequest();
57
-		if ($response instanceof SS_HTTPResponse) {
57
+		if($response instanceof SS_HTTPResponse) {
58 58
 			return $response;
59 59
 		}
60 60
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		}
76 76
 
77 77
 		$deployment = $this->getDeployment();
78
-		if (!$deployment) {
78
+		if(!$deployment) {
79 79
 			return new SS_HTTPResponse('Deployment not found', 404);
80 80
 		}
81 81
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 	protected function getMachine() {
86 86
 		$deployment = $this->getDeployment();
87
-		if (!$deployment) {
87
+		if(!$deployment) {
88 88
 			return null;
89 89
 		}
90 90
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 			// It gives a chance to perform a dry-run, and reject the transition, for example
97 97
 			// in case the user is unauthorised.
98 98
 			'finite.test_transition',
99
-			function (Finite\Event\TransitionEvent $e) use ($project) {
99
+			function(Finite\Event\TransitionEvent $e) use ($project) {
100 100
 				$code = null;
101 101
 
102
-				switch ($e->getTransition()->getName()) {
102
+				switch($e->getTransition()->getName()) {
103 103
 				case 'approve':
104 104
 					$code = self::ALLOW_DNDEPLOYMENT_APPROVE;
105 105
 					break;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 					break;
109 109
 				}
110 110
 
111
-				if (!$code || !$project->allowed($code)) {
111
+				if(!$code || !$project->allowed($code)) {
112 112
 					$e->reject();
113 113
 				}
114 114
 			}
Please login to merge, or discard this patch.
Switch Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -100,12 +100,12 @@
 block discarded – undo
100 100
 				$code = null;
101 101
 
102 102
 				switch ($e->getTransition()->getName()) {
103
-				case DNDeployment::TR_SUBMIT:
104
-					$code = self::ALLOW_DNDEPLOYMENT_SUBMIT;
105
-					break;
106
-				case DNDeployment::TR_QUEUE:
107
-					$code = self::ALLOW_DNDEPLOYMENT_QUEUE;
108
-					break;
103
+					case DNDeployment::TR_SUBMIT:
104
+						$code = self::ALLOW_DNDEPLOYMENT_SUBMIT;
105
+						break;
106
+					case DNDeployment::TR_QUEUE:
107
+						$code = self::ALLOW_DNDEPLOYMENT_QUEUE;
108
+						break;
109 109
 				}
110 110
 
111 111
 				if (!$code || !$project->allowed($code)) {
Please login to merge, or discard this patch.
code/model/StateMachineFactory.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -58,17 +58,17 @@
 block discarded – undo
58 58
 
59 59
 	protected function addHandlers($machine) {
60 60
 		$class = get_class($machine->getObject());
61
-		if (empty($this->config()->handlers[$class])) return;
61
+		if(empty($this->config()->handlers[$class])) return;
62 62
 
63 63
 		$transitions = $this->config()->handlers[$class];
64
-		foreach ($transitions as $transName => $handlers) {
65
-			if (!is_array($handlers)) {
64
+		foreach($transitions as $transName => $handlers) {
65
+			if(!is_array($handlers)) {
66 66
 				throw new Exception(sprintf('Transition %s must be configured as an assoc array.', $transName));
67 67
 			}
68 68
 
69
-			foreach ($handlers as $handlerClass => $handlerMethod) {
69
+			foreach($handlers as $handlerClass => $handlerMethod) {
70 70
 				$handlerObj = Injector::inst()->get($handlerClass);
71
-				if (!is_callable([$handlerObj, $handlerMethod])) {
71
+				if(!is_callable([$handlerObj, $handlerMethod])) {
72 72
 					throw new Exception(sprintf('Handler %s is not callable on %s.', $handlerMethod, $handlerClass));
73 73
 				}
74 74
 				$machine->getDispatcher()->addListener(
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,9 @@
 block discarded – undo
58 58
 
59 59
 	protected function addHandlers($machine) {
60 60
 		$class = get_class($machine->getObject());
61
-		if (empty($this->config()->handlers[$class])) return;
61
+		if (empty($this->config()->handlers[$class])) {
62
+			return;
63
+		}
62 64
 
63 65
 		$transitions = $this->config()->handlers[$class];
64 66
 		foreach ($transitions as $transName => $handlers) {
Please login to merge, or discard this patch.
code/control/DNDeploymentHandlers.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	protected function sendEmailToApprover(DNDeployment $deployment) {
13 13
 		$deployer = $deployment->Deployer();
14 14
 		$approver = $deployment->Approver();
15
-		if (!$approver || !$approver->exists()) {
15
+		if(!$approver || !$approver->exists()) {
16 16
 			return false;
17 17
 		}
18 18
 
Please login to merge, or discard this patch.
code/tasks/MigrateDeploymentStatusTask.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -4,28 +4,28 @@
 block discarded – undo
4 4
 
5 5
 	public function run($request) {
6 6
 		$log = function($message) {
7
-			$message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message;
8
-			echo $message . PHP_EOL;
7
+			$message = sprintf('[%s] ', date('Y-m-d H:i:s')).$message;
8
+			echo $message.PHP_EOL;
9 9
 		};
10 10
 
11
-		if (!Director::is_cli()) {
11
+		if(!Director::is_cli()) {
12 12
 			$log('This command can only run via CLI');
13 13
 			return;
14 14
 		}
15 15
 
16 16
 		$columns = DB::query('SHOW COLUMNS FROM "DNDeployment"')->column();
17
-		if (!in_array('Status', $columns)) {
17
+		if(!in_array('Status', $columns)) {
18 18
 			$log('Migration has already been run');
19 19
 			return;
20 20
 		}
21 21
 
22
-		foreach (DB::query('SELECT "ID", "Status" FROM "DNDeployment"') as $record) {
22
+		foreach(DB::query('SELECT "ID", "Status" FROM "DNDeployment"') as $record) {
23 23
 			// This record looks to be already migrated
24
-			if (empty($record['Status'])) {
24
+			if(empty($record['Status'])) {
25 25
 				continue;
26 26
 			}
27 27
 
28
-			switch ($record['Status']) {
28
+			switch($record['Status']) {
29 29
 				case 'Queued':
30 30
 					DB::query(sprintf('UPDATE "DNDeployment" SET "State" = \'Queued\' WHERE "ID" = %s', $record['ID']));
31 31
 					break;
Please login to merge, or discard this patch.
code/jobs/DeployJob.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 	 */
18 18
 	public function alarmHandler() {
19 19
 		$sigFile = $this->args['sigFile'];
20
-		if (file_exists($sigFile) && is_readable($sigFile) && is_writable($sigFile)) {
20
+		if(file_exists($sigFile) && is_readable($sigFile) && is_writable($sigFile)) {
21 21
 			$signal = (int)file_get_contents($sigFile);
22
-			if (is_int($signal) && in_array((int)$signal, [
22
+			if(is_int($signal) && in_array((int)$signal, [
23 23
 				// The following signals are trapped by both Resque and Rainforest.
24 24
 				SIGTERM,
25 25
 				SIGINT,
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 				SIGCONT
31 31
 			])) {
32 32
 				echo sprintf(
33
-					'[-] Signal "%s" received, delivering to own process group, PID "%s".' . PHP_EOL,
33
+					'[-] Signal "%s" received, delivering to own process group, PID "%s".'.PHP_EOL,
34 34
 					$signal,
35 35
 					getmypid()
36 36
 				);
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 
41 41
 				// Dispatch to own process group.
42 42
 				$pgid = posix_getpgid(getmypid());
43
-				if ($pgid<=0) {
43
+				if($pgid <= 0) {
44 44
 					echo sprintf(
45
-						'[-] Unable to send signal to invalid PGID "%s".' . PHP_EOL,
45
+						'[-] Unable to send signal to invalid PGID "%s".'.PHP_EOL,
46 46
 						$pgid
47 47
 					);
48 48
 				} else {
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 		posix_setsid();
62 62
 
63 63
 		if(function_exists('pcntl_alarm') && function_exists('pcntl_signal')) {
64
-			if (!empty($this->args['sigFile'])) {
65
-				echo sprintf('[-] Signal file requested, polling "%s".' . PHP_EOL, $this->args['sigFile']);
64
+			if(!empty($this->args['sigFile'])) {
65
+				echo sprintf('[-] Signal file requested, polling "%s".'.PHP_EOL, $this->args['sigFile']);
66 66
 				declare(ticks = 1);
67 67
 				pcntl_signal(SIGALRM, [$this, 'alarmHandler']);
68 68
 				pcntl_alarm(1);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	}
75 75
 
76 76
 	public function perform() {
77
-		echo "[-] DeployJob starting" . PHP_EOL;
77
+		echo "[-] DeployJob starting".PHP_EOL;
78 78
 		$log = new DeploynautLogFile($this->args['logfile']);
79 79
 
80 80
 		$deployment = DNDeployment::get()->byID($this->args['deploymentID']);
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 			);
110 110
 		} catch(Exception $e) {
111 111
 			// DeploynautJob will automatically trigger onFailure.
112
-			echo "[-] DeployJob failed" . PHP_EOL;
112
+			echo "[-] DeployJob failed".PHP_EOL;
113 113
 			throw $e;
114 114
 		}
115 115
 		$this->updateStatus(DNDeployment::TR_COMPLETE);
116
-		echo "[-] DeployJob finished" . PHP_EOL;
116
+		echo "[-] DeployJob finished".PHP_EOL;
117 117
 	}
118 118
 
119 119
 	public function onFailure(Exception $exception) {
Please login to merge, or discard this patch.