@@ -1,9 +1,9 @@ |
||
1 | 1 | #!/usr/bin/env php |
2 | 2 | <?php |
3 | 3 | |
4 | -define('BASE_DIR', realpath(__DIR__.'/..')); |
|
4 | +define('BASE_DIR', realpath(__DIR__ . '/..')); |
|
5 | 5 | define('PHAR_FILENAME', 'pheanstalk.phar'); |
6 | -define('PHAR_FULLPATH', BASE_DIR.'/'.PHAR_FILENAME); |
|
6 | +define('PHAR_FULLPATH', BASE_DIR . '/' . PHAR_FILENAME); |
|
7 | 7 | |
8 | 8 | // ---------------------------------------- |
9 | 9 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | if (!$this->_socket) { |
46 | - throw new Exception\ConnectionException($errno, $errstr." (connecting to $host:$port)"); |
|
46 | + throw new Exception\ConnectionException($errno, $errstr . " (connecting to $host:$port)"); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | $this->_wrapper() |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | public function recv() |
102 | 102 | { |
103 | 103 | $response = ""; |
104 | - while($recv = $this->_wrapper()->fread($this->_socket, 1600)){ |
|
104 | + while ($recv = $this->_wrapper()->fread($this->_socket, 1600)) { |
|
105 | 105 | $response .= $recv; |
106 | 106 | } |
107 | 107 | return $response; |
@@ -123,14 +123,13 @@ discard block |
||
123 | 123 | do { |
124 | 124 | libxml_clear_errors(); |
125 | 125 | $data .= isset($length) ? |
126 | - $this->_wrapper()->fgets($this->_socket, $length) : |
|
127 | - $this->_wrapper()->fgets($this->_socket); |
|
126 | + $this->_wrapper()->fgets($this->_socket, $length) : $this->_wrapper()->fgets($this->_socket); |
|
128 | 127 | simplexml_load_string($data); |
129 | 128 | if (!empty(libxml_get_errors()) && microtime(true) - $timer > $timeout) { |
130 | 129 | $this->disconnect(); |
131 | 130 | throw new Exception\SocketException('Socket timed out!'); |
132 | - } elseif(empty(libxml_get_errors())) { |
|
133 | - try{ |
|
131 | + } elseif (empty(libxml_get_errors())) { |
|
132 | + try { |
|
134 | 133 | $xml = new \SimpleXMLElement($data); |
135 | 134 | } catch (\Exception $e) { |
136 | 135 | $error = (string) (isset($xml['error'])) ? $xml['error'] : 'Socket closed by server!'; |
@@ -51,7 +51,7 @@ |
||
51 | 51 | $this->workflow = $workflow; |
52 | 52 | $this->schedule = $schedule; |
53 | 53 | $this->onFailure = $onFailure ?? self::FAILURE_TYPE_CONTINUE; |
54 | - $this->active = $active ?? true ; |
|
54 | + $this->active = $active ?? true; |
|
55 | 55 | $this->comment = $comment ?? $this->workflow->getComment(); |
56 | 56 | } |
57 | 57 |
@@ -42,6 +42,6 @@ |
||
42 | 42 | return $tube->getName() === $name; |
43 | 43 | }); |
44 | 44 | |
45 | - return !$matchingTubes->isEmpty() ? $matchingTubes->first() : false; |
|
45 | + return !$matchingTubes->isEmpty() ? $matchingTubes->first() : false; |
|
46 | 46 | } |
47 | 47 | } |
@@ -72,13 +72,13 @@ |
||
72 | 72 | |
73 | 73 | $subjobs = $responseData['workflow']['subjobs']; |
74 | 74 | $jobInstances = new ArrayCollection([]); |
75 | - foreach($subjobs as $subjob) { |
|
75 | + foreach ($subjobs as $subjob) { |
|
76 | 76 | $taskInstances = new ArrayCollection([]); |
77 | - foreach($subjob['tasks'] as $tasks) { |
|
77 | + foreach ($subjob['tasks'] as $tasks) { |
|
78 | 78 | $task = $tasks['@attributes']; |
79 | 79 | |
80 | 80 | if (isset($task['execution_time'])) $task['execution_time'] = new \DateTime($task['execution_time']); |
81 | - foreach($task as $key => $val) |
|
81 | + foreach ($task as $key => $val) |
|
82 | 82 | if (ctype_digit($val)) $task[$key] = (int) $task[$key]; |
83 | 83 | $taskInstances[] = new TaskInstance($task); |
84 | 84 | } |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | public function parseResponse($responseLine, $responseData) |
68 | 68 | { |
69 | 69 | |
70 | - if (!(isset($responseData['workflow']))) |
|
71 | - return false; |
|
70 | + if (!(isset($responseData['workflow']))) { |
|
71 | + return false; |
|
72 | + } |
|
72 | 73 | |
73 | 74 | $subjobs = $responseData['workflow']['subjobs']; |
74 | 75 | $jobInstances = new ArrayCollection([]); |
@@ -77,9 +78,12 @@ discard block |
||
77 | 78 | foreach($subjob['tasks'] as $tasks) { |
78 | 79 | $task = $tasks['@attributes']; |
79 | 80 | |
80 | - if (isset($task['execution_time'])) $task['execution_time'] = new \DateTime($task['execution_time']); |
|
81 | - foreach($task as $key => $val) |
|
82 | - if (ctype_digit($val)) $task[$key] = (int) $task[$key]; |
|
81 | + if (isset($task['execution_time'])) { |
|
82 | + $task['execution_time'] = new \DateTime($task['execution_time']); |
|
83 | + } |
|
84 | + foreach($task as $key => $val) { |
|
85 | + if (ctype_digit($val)) $task[$key] = (int) $task[$key]; |
|
86 | + } |
|
83 | 87 | $taskInstances[] = new TaskInstance($task); |
84 | 88 | } |
85 | 89 | $jobInstances[] = new JobInstance($taskInstances); |
@@ -73,7 +73,7 @@ |
||
73 | 73 | $responseData = array_column($responseData, '@attributes'); |
74 | 74 | $dates = array_column($responseData, 'start_time'); |
75 | 75 | $mostRecent = []; |
76 | - foreach($responseData as $date){ |
|
76 | + foreach ($responseData as $date) { |
|
77 | 77 | $curDate = strtotime($date['start_time']); |
78 | 78 | if (!isset($mostRecent['start_time']) || $curDate < strtotime($mostRecent['start_time'])) { |
79 | 79 | $mostRecent = $date; |
@@ -79,7 +79,9 @@ |
||
79 | 79 | $mostRecent = $date; |
80 | 80 | } |
81 | 81 | } |
82 | - if (empty($responseData)) return $this->parseResponse($responseLine, $responseData); |
|
82 | + if (empty($responseData)) { |
|
83 | + return $this->parseResponse($responseLine, $responseData); |
|
84 | + } |
|
83 | 85 | return $this->_createResponse( |
84 | 86 | Response::RESPONSE_FOUND, |
85 | 87 | array( |
@@ -67,9 +67,9 @@ |
||
67 | 67 | $jobs = $workflow['workflow']['subjobs']; |
68 | 68 | $workflow = $workflow['@attributes'] ?? $workflow; |
69 | 69 | $jobObjects = []; |
70 | - foreach($jobs as $job) { |
|
70 | + foreach ($jobs as $job) { |
|
71 | 71 | $taskObjects = []; |
72 | - foreach($job['tasks'] as $task) { |
|
72 | + foreach ($job['tasks'] as $task) { |
|
73 | 73 | $task = $task['@attributes']; |
74 | 74 | $taskObjects[] = new Task($task['path'], $task['queue'], $task['use-agent'], $task['user'], $task['host'], $task['output-method'], $task['parameters-mode']); |
75 | 75 | } |
@@ -42,6 +42,6 @@ |
||
42 | 42 | return $workflow->getName() === $name; |
43 | 43 | }); |
44 | 44 | |
45 | - return !$matchingWorkflows->isEmpty() ? $matchingWorkflows->first() : false; |
|
45 | + return !$matchingWorkflows->isEmpty() ? $matchingWorkflows->first() : false; |
|
46 | 46 | } |
47 | 47 | } |
@@ -91,20 +91,19 @@ |
||
91 | 91 | if (!(isset($responseData['workflow']))) |
92 | 92 | return new ArrayCollection([]); |
93 | 93 | |
94 | - $instances = $responseData['workflow'] ; |
|
94 | + $instances = $responseData['workflow']; |
|
95 | 95 | $instances = isset($instances['tags']) ? [$instances['@attributes']] : $instances; |
96 | 96 | $workflowInstances = new ArrayCollection([]); |
97 | - foreach($instances as $instance) { |
|
97 | + foreach ($instances as $instance) { |
|
98 | 98 | $instance = $instance['@attributes'] ?? $instance; |
99 | 99 | if (isset($instance['start_time'])) $instance['start_time'] = new \DateTime($instance['start_time']); |
100 | 100 | if (isset($instance['end_time'])) $instance['end_time'] = new \DateTime($instance['end_time']); |
101 | - foreach($instance as $key => $val) |
|
101 | + foreach ($instance as $key => $val) |
|
102 | 102 | if (ctype_digit($val)) $instance[$key] = (int) $instance[$key]; |
103 | 103 | $workflowInstances[] = new WorkflowInstance($instance); |
104 | 104 | } |
105 | 105 | $collection['rows'] = (int) (isset($responseData['@attributes']['rows'])) ? |
106 | - (int) $responseData['@attributes']['rows'] : |
|
107 | - $workflowInstances->count(); |
|
106 | + (int) $responseData['@attributes']['rows'] : $workflowInstances->count(); |
|
108 | 107 | $collection['page'] = $this->page; |
109 | 108 | $collection['workflow_instances'] = $workflowInstances; |
110 | 109 | return new ArrayCollection($collection); |
@@ -76,8 +76,9 @@ discard block |
||
76 | 76 | 'offset' => $offset, |
77 | 77 | 'limit' => $limit |
78 | 78 | ]; |
79 | - if (!empty($this->workflow)) |
|
80 | - $filters['filter_workflow'] = $this->workflow->getName(); |
|
79 | + if (!empty($this->workflow)) { |
|
80 | + $filters['filter_workflow'] = $this->workflow->getName(); |
|
81 | + } |
|
81 | 82 | |
82 | 83 | return $filters; |
83 | 84 | } |
@@ -88,18 +89,24 @@ discard block |
||
88 | 89 | public function parseResponse($responseLine, $responseData) |
89 | 90 | { |
90 | 91 | |
91 | - if (!(isset($responseData['workflow']))) |
|
92 | - return new ArrayCollection([]); |
|
92 | + if (!(isset($responseData['workflow']))) { |
|
93 | + return new ArrayCollection([]); |
|
94 | + } |
|
93 | 95 | |
94 | 96 | $instances = $responseData['workflow'] ; |
95 | 97 | $instances = isset($instances['tags']) ? [$instances['@attributes']] : $instances; |
96 | 98 | $workflowInstances = new ArrayCollection([]); |
97 | 99 | foreach($instances as $instance) { |
98 | 100 | $instance = $instance['@attributes'] ?? $instance; |
99 | - if (isset($instance['start_time'])) $instance['start_time'] = new \DateTime($instance['start_time']); |
|
100 | - if (isset($instance['end_time'])) $instance['end_time'] = new \DateTime($instance['end_time']); |
|
101 | - foreach($instance as $key => $val) |
|
102 | - if (ctype_digit($val)) $instance[$key] = (int) $instance[$key]; |
|
101 | + if (isset($instance['start_time'])) { |
|
102 | + $instance['start_time'] = new \DateTime($instance['start_time']); |
|
103 | + } |
|
104 | + if (isset($instance['end_time'])) { |
|
105 | + $instance['end_time'] = new \DateTime($instance['end_time']); |
|
106 | + } |
|
107 | + foreach($instance as $key => $val) { |
|
108 | + if (ctype_digit($val)) $instance[$key] = (int) $instance[$key]; |
|
109 | + } |
|
103 | 110 | $workflowInstances[] = new WorkflowInstance($instance); |
104 | 111 | } |
105 | 112 | $collection['rows'] = (int) (isset($responseData['@attributes']['rows'])) ? |