Completed
Push — master ( a9ad96...04f2d0 )
by Nicolas
02:49
created
src/SA/CpeSdk/CpeActivity.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         // Check if there is an activity name
50 50
         if (!isset($params["name"]) || !$params["name"])
51 51
             throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'name' is not provided or empty !\n", 
52
-			    self::NO_ACTIVITY_NAME);
52
+                self::NO_ACTIVITY_NAME);
53 53
         
54 54
         if (!$cpeLogger)
55 55
             $this->cpeLogger = new CpeSdk\CpeLogger(null, $params["name"]); 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         // Check if there is a version name
62 62
         if (!isset($params["version"]) || !$params["version"])
63 63
             throw new CpeSdk\CpeException("Can't instantiate BasicActivity: 'version' is not provided or empty !\n", 
64
-			    self::NO_ACTIVITY_VERSION);
64
+                self::NO_ACTIVITY_VERSION);
65 65
 
66 66
         // Initialize the activity in SWF if necessary
67 67
         $this->init_activity();
@@ -106,12 +106,12 @@  discard block
 block discarded – undo
106 106
     {
107 107
         if (!$task)
108 108
             throw new CpeSdk\CpeException("Activity Task empty !", 
109
-			    self::ACTIVITY_TASK_EMPTY); 
109
+                self::ACTIVITY_TASK_EMPTY); 
110 110
         
111 111
         if (!isset($task["input"]) || !$task["input"] ||
112 112
             $task["input"] == "")
113 113
             throw new CpeSdk\CpeException("No input provided to 'Activity'", 
114
-			    self::NO_INPUT);
114
+                self::NO_INPUT);
115 115
         
116 116
         // Save input string
117 117
         $this->input_str      = $task["input"];
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         // Check JSON input
136 136
         if (!($this->input = json_decode($this->input_str)))
137 137
             throw new CpeSdk\CpeException("JSON input is invalid !", 
138
-			    self::INPUT_INVALID);
138
+                self::INPUT_INVALID);
139 139
     }
140 140
     
141 141
     /**
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,20 +11,20 @@  discard block
 block discarded – undo
11 11
 
12 12
 class CpeActivity
13 13
 {
14
-    public $params;          // Activity params coming from ActivityPoller
15
-    public $debug;           // Debug flag
14
+    public $params; // Activity params coming from ActivityPoller
15
+    public $debug; // Debug flag
16 16
     
17
-    public $activityId;      // ID of the activity
18
-    public $activityType;    // Type of activity
17
+    public $activityId; // ID of the activity
18
+    public $activityType; // Type of activity
19 19
     
20
-    public $cpeLogger;       // Logger
21
-    public $cpeSqsWriter;    // Used to write messages in SQS
22
-    public $cpeSwfHandler;   // USed to control SWF
23
-    public $cpeJsonValidator;// Run JSON schemas validation
20
+    public $cpeLogger; // Logger
21
+    public $cpeSqsWriter; // Used to write messages in SQS
22
+    public $cpeSwfHandler; // USed to control SWF
23
+    public $cpeJsonValidator; // Run JSON schemas validation
24 24
     
25
-    public $input_str;       // Complete activity input string
26
-    public $input;           // Complete activity input JSON object
27
-    public $activityLogKey;  // Create a key workflowId:activityId to put in logs
25
+    public $input_str; // Complete activity input string
26
+    public $input; // Complete activity input JSON object
27
+    public $activityLogKey; // Create a key workflowId:activityId to put in logs
28 28
     
29 29
     const HEARTBEAT_FAILED     = "HEARTBEAT_FAILED";
30 30
     const NO_ACTIVITY_NAME     = "NO_ACTIVITY_NAME";
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         // For listening to the Input SQS queue 
45 45
         $this->cpeJsonValidator = new CpeSdk\CpeJsonValidator();     
46 46
         // Save activity params
47
-        $this->params        = $params;
47
+        $this->params = $params;
48 48
 
49 49
         // Check if there is an activity name
50 50
         if (!isset($params["name"]) || !$params["name"])
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
             return true;
91 91
         } catch (\Aws\Swf\Exception\UnknownResourceException $e) {
92 92
             $this->cpeLogger->log_out("ERROR", basename(__FILE__), 
93
-                "Activity '" . $this->params["name"] . "' doesn't exists. Creating it ...\n");
93
+                "Activity '".$this->params["name"]."' doesn't exists. Creating it ...\n");
94 94
         }
95 95
         
96 96
         // Register activites if doesn't exists in SWF
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
                 ));
171 171
         } catch (\Exception $e) {
172 172
             $this->cpeLogger->log_out("ERROR", basename(__FILE__), 
173
-                "Unable to send 'Task Failed' response ! " . $e->getMessage(),
173
+                "Unable to send 'Task Failed' response ! ".$e->getMessage(),
174 174
                 $this->activityLogKey);
175 175
             return false;
176 176
         }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
                 ));
196 196
         } catch (\Exception $e) {
197 197
             $this->cpeLogger->log_out("ERROR", basename(__FILE__), 
198
-                "Unable to send 'Task Completed' response ! " . $e->getMessage(),
198
+                "Unable to send 'Task Completed' response ! ".$e->getMessage(),
199 199
                 $this->activityLogKey);
200 200
             return false;
201 201
         }
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             if ($info->get("cancelRequested") == true)
224 224
             {
225 225
                 $this->cpeLogger->log_out("WARNING", basename(__FILE__), 
226
-                    "Cancel has been requested for this task '" . $task->get("activityId") . "' ! Killing task ...",
226
+                    "Cancel has been requested for this task '".$task->get("activityId")."' ! Killing task ...",
227 227
                     $this->activityLogKey);
228 228
                 throw new CpeSdk\CpeException("Cancel request. No heartbeat, leaving!",
229 229
                     self::HEARTBEAT_FAILED);
Please login to merge, or discard this 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.
src/SA/CpeSdk/CpeException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,6 +16,6 @@
 block discarded – undo
16 16
     
17 17
     // custom string representation of object
18 18
     public function __toString() {
19
-        return __CLASS__ . ": [{$this->ref}]: {$this->message}\n";
19
+        return __CLASS__.": [{$this->ref}]: {$this->message}\n";
20 20
     }
21 21
 }
Please login to merge, or discard this patch.
src/SA/CpeSdk/CpeJsonValidator.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@
 block discarded – undo
10 10
         $schemas_path)
11 11
     {
12 12
         $retriever    = new JsonSchema\Uri\UriRetriever;
13
-        $json_schemas = $retriever->retrieve('file://' . $schemas_path . "/$schemas_name");
13
+        $json_schemas = $retriever->retrieve('file://'.$schemas_path."/$schemas_name");
14 14
 
15 15
         $refResolver  = new JsonSchema\RefResolver($retriever);
16
-        $refResolver->resolve($json_schemas, 'file://' . $schemas_path . "/");
16
+        $refResolver->resolve($json_schemas, 'file://'.$schemas_path."/");
17 17
 
18 18
         $validator    = new JsonSchema\Validator();
19 19
         $validator->check($json, $json_schemas);
Please login to merge, or discard this 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/CpeLogger.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             $log["workflowId"] = $workflowId;
55 55
 
56 56
         // Open Syslog. Use programe name as key
57
-        if (!openlog (__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1))
57
+        if (!openlog(__FILE__, LOG_CONS|LOG_PID, LOG_LOCAL1))
58 58
             throw new CpeException("Unable to connect to Syslog!",
59 59
                 OPENLOG_ERROR);
60 60
         
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
         if (!is_string($log['message']))
97 97
             $log['message'] = json_encode($log['message']);
98 98
         
99
-        $toPrint = $log['time'] . " [" . $log['type'] . "] [" . $log['source'] . "] ";
99
+        $toPrint = $log['time']." [".$log['type']."] [".$log['source']."] ";
100 100
         // If there is a workflow ID. We append it.
101 101
         if ($workflowId)
102 102
             $toPrint .= "[$workflowId] ";
103
-        $toPrint .= $log['message'] . "\n";
103
+        $toPrint .= $log['message']."\n";
104 104
             
105 105
         if (file_put_contents(
106 106
                 $this->logPath,
Please login to merge, or discard this 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/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 2 patches
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.
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -98,6 +98,10 @@  discard block
 block discarded – undo
98 98
         );
99 99
     }
100 100
 
101
+    /**
102
+     * @param string $reason
103
+     * @param string $details
104
+     */
101 105
     public function activity_failed($task, $reason, $details)
102 106
     {
103 107
         $this->send_activity_msg(
@@ -169,6 +173,11 @@  discard block
 block discarded – undo
169 173
     }
170 174
 
171 175
     // Send a message to SQS output queue
176
+
177
+    /**
178
+     * @param string $eventType
179
+     * @param boolean $sendInput
180
+     */
172 181
     private function send_activity_msg(
173 182
         $activityTask, 
174 183
         $eventType, 
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.