Completed
Branch master (bdef63)
by Sam
01:52
created
src/cli/Jalle19/StatusManager/Configuration.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,8 +92,9 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function setUpdateInterval($updateInterval)
94 94
 	{
95
-		if ($updateInterval <= 0)
96
-			throw new \RuntimeException('Invalid update interval specified');
95
+		if ($updateInterval <= 0) {
96
+					throw new \RuntimeException('Invalid update interval specified');
97
+		}
97 98
 
98 99
 		$this->_updateInterval = $updateInterval;
99 100
 	}
@@ -133,8 +134,9 @@  discard block
 block discarded – undo
133 134
 	 */
134 135
 	public function setListenPort($listenPort)
135 136
 	{
136
-		if ($listenPort < 1 || $listenPort > 65535)
137
-			throw new \RuntimeException('Invalid port specified');
137
+		if ($listenPort < 1 || $listenPort > 65535) {
138
+					throw new \RuntimeException('Invalid port specified');
139
+		}
138 140
 
139 141
 		$this->_listenPort = $listenPort;
140 142
 	}
Please login to merge, or discard this patch.
Jalle19/StatusManager/Console/Commands/TvheadendStatusManagerCommand.php 1 patch
Braces   +20 added lines, -14 removed lines patch added patch discarded remove patch
@@ -124,23 +124,26 @@  discard block
 block discarded – undo
124 124
 	private function parseConfiguration(InputInterface $input)
125 125
 	{
126 126
 		// Check that the configuration file exists
127
-		if (!file_exists($input->getArgument('configFile')))
128
-			throw new InvalidConfigurationException('The specified configuration file does not exist');
127
+		if (!file_exists($input->getArgument('configFile'))) {
128
+					throw new InvalidConfigurationException('The specified configuration file does not exist');
129
+		}
129 130
 
130 131
 		// Check that the database exists and is writable
131 132
 		$databasePath = $input->getArgument('databaseFile');
132 133
 
133
-		if (!file_exists($databasePath))
134
-			throw new InvalidConfigurationException('The specified database path does not exist');
135
-		else if (!is_writable($databasePath))
136
-			throw new InvalidConfigurationException('The specified database path is not writable');
134
+		if (!file_exists($databasePath)) {
135
+					throw new InvalidConfigurationException('The specified database path does not exist');
136
+		} else if (!is_writable($databasePath)) {
137
+					throw new InvalidConfigurationException('The specified database path is not writable');
138
+		}
137 139
 
138 140
 		// Parse the configuration file
139 141
 		$configuration = parse_ini_file($input->getArgument('configFile'), true);
140 142
 
141 143
 		// Check that the file was parsed
142
-		if ($configuration === false)
143
-			throw new InvalidConfigurationException('Failed to parse the specified configuration file');
144
+		if ($configuration === false) {
145
+					throw new InvalidConfigurationException('Failed to parse the specified configuration file');
146
+		}
144 147
 
145 148
 		$instances    = [];
146 149
 
@@ -157,8 +160,9 @@  discard block
 block discarded – undo
157 160
 					$instance = new Instance($name, $address, $port);
158 161
 
159 162
 					// Optionally set credentials
160
-					if (isset($values['username']) && isset($values['password']))
161
-						$instance->setCredentials($values['username'], $values['password']);
163
+					if (isset($values['username']) && isset($values['password'])) {
164
+											$instance->setCredentials($values['username'], $values['password']);
165
+					}
162 166
 
163 167
 					$instances[] = $instance;
164 168
 					break;
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
 		}
167 171
 
168 172
 		// Validate the configuration. We need at least one instance.
169
-		if (empty($instances))
170
-			throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance');
173
+		if (empty($instances)) {
174
+					throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance');
175
+		}
171 176
 
172 177
 		// Create the configuration object
173 178
 		$config = new Configuration($databasePath, $instances);
@@ -196,8 +201,9 @@  discard block
 block discarded – undo
196 201
 	 */
197 202
 	private static function getSectionType($section)
198 203
 	{
199
-		if (substr($section, 0, 8) === 'instance')
200
-			return Configuration::SECTION_TYPE_INSTANCE;
204
+		if (substr($section, 0, 8) === 'instance') {
205
+					return Configuration::SECTION_TYPE_INSTANCE;
206
+		}
201 207
 
202 208
 		throw new InvalidConfigurationException('Unknown section "' . $section . '"');
203 209
 	}
Please login to merge, or discard this patch.
src/cli/Jalle19/StatusManager/PersistenceManager.php 1 patch
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -50,8 +50,9 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function onInstanceSeen(Tvheadend $instance)
52 52
 	{
53
-		if ($this->hasInstance($instance))
54
-			return;
53
+		if ($this->hasInstance($instance)) {
54
+					return;
55
+		}
55 56
 
56 57
 		$instanceModel = new Database\Instance();
57 58
 		$instanceModel->setPrimaryKey($instance->getHostname());
@@ -80,8 +81,9 @@  discard block
 block discarded – undo
80 81
 	 */
81 82
 	public function onConnectionSeen($instanceName, ConnectionStatus $connectionStatus)
82 83
 	{
83
-		if ($this->hasConnection($instanceName, $connectionStatus))
84
-			return;
84
+		if ($this->hasConnection($instanceName, $connectionStatus)) {
85
+					return;
86
+		}
85 87
 
86 88
 		$user = null;
87 89
 
@@ -114,8 +116,9 @@  discard block
 block discarded – undo
114 116
 	 */
115 117
 	public function onUserSeen($instanceName, $userName)
116 118
 	{
117
-		if ($this->hasUser($instanceName, $userName))
118
-			return;
119
+		if ($this->hasUser($instanceName, $userName)) {
120
+					return;
121
+		}
119 122
 
120 123
 		$user = new User();
121 124
 		$user->setInstanceName($instanceName)->setName($userName);
@@ -136,8 +139,9 @@  discard block
 block discarded – undo
136 139
 	 */
137 140
 	public function onChannelSeen($instanceName, $channelName)
138 141
 	{
139
-		if ($this->hasChannel($instanceName, $channelName))
140
-			return;
142
+		if ($this->hasChannel($instanceName, $channelName)) {
143
+					return;
144
+		}
141 145
 
142 146
 		$channel = new Channel();
143 147
 		$channel->setInstanceName($instanceName)->setName($channelName);
@@ -159,8 +163,9 @@  discard block
 block discarded – undo
159 163
 	public function onSubscriptionSeen($instanceName, SubscriptionStatus $status)
160 164
 	{
161 165
 		// Ignore EPG grabber subscriptions
162
-		if ($status->getType() === SubscriptionStatus::TYPE_EPGGRAB)
163
-			return;
166
+		if ($status->getType() === SubscriptionStatus::TYPE_EPGGRAB) {
167
+					return;
168
+		}
164 169
 
165 170
 		// Determine the username to store for the subscription
166 171
 		$username = $status->username;
@@ -180,8 +185,9 @@  discard block
 block discarded – undo
180 185
 		$this->onChannelSeen($instanceName, $status->channel);
181 186
 		$channel = ChannelQuery::create()->filterByInstance($instance)->filterByName($status->channel)->findOne();
182 187
 
183
-		if ($this->hasSubscription($instance, $user, $channel, $status))
184
-			return;
188
+		if ($this->hasSubscription($instance, $user, $channel, $status)) {
189
+					return;
190
+		}
185 191
 
186 192
 		$subscription = new Subscription();
187 193
 		$subscription->setInstance($instance)->setUser($user)->setChannel($channel)
@@ -205,8 +211,9 @@  discard block
 block discarded – undo
205 211
 	public function onSubscriptionStateChange($instanceName, StateChange $stateChange)
206 212
 	{
207 213
 		// We only need to persist subscription stops
208
-		if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED)
209
-			return;
214
+		if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED) {
215
+					return;
216
+		}
210 217
 
211 218
 		// Find the latest matching subscription
212 219
 		$subscription = SubscriptionQuery::create()->filterByInstanceName($instanceName)
Please login to merge, or discard this patch.
src/cli/Jalle19/StatusManager/StatusManager.php 1 patch
Braces   +16 added lines, -14 removed lines patch added patch discarded remove patch
@@ -70,8 +70,9 @@  discard block
 block discarded – undo
70 70
 		$this->_instances        = new \SplObjectStorage();
71 71
 
72 72
 		// Attach a state to each instance
73
-		foreach ($this->_configuration->getInstances() as $instance)
74
-			$this->_instances->attach($instance, new InstanceState());
73
+		foreach ($this->_configuration->getInstances() as $instance) {
74
+					$this->_instances->attach($instance, new InstanceState());
75
+		}
75 76
 
76 77
 		// Start the persistence manager
77 78
 		$this->_persistenceManager = new PersistenceManager($logger);
@@ -147,16 +148,19 @@  discard block
 block discarded – undo
147 148
 			]);
148 149
 
149 150
 			// Persist connections
150
-			foreach ($instanceStatus->getConnections() as $connection)
151
-				$this->_persistenceManager->onConnectionSeen($instanceName, $connection);
151
+			foreach ($instanceStatus->getConnections() as $connection) {
152
+							$this->_persistenceManager->onConnectionSeen($instanceName, $connection);
153
+			}
152 154
 
153 155
 			// Persist running subscriptions
154
-			foreach ($instanceStatus->getSubscriptions() as $subscription)
155
-				$this->_persistenceManager->onSubscriptionSeen($instanceName, $subscription);
156
+			foreach ($instanceStatus->getSubscriptions() as $subscription) {
157
+							$this->_persistenceManager->onSubscriptionSeen($instanceName, $subscription);
158
+			}
156 159
 
157 160
 			// Handle subscription state changes
158
-			foreach ($instanceStatus->getSubscriptionStateChanges() as $subscriptionStateChange)
159
-				$this->_persistenceManager->onSubscriptionStateChange($instanceName, $subscriptionStateChange);
161
+			foreach ($instanceStatus->getSubscriptionStateChanges() as $subscriptionStateChange) {
162
+							$this->_persistenceManager->onSubscriptionStateChange($instanceName, $subscriptionStateChange);
163
+			}
160 164
 		}
161 165
 
162 166
 		// Broadcast the status messages to all connected clients
@@ -204,8 +208,7 @@  discard block
 block discarded – undo
204 208
 
205 209
 						$instanceState->setReachability(InstanceState::REACHABLE);
206 210
 					}
207
-				}
208
-				catch (\Exception $e)
211
+				} catch (\Exception $e)
209 212
 				{
210 213
 					// Mark the instance as unreachable
211 214
 					$message = 'Instance {instanceName} not reachable, will wait for {cycles} cycles before retrying.
@@ -219,8 +222,7 @@  discard block
 block discarded – undo
219 222
 
220 223
 					$instanceState->setReachability(InstanceState::UNREACHABLE);
221 224
 				}
222
-			}
223
-			else
225
+			} else
224 226
 			{
225 227
 				// Wait for some cycles and then mark unreachable instances as maybe reachable
226 228
 				if ($instanceState->getRetryCount() === self::UNREACHABLE_CYCLES_UNTIL_RETRY - 1)
@@ -231,9 +233,9 @@  discard block
 block discarded – undo
231 233
 					$this->_logger->info('Retrying instance {instanceName} during next cycle', [
232 234
 						'instanceName' => $instanceName,
233 235
 					]);
236
+				} else {
237
+									$instanceState->incrementRetryCount();
234 238
 				}
235
-				else
236
-					$instanceState->incrementRetryCount();
237 239
 			}
238 240
 		}
239 241
 
Please login to merge, or discard this patch.
src/cli/Jalle19/StatusManager/Subscription/StateChangeParser.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,8 +29,9 @@  discard block
 block discarded – undo
29 29
 		{
30 30
 			$stateChange = self::parseMessage($logMessage->logtxt);
31 31
 
32
-			if ($stateChange !== null)
33
-				$stateChanges[] = $stateChange;
32
+			if ($stateChange !== null) {
33
+							$stateChanges[] = $stateChange;
34
+			}
34 35
 		}
35 36
 
36 37
 		return $stateChanges;
@@ -54,10 +55,11 @@  discard block
 block discarded – undo
54 55
 			$stateChange = new StateChange(self::getSubscriptionId($messageParts[3]));
55 56
 
56 57
 			// Check the state
57
-			if (strpos($message, 'subscribing on channel') !== false)
58
-				$stateChange->setState(StateChange::STATE_SUBSCRIPTION_STARTED);
59
-			else if (strpos($message, 'unsubscribing from'))
60
-				$stateChange->setState(StateChange::STATE_SUBSCRIPTION_STOPPED);
58
+			if (strpos($message, 'subscribing on channel') !== false) {
59
+							$stateChange->setState(StateChange::STATE_SUBSCRIPTION_STARTED);
60
+			} else if (strpos($message, 'unsubscribing from')) {
61
+							$stateChange->setState(StateChange::STATE_SUBSCRIPTION_STOPPED);
62
+			}
61 63
 
62 64
 			return $stateChange;
63 65
 		}
Please login to merge, or discard this patch.