Completed
Branch master (a15a51)
by Sam
01:56
created
src/cli/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.
src/cli/Console/Commands/TvheadendStatusManagerCommand.php 1 patch
Braces   +23 added lines, -16 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,12 +160,14 @@  discard block
 block discarded – undo
157 160
 					$instance = new Instance($name, $address, $port);
158 161
 
159 162
 					// Optionally set ignored users
160
-					if (isset($values['ignoredUsers']))
161
-						$instance->setIgnoredUsers($values['ignoredUsers']);
163
+					if (isset($values['ignoredUsers'])) {
164
+											$instance->setIgnoredUsers($values['ignoredUsers']);
165
+					}
162 166
 
163 167
 					// Optionally set credentials
164
-					if (isset($values['username']) && isset($values['password']))
165
-						$instance->setCredentials($values['username'], $values['password']);
168
+					if (isset($values['username']) && isset($values['password'])) {
169
+											$instance->setCredentials($values['username'], $values['password']);
170
+					}
166 171
 
167 172
 					$instances[] = $instance;
168 173
 					break;
@@ -170,8 +175,9 @@  discard block
 block discarded – undo
170 175
 		}
171 176
 
172 177
 		// Validate the configuration. We need at least one instance.
173
-		if (empty($instances))
174
-			throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance');
178
+		if (empty($instances)) {
179
+					throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance');
180
+		}
175 181
 
176 182
 		// Create the configuration object
177 183
 		$config = new Configuration($databasePath, $instances);
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 	 */
201 207
 	private static function getSectionType($section)
202 208
 	{
203
-		if (substr($section, 0, 8) === 'instance')
204
-			return Configuration::SECTION_TYPE_INSTANCE;
209
+		if (substr($section, 0, 8) === 'instance') {
210
+					return Configuration::SECTION_TYPE_INSTANCE;
211
+		}
205 212
 
206 213
 		throw new InvalidConfigurationException('Unknown section "' . $section . '"');
207 214
 	}
Please login to merge, or discard this patch.
src/cli/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/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.
src/cli/StatusManager.php 1 patch
Braces   +19 added lines, -16 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,20 +148,24 @@  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 inputs
154
-			foreach($instanceStatus->getInputs() as $input)
155
-				$this->_persistenceManager->onInputSeen($instanceName, $input);
156
+			foreach($instanceStatus->getInputs() as $input) {
157
+							$this->_persistenceManager->onInputSeen($instanceName, $input);
158
+			}
156 159
 
157 160
 			// Persist running subscriptions
158
-			foreach ($instanceStatus->getSubscriptions() as $subscription)
159
-				$this->_persistenceManager->onSubscriptionSeen($instanceName, $subscription);
161
+			foreach ($instanceStatus->getSubscriptions() as $subscription) {
162
+							$this->_persistenceManager->onSubscriptionSeen($instanceName, $subscription);
163
+			}
160 164
 
161 165
 			// Handle subscription state changes
162
-			foreach ($instanceStatus->getSubscriptionStateChanges() as $subscriptionStateChange)
163
-				$this->_persistenceManager->onSubscriptionStateChange($instanceName, $subscriptionStateChange);
166
+			foreach ($instanceStatus->getSubscriptionStateChanges() as $subscriptionStateChange) {
167
+							$this->_persistenceManager->onSubscriptionStateChange($instanceName, $subscriptionStateChange);
168
+			}
164 169
 		}
165 170
 
166 171
 		// Broadcast the status messages to all connected clients
@@ -208,8 +213,7 @@  discard block
 block discarded – undo
208 213
 
209 214
 						$instanceState->setReachability(InstanceState::REACHABLE);
210 215
 					}
211
-				}
212
-				catch (\Exception $e)
216
+				} catch (\Exception $e)
213 217
 				{
214 218
 					// Mark the instance as unreachable
215 219
 					$message = 'Instance {instanceName} not reachable, will wait for {cycles} cycles before retrying.
@@ -223,8 +227,7 @@  discard block
 block discarded – undo
223 227
 
224 228
 					$instanceState->setReachability(InstanceState::UNREACHABLE);
225 229
 				}
226
-			}
227
-			else
230
+			} else
228 231
 			{
229 232
 				// Wait for some cycles and then mark unreachable instances as maybe reachable
230 233
 				if ($instanceState->getRetryCount() === self::UNREACHABLE_CYCLES_UNTIL_RETRY - 1)
@@ -235,9 +238,9 @@  discard block
 block discarded – undo
235 238
 					$this->_logger->info('Retrying instance {instanceName} during next cycle', [
236 239
 						'instanceName' => $instanceName,
237 240
 					]);
241
+				} else {
242
+									$instanceState->incrementRetryCount();
238 243
 				}
239
-				else
240
-					$instanceState->incrementRetryCount();
241 244
 			}
242 245
 		}
243 246
 
Please login to merge, or discard this patch.