| @@ -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 | } | 
| @@ -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 | } | 
| @@ -251,7 +251,7 @@ | ||
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | /** | 
| 254 | - * @param $instanceName | |
| 254 | + * @param string $instanceName | |
| 255 | 255 | * @param ConnectionStatus $connectionStatus | 
| 256 | 256 | * | 
| 257 | 257 | * @return bool whether the connection exists in the database | 
| @@ -94,13 +94,13 @@ discard block | ||
| 94 | 94 | $this->onUserSeen($instanceName, $connectionStatus->user); | 
| 95 | 95 | |
| 96 | 96 | $user = UserQuery::create()->filterByInstanceName($instanceName)->filterByName($connectionStatus->user) | 
| 97 | - ->findOne(); | |
| 97 | + ->findOne(); | |
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | 100 | $connection = new Connection(); | 
| 101 | 101 | $connection->setInstanceName($instanceName)->setPeer($connectionStatus->peer) | 
| 102 | - ->setUser($user) | |
| 103 | - ->setStarted($connectionStatus->started)->setType($connectionStatus->type)->save(); | |
| 102 | + ->setUser($user) | |
| 103 | + ->setStarted($connectionStatus->started)->setType($connectionStatus->type)->save(); | |
| 104 | 104 | |
| 105 | 105 |  		$this->_logger->info('Stored new connection (instance: {instanceName}, peer: {peer})', [ | 
| 106 | 106 | 'instanceName' => $instanceName, | 
| @@ -127,11 +127,11 @@ discard block | ||
| 127 | 127 | $input = new Input(); | 
| 128 | 128 | $input->setPrimaryKey($inputStatus->uuid); | 
| 129 | 129 | $input->setInstanceName($instanceName) | 
| 130 | - ->setStarted(new \DateTime()) | |
| 131 | - ->setInput($inputStatus->input) | |
| 132 | - ->setWeight($inputStatus->weight) | |
| 133 | - ->setNetwork(Input::parseNetwork($inputStatus)) | |
| 134 | - ->setMux(Input::parseMux($inputStatus))->save(); | |
| 130 | + ->setStarted(new \DateTime()) | |
| 131 | + ->setInput($inputStatus->input) | |
| 132 | + ->setWeight($inputStatus->weight) | |
| 133 | + ->setNetwork(Input::parseNetwork($inputStatus)) | |
| 134 | + ->setMux(Input::parseMux($inputStatus))->save(); | |
| 135 | 135 | |
| 136 | 136 |  		$this->_logger->info('Stored new input (instance: {instanceName}, network: {network}, mux: {mux}, weight: {weight})', | 
| 137 | 137 | [ | 
| @@ -237,8 +237,8 @@ discard block | ||
| 237 | 237 | |
| 238 | 238 | $subscription = new Subscription(); | 
| 239 | 239 | $subscription->setInstance($instance)->setInput($input)->setUser($user)->setChannel($channel) | 
| 240 | - ->setSubscriptionId($status->id)->setStarted($status->start)->setTitle($status->title) | |
| 241 | - ->setService($status->service); | |
| 240 | + ->setSubscriptionId($status->id)->setStarted($status->start)->setTitle($status->title) | |
| 241 | + ->setService($status->service); | |
| 242 | 242 | $subscription->save(); | 
| 243 | 243 | |
| 244 | 244 |  		$this->_logger->info('Stored new subscription (instance: {instanceName}, user: {userName}, channel: {channelName})', | 
| @@ -262,8 +262,8 @@ discard block | ||
| 262 | 262 | |
| 263 | 263 | // Find the latest matching subscription | 
| 264 | 264 | $subscription = SubscriptionQuery::create()->filterByInstanceName($instanceName) | 
| 265 | - ->filterBySubscriptionId($stateChange->getSubscriptionId()) | |
| 266 | -		                                 ->addDescendingOrderByColumn('started')->findOne(); | |
| 265 | + ->filterBySubscriptionId($stateChange->getSubscriptionId()) | |
| 266 | +										 ->addDescendingOrderByColumn('started')->findOne(); | |
| 267 | 267 | |
| 268 | 268 | // EPG grab subscriptions are not stored so we don't want to log these with a high level | 
| 269 | 269 | if ($subscription === null) | 
| @@ -312,7 +312,7 @@ discard block | ||
| 312 | 312 | private function hasConnection($instanceName, ConnectionStatus $connectionStatus) | 
| 313 | 313 |  	{ | 
| 314 | 314 | return ConnectionQuery::create()->filterByInstanceName($instanceName)->filterByPeer($connectionStatus->peer) | 
| 315 | - ->filterByStarted($connectionStatus->started)->findOne() !== null; | |
| 315 | + ->filterByStarted($connectionStatus->started)->findOne() !== null; | |
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 | |
| @@ -348,7 +348,7 @@ discard block | ||
| 348 | 348 | private function hasChannel($instanceName, $channelName) | 
| 349 | 349 |  	{ | 
| 350 | 350 | return ChannelQuery::create()->filterByInstanceName($instanceName)->filterByName($channelName) | 
| 351 | - ->findOne() !== null; | |
| 351 | + ->findOne() !== null; | |
| 352 | 352 | } | 
| 353 | 353 | |
| 354 | 354 | |
| @@ -371,9 +371,9 @@ discard block | ||
| 371 | 371 | $userId = $user !== null ? $user->getId() : null; | 
| 372 | 372 | |
| 373 | 373 | return SubscriptionQuery::create()->filterByInstance($instance)->filterByUserId($userId) | 
| 374 | - ->filterByChannel($channel) | |
| 375 | - ->filterBySubscriptionId($subscription->id)->filterByStarted($subscription->start) | |
| 376 | - ->findOne() !== null; | |
| 374 | + ->filterByChannel($channel) | |
| 375 | + ->filterBySubscriptionId($subscription->id)->filterByStarted($subscription->start) | |
| 376 | + ->findOne() !== null; | |
| 377 | 377 | } | 
| 378 | 378 | |
| 379 | 379 | } | 
| @@ -72,8 +72,9 @@ discard block | ||
| 72 | 72 |  	{ | 
| 73 | 73 | $instance = $event->getInstance(); | 
| 74 | 74 | |
| 75 | - if ($this->hasInstance($instance)) | |
| 76 | - return; | |
| 75 | +		if ($this->hasInstance($instance)) { | |
| 76 | + return; | |
| 77 | + } | |
| 77 | 78 | |
| 78 | 79 | $instanceModel = new Database\Instance(); | 
| 79 | 80 | $instanceModel->setPrimaryKey($instance->getHostname()); | 
| @@ -104,8 +105,9 @@ discard block | ||
| 104 | 105 | $instanceName = $event->getInstance(); | 
| 105 | 106 | $connectionStatus = $event->getConnection(); | 
| 106 | 107 | |
| 107 | - if ($this->hasConnection($instanceName, $connectionStatus)) | |
| 108 | - return; | |
| 108 | +		if ($this->hasConnection($instanceName, $connectionStatus)) { | |
| 109 | + return; | |
| 110 | + } | |
| 109 | 111 | |
| 110 | 112 | $user = null; | 
| 111 | 113 | |
| @@ -177,8 +179,9 @@ discard block | ||
| 177 | 179 | $status = $event->getSubscription(); | 
| 178 | 180 | |
| 179 | 181 | // Ignore certain subscriptions | 
| 180 | - if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) | |
| 181 | - return; | |
| 182 | +		if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) { | |
| 183 | + return; | |
| 184 | + } | |
| 182 | 185 | |
| 183 | 186 | // Determine the username to store for the subscription | 
| 184 | 187 | $username = $status->username; | 
| @@ -198,8 +201,9 @@ discard block | ||
| 198 | 201 | $this->onChannelSeen($instanceName, $status->channel); | 
| 199 | 202 | $channel = ChannelQuery::create()->filterByInstance($instance)->filterByName($status->channel)->findOne(); | 
| 200 | 203 | |
| 201 | - if ($this->hasSubscription($instance, $user, $channel, $status)) | |
| 202 | - return; | |
| 204 | +		if ($this->hasSubscription($instance, $user, $channel, $status)) { | |
| 205 | + return; | |
| 206 | + } | |
| 203 | 207 | |
| 204 | 208 | // Try to determine which input is used by the subscription | 
| 205 | 209 | $input = InputQuery::create()->filterBySubscriptionStatus($instanceName, $status)->findOne(); | 
| @@ -238,8 +242,9 @@ discard block | ||
| 238 | 242 | $stateChange = $event->getStateChange(); | 
| 239 | 243 | |
| 240 | 244 | // We only need to persist subscription stops | 
| 241 | - if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED) | |
| 242 | - return; | |
| 245 | +		if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED) { | |
| 246 | + return; | |
| 247 | + } | |
| 243 | 248 | |
| 244 | 249 | // Find the latest matching subscription | 
| 245 | 250 | $subscription = SubscriptionQuery::create()->filterByInstanceName($instanceName) | 
| @@ -280,8 +285,9 @@ discard block | ||
| 280 | 285 | */ | 
| 281 | 286 | private function onUserSeen($instanceName, $userName) | 
| 282 | 287 |  	{ | 
| 283 | - if ($this->hasUser($instanceName, $userName)) | |
| 284 | - return; | |
| 288 | +		if ($this->hasUser($instanceName, $userName)) { | |
| 289 | + return; | |
| 290 | + } | |
| 285 | 291 | |
| 286 | 292 | $user = new User(); | 
| 287 | 293 | $user->setInstanceName($instanceName)->setName($userName); | 
| @@ -302,8 +308,9 @@ discard block | ||
| 302 | 308 | */ | 
| 303 | 309 | private function onChannelSeen($instanceName, $channelName) | 
| 304 | 310 |  	{ | 
| 305 | - if ($this->hasChannel($instanceName, $channelName)) | |
| 306 | - return; | |
| 311 | +		if ($this->hasChannel($instanceName, $channelName)) { | |
| 312 | + return; | |
| 313 | + } | |
| 307 | 314 | |
| 308 | 315 | $channel = new Channel(); | 
| 309 | 316 | $channel->setInstanceName($instanceName)->setName($channelName); | 
| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | public function filterBySubscriptionStatus($instanceName, SubscriptionStatus $status) | 
| 28 | 28 |  	{ | 
| 29 | 29 | return $this->filterByInstanceName($instanceName) | 
| 30 | - ->filterByNetwork(Subscription::parseNetwork($status)) | |
| 31 | - ->filterByMux(Subscription::parseMux($status)) | |
| 32 | -		            ->addDescendingOrderByColumn('started'); | |
| 30 | + ->filterByNetwork(Subscription::parseNetwork($status)) | |
| 31 | + ->filterByMux(Subscription::parseMux($status)) | |
| 32 | +					->addDescendingOrderByColumn('started'); | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | } | 
| @@ -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 | } | 
| @@ -12,13 +12,13 @@ | ||
| 12 | 12 | final class Events | 
| 13 | 13 |  { | 
| 14 | 14 | |
| 15 | - const MAIN_LOOP_STARTING = 'mainLoop.starting'; | |
| 16 | - const INSTANCE_STATUS_UPDATES = 'status.instanceUpdates'; | |
| 15 | + const MAIN_LOOP_STARTING = 'mainLoop.starting'; | |
| 16 | + const INSTANCE_STATUS_UPDATES = 'status.instanceUpdates'; | |
| 17 | 17 | |
| 18 | - const INSTANCE_SEEN = 'persistence.instanceSeen'; | |
| 19 | - const CONNECTION_SEEN = 'persistence.connectionSeen'; | |
| 20 | - const INPUT_SEEN = 'persistence.inputSeen'; | |
| 21 | - const SUBSCRIPTION_SEEN = 'persistence.subscriptionSeen'; | |
| 22 | - const SUBSCRIPTION_STATE_CHANGE = 'persistence.subscriptionStateChange'; | |
| 18 | + const INSTANCE_SEEN = 'persistence.instanceSeen'; | |
| 19 | + const CONNECTION_SEEN = 'persistence.connectionSeen'; | |
| 20 | + const INPUT_SEEN = 'persistence.inputSeen'; | |
| 21 | + const SUBSCRIPTION_SEEN = 'persistence.subscriptionSeen'; | |
| 22 | + const SUBSCRIPTION_STATE_CHANGE = 'persistence.subscriptionStateChange'; | |
| 23 | 23 | |
| 24 | 24 | } | 
| @@ -80,8 +80,9 @@ discard block | ||
| 80 | 80 | $this->_instances = new \SplObjectStorage(); | 
| 81 | 81 | |
| 82 | 82 | // Attach a state to each instance | 
| 83 | - foreach ($this->_configuration->getInstances() as $instance) | |
| 84 | - $this->_instances->attach($instance, new InstanceState()); | |
| 83 | +		foreach ($this->_configuration->getInstances() as $instance) { | |
| 84 | + $this->_instances->attach($instance, new InstanceState()); | |
| 85 | + } | |
| 85 | 86 | |
| 86 | 87 | // Create manager instances | 
| 87 | 88 | $this->_persistenceManager = new PersistenceManager($logger); | 
| @@ -109,8 +110,9 @@ discard block | ||
| 109 | 110 | [Events::SUBSCRIPTION_STATE_CHANGE, $this->_persistenceManager, 'onSubscriptionStateChange'], | 
| 110 | 111 | ]; | 
| 111 | 112 | |
| 112 | - foreach ($eventDefinitions as $eventDefinition) | |
| 113 | - $this->_eventDispatcher->addListener($eventDefinition[0], [$eventDefinition[1], $eventDefinition[2]]); | |
| 113 | +		foreach ($eventDefinitions as $eventDefinition) { | |
| 114 | + $this->_eventDispatcher->addListener($eventDefinition[0], [$eventDefinition[1], $eventDefinition[2]]); | |
| 115 | + } | |
| 114 | 116 | } | 
| 115 | 117 | |
| 116 | 118 | |
| @@ -192,8 +194,9 @@ discard block | ||
| 192 | 194 | } | 
| 193 | 195 | |
| 194 | 196 | // Persist inputs | 
| 195 | - foreach ($instanceStatus->getInputs() as $input) | |
| 196 | - $this->_eventDispatcher->dispatch(Events::INPUT_SEEN, new InputSeenEvent($instanceName, $input)); | |
| 197 | +			foreach ($instanceStatus->getInputs() as $input) { | |
| 198 | + $this->_eventDispatcher->dispatch(Events::INPUT_SEEN, new InputSeenEvent($instanceName, $input)); | |
| 199 | + } | |
| 197 | 200 | |
| 198 | 201 | // Persist running subscriptions | 
| 199 | 202 | foreach ($instanceStatus->getSubscriptions() as $subscription) | 
| @@ -255,8 +258,7 @@ discard block | ||
| 255 | 258 | |
| 256 | 259 | $instanceState->setReachability(InstanceState::REACHABLE); | 
| 257 | 260 | } | 
| 258 | - } | |
| 259 | - catch (\Exception $e) | |
| 261 | + } catch (\Exception $e) | |
| 260 | 262 |  				{ | 
| 261 | 263 | // Mark the instance as unreachable | 
| 262 | 264 |  					$message = 'Instance {instanceName} not reachable, will wait for {cycles} cycles before retrying. | 
| @@ -270,8 +272,7 @@ discard block | ||
| 270 | 272 | |
| 271 | 273 | $instanceState->setReachability(InstanceState::UNREACHABLE); | 
| 272 | 274 | } | 
| 273 | - } | |
| 274 | - else | |
| 275 | + } else | |
| 275 | 276 |  			{ | 
| 276 | 277 | // Wait for some cycles and then mark unreachable instances as maybe reachable | 
| 277 | 278 | if ($instanceState->getRetryCount() === self::UNREACHABLE_CYCLES_UNTIL_RETRY - 1) | 
| @@ -282,9 +283,9 @@ discard block | ||
| 282 | 283 |  					$this->_logger->info('Retrying instance {instanceName} during next cycle', [ | 
| 283 | 284 | 'instanceName' => $instanceName, | 
| 284 | 285 | ]); | 
| 286 | +				} else { | |
| 287 | + $instanceState->incrementRetryCount(); | |
| 285 | 288 | } | 
| 286 | - else | |
| 287 | - $instanceState->incrementRetryCount(); | |
| 288 | 289 | } | 
| 289 | 290 | } | 
| 290 | 291 | |