@@ -92,8 +92,9 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -50,8 +50,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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) |
@@ -29,8 +29,9 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -70,8 +70,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -138,8 +138,9 @@ discard block |
||
| 138 | 138 | $configuration = parse_ini_file($configFile, true); |
| 139 | 139 | |
| 140 | 140 | // Check that the file was parsed |
| 141 | - if ($configuration === false) |
|
| 142 | - throw new InvalidConfigurationException('Failed to parse the specified configuration file'); |
|
| 141 | + if ($configuration === false) { |
|
| 142 | + throw new InvalidConfigurationException('Failed to parse the specified configuration file'); |
|
| 143 | + } |
|
| 143 | 144 | |
| 144 | 145 | $instances = []; |
| 145 | 146 | |
@@ -155,8 +156,9 @@ discard block |
||
| 155 | 156 | } |
| 156 | 157 | |
| 157 | 158 | // Validate the configuration. We need at least one instance. |
| 158 | - if (empty($instances)) |
|
| 159 | - throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance'); |
|
| 159 | + if (empty($instances)) { |
|
| 160 | + throw new InvalidConfigurationException('No instances defined, you need to specify at least one instance'); |
|
| 161 | + } |
|
| 160 | 162 | |
| 161 | 163 | // Create the configuration object |
| 162 | 164 | $config = new Configuration($databaseFile, $instances); |
@@ -189,18 +191,21 @@ discard block |
||
| 189 | 191 | $logFile = $input->getArgument('logFile'); |
| 190 | 192 | |
| 191 | 193 | // Check that the configuration file exists |
| 192 | - if (!file_exists($configFile)) |
|
| 193 | - throw new InvalidConfigurationException('The specified configuration file does not exist'); |
|
| 194 | + if (!file_exists($configFile)) { |
|
| 195 | + throw new InvalidConfigurationException('The specified configuration file does not exist'); |
|
| 196 | + } |
|
| 194 | 197 | |
| 195 | 198 | // Check that the database exists and is writable |
| 196 | - if (!file_exists($databasePath)) |
|
| 197 | - throw new InvalidConfigurationException('The specified database path does not exist'); |
|
| 198 | - else if (!is_writable($databasePath)) |
|
| 199 | - throw new InvalidConfigurationException('The specified database path is not writable'); |
|
| 199 | + if (!file_exists($databasePath)) { |
|
| 200 | + throw new InvalidConfigurationException('The specified database path does not exist'); |
|
| 201 | + } else if (!is_writable($databasePath)) { |
|
| 202 | + throw new InvalidConfigurationException('The specified database path is not writable'); |
|
| 203 | + } |
|
| 200 | 204 | |
| 201 | 205 | // Check that the directory of the log file path is writable |
| 202 | - if ($logFile !== null && !is_writable(dirname($logFile))) |
|
| 203 | - throw new InvalidConfigurationException('The specified log file path is not writable'); |
|
| 206 | + if ($logFile !== null && !is_writable(dirname($logFile))) { |
|
| 207 | + throw new InvalidConfigurationException('The specified log file path is not writable'); |
|
| 208 | + } |
|
| 204 | 209 | } |
| 205 | 210 | |
| 206 | 211 | |
@@ -219,12 +224,14 @@ discard block |
||
| 219 | 224 | $instance = new Instance($name, $address, $port); |
| 220 | 225 | |
| 221 | 226 | // Optionally set ignored users |
| 222 | - if (isset($values['ignoredUsers'])) |
|
| 223 | - $instance->setIgnoredUsers($values['ignoredUsers']); |
|
| 227 | + if (isset($values['ignoredUsers'])) { |
|
| 228 | + $instance->setIgnoredUsers($values['ignoredUsers']); |
|
| 229 | + } |
|
| 224 | 230 | |
| 225 | 231 | // Optionally set credentials |
| 226 | - if (isset($values['username']) && isset($values['password'])) |
|
| 227 | - $instance->setCredentials($values['username'], $values['password']); |
|
| 232 | + if (isset($values['username']) && isset($values['password'])) { |
|
| 233 | + $instance->setCredentials($values['username'], $values['password']); |
|
| 234 | + } |
|
| 228 | 235 | |
| 229 | 236 | return $instance; |
| 230 | 237 | } |
@@ -240,8 +247,9 @@ discard block |
||
| 240 | 247 | */ |
| 241 | 248 | private static function getSectionType($section) |
| 242 | 249 | { |
| 243 | - if (substr($section, 0, 8) === 'instance') |
|
| 244 | - return Configuration::SECTION_TYPE_INSTANCE; |
|
| 250 | + if (substr($section, 0, 8) === 'instance') { |
|
| 251 | + return Configuration::SECTION_TYPE_INSTANCE; |
|
| 252 | + } |
|
| 245 | 253 | |
| 246 | 254 | throw new InvalidConfigurationException('Unknown section "' . $section . '"'); |
| 247 | 255 | } |