Completed
Push — master ( a9ad96...04f2d0 )
by Nicolas
02:49
created
src/SA/CpeSdk/CpeJsonValidator.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,12 +18,14 @@
 block discarded – undo
18 18
         $validator    = new JsonSchema\Validator();
19 19
         $validator->check($json, $json_schemas);
20 20
 
21
-        if ($validator->isValid())
22
-            return false;
21
+        if ($validator->isValid()) {
22
+                    return false;
23
+        }
23 24
     
24 25
         $details = "";
25
-        foreach ($validator->getErrors() as $error)
26
-            $details .= sprintf("[%s] %s\n", $error['property'], $error['message']);
26
+        foreach ($validator->getErrors() as $error) {
27
+                    $details .= sprintf("[%s] %s\n", $error['property'], $error['message']);
28
+        }
27 29
     
28 30
         return $details;
29 31
     }
Please login to merge, or discard this patch.
src/SA/CpeSdk/Sqs/CpeSqsListener.php 1 patch
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,10 +31,11 @@  discard block
 block discarded – undo
31 31
         $this->sqs = $aws->get('Sqs');
32 32
 
33 33
         // Logger
34
-        if (!$cpeLogger)
35
-            $this->cpeLogger = new CpeSdk\CpeLogger();
36
-        else
37
-            $this->cpeLogger = $cpeLogger;
34
+        if (!$cpeLogger) {
35
+                    $this->cpeLogger = new CpeSdk\CpeLogger();
36
+        } else {
37
+                    $this->cpeLogger = $cpeLogger;
38
+        }
38 39
     }
39 40
     
40 41
     /**
@@ -45,12 +46,13 @@  discard block
 block discarded – undo
45 46
     // Poll one message at a time from the provided SQS queue
46 47
     public function receive_message($queue, $timeout)
47 48
     {
48
-        if ($this->debug)
49
-            $this->cpeLogger->log_out(
49
+        if ($this->debug) {
50
+                    $this->cpeLogger->log_out(
50 51
                 "DEBUG", 
51 52
                 basename(__FILE__),
52 53
                 "Polling from '$queue' ..."
53 54
             );
55
+        }
54 56
             
55 57
         // Poll from SQS to check for new message 
56 58
         $result = $this->sqs->receiveMessage(array(
@@ -62,12 +64,13 @@  discard block
 block discarded – undo
62 64
         if (($messages = $result->get('Messages')) &&
63 65
             count($messages))
64 66
         {
65
-            if ($this->debug)
66
-                $this->cpeLogger->log_out(
67
+            if ($this->debug) {
68
+                            $this->cpeLogger->log_out(
67 69
                     "DEBUG", 
68 70
                     basename(__FILE__),
69 71
                     "New messages recieved in queue: '$queue'"
70 72
                 );
73
+            }
71 74
             
72 75
             return $messages[0];
73 76
         }
Please login to merge, or discard this patch.
src/SA/CpeSdk/Sqs/CpeSqsWriter.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -175,9 +175,10 @@  discard block
 block discarded – undo
175 175
         $sendInput = null, 
176 176
         $result = null)
177 177
     {
178
-        if (!($input = json_decode($activityTask->get('input'))))
179
-            throw new CpeException("Task input JSON is invalid!\n".$activityTask->get('input'),
178
+        if (!($input = json_decode($activityTask->get('input')))) {
179
+                    throw new CpeException("Task input JSON is invalid!\n".$activityTask->get('input'),
180 180
                 INVALID_JSON);
181
+        }
181 182
         
182 183
         $activity = [
183 184
             'activityId'   => $activityTask->get('activityId'),
@@ -185,12 +186,14 @@  discard block
 block discarded – undo
185 186
         ];
186 187
         
187 188
         // Want to send back the input data ?
188
-        if ($sendInput)
189
-            $activity['input'] = $input;
189
+        if ($sendInput) {
190
+                    $activity['input'] = $input;
191
+        }
190 192
         
191 193
         // Extra data? Concat to data array.
192
-        if ($result)
193
-            $activity['result'] = $result;
194
+        if ($result) {
195
+                    $activity['result'] = $result;
196
+        }
194 197
         
195 198
         // Initial data structure
196 199
         $data = array(
Please login to merge, or discard this patch.
src/SA/CpeSdk/Swf/CpeSwfHandler.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@
 block discarded – undo
18 18
     public function __construct()
19 19
     {
20 20
         # Check if preper env vars are setup
21
-        if (!($region = getenv("AWS_DEFAULT_REGION")))
22
-            throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!");
21
+        if (!($region = getenv("AWS_DEFAULT_REGION"))) {
22
+                    throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!");
23
+        }
23 24
 
24 25
         // SWF client
25 26
         $this->swf = SwfClient::factory(array(
Please login to merge, or discard this patch.
src/SA/CpeSdk/CpeLogger.php 1 patch
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -28,15 +28,18 @@  discard block
 block discarded – undo
28 28
         $this->printout = $printout;
29 29
         $this->logPath = "/var/tmp/logs/cpe/";
30 30
                 
31
-        if ($logPath)
32
-            $this->logPath = $logPath;
31
+        if ($logPath) {
32
+                    $this->logPath = $logPath;
33
+        }
33 34
 
34
-        if (!file_exists($this->logPath))
35
-            mkdir($this->logPath, 0755, true);
35
+        if (!file_exists($this->logPath)) {
36
+                    mkdir($this->logPath, 0755, true);
37
+        }
36 38
 
37 39
         $file = basename($argv[0]);
38
-        if ($suffix)
39
-            $file .= "-".$suffix;
40
+        if ($suffix) {
41
+                    $file .= "-".$suffix;
42
+        }
40 43
         // Append progname to the path
41 44
         $this->logPath .= "/".$file.".log";
42 45
 
@@ -60,13 +63,15 @@  discard block
 block discarded – undo
60 63
             "message" => $message
61 64
         ];
62 65
     
63
-        if ($workflowId)
64
-            $log["workflowId"] = $workflowId;
66
+        if ($workflowId) {
67
+                    $log["workflowId"] = $workflowId;
68
+        }
65 69
 
66 70
         // Open Syslog. Use programe name as key
67
-        if (!openlog (__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1))
68
-            throw new CpeException("Unable to connect to Syslog!",
71
+        if (!openlog (__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1)) {
72
+                    throw new CpeException("Unable to connect to Syslog!",
69 73
                 OPENLOG_ERROR);
74
+        }
70 75
         
71 76
         // Change Syslog priority level
72 77
         switch ($type)
@@ -103,22 +108,26 @@  discard block
 block discarded – undo
103 108
     // Write log in file
104 109
     private function print_to_file($log, $workflowId)
105 110
     {
106
-        if (!is_string($log['message']))
107
-            $log['message'] = json_encode($log['message']);
111
+        if (!is_string($log['message'])) {
112
+                    $log['message'] = json_encode($log['message']);
113
+        }
108 114
         
109 115
         $toPrint = $log['time'] . " [" . $log['type'] . "] [" . $log['source'] . "] ";
110 116
         // If there is a workflow ID. We append it.
111
-        if ($workflowId)
112
-            $toPrint .= "[$workflowId] ";
117
+        if ($workflowId) {
118
+                    $toPrint .= "[$workflowId] ";
119
+        }
113 120
         $toPrint .= $log['message'] . "\n";
114 121
 
115
-        if ($this->printout)
116
-            print $toPrint;
122
+        if ($this->printout) {
123
+                    print $toPrint;
124
+        }
117 125
         
118 126
         if (file_put_contents(
119 127
                 $this->logPath,
120 128
                 $toPrint,
121
-                FILE_APPEND) === false)
122
-            print "ERROR: Can't write into log file!\n";
129
+                FILE_APPEND) === false) {
130
+                    print "ERROR: Can't write into log file!\n";
131
+        }
123 132
     }
124 133
 }
125 134
\ No newline at end of file
Please login to merge, or discard this patch.
src/SA/CpeSdk/CpeActivity.php 1 patch
Braces   +21 added lines, -15 removed lines patch added patch discarded remove patch
@@ -47,21 +47,24 @@  discard block
 block discarded – undo
47 47
         $this->params        = $params;
48 48
 
49 49
         // Check if there is an activity name
50
-        if (!isset($params["name"]) || !$params["name"])
51
-            throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'name' is not provided or empty !\n", 
50
+        if (!isset($params["name"]) || !$params["name"]) {
51
+                    throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'name' is not provided or empty !\n", 
52 52
 			    self::NO_ACTIVITY_NAME);
53
+        }
53 54
         
54
-        if (!$cpeLogger)
55
-            $this->cpeLogger = new CpeSdk\CpeLogger(null, $params["name"], $debug); 
56
-        else
57
-            $this->cpeLogger = $cpeLogger;
55
+        if (!$cpeLogger) {
56
+                    $this->cpeLogger = new CpeSdk\CpeLogger(null, $params["name"], $debug);
57
+        } else {
58
+                    $this->cpeLogger = $cpeLogger;
59
+        }
58 60
         
59 61
         // Create logger object. Use activity name for logger
60 62
 
61 63
         // Check if there is a version name
62
-        if (!isset($params["version"]) || !$params["version"])
63
-            throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'version' is not provided or empty !\n", 
64
+        if (!isset($params["version"]) || !$params["version"]) {
65
+                    throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'version' is not provided or empty !\n", 
64 66
 			    self::NO_ACTIVITY_VERSION);
67
+        }
65 68
 
66 69
         // Initialize the activity in SWF if necessary
67 70
         $this->init_activity();
@@ -104,14 +107,16 @@  discard block
 block discarded – undo
104 107
      */
105 108
     public function do_task_check($task)
106 109
     {
107
-        if (!$task)
108
-            throw new CpeSdk\CpeException("Activity Task empty !", 
109
-			    self::ACTIVITY_TASK_EMPTY); 
110
+        if (!$task) {
111
+                    throw new CpeSdk\CpeException("Activity Task empty !", 
112
+			    self::ACTIVITY_TASK_EMPTY);
113
+        }
110 114
         
111 115
         if (!isset($task["input"]) || !$task["input"] ||
112
-            $task["input"] == "")
113
-            throw new CpeSdk\CpeException("No input provided to 'Activity'", 
116
+            $task["input"] == "") {
117
+                    throw new CpeSdk\CpeException("No input provided to 'Activity'", 
114 118
 			    self::NO_INPUT);
119
+        }
115 120
         
116 121
         // Save input string
117 122
         $this->input_str      = $task["input"];
@@ -133,9 +138,10 @@  discard block
 block discarded – undo
133 138
     public function do_input_validation()
134 139
     {
135 140
         // Check JSON input
136
-        if (!($this->input = json_decode($this->input_str)))
137
-            throw new CpeSdk\CpeException("JSON input is invalid !", 
141
+        if (!($this->input = json_decode($this->input_str))) {
142
+                    throw new CpeSdk\CpeException("JSON input is invalid !", 
138 143
 			    self::INPUT_INVALID);
144
+        }
139 145
     }
140 146
     
141 147
     /**
Please login to merge, or discard this patch.