| @@ -9,13 +9,13 @@ | ||
| 9 | 9 | use Rector\Set\ValueObject\LevelSetList; | 
| 10 | 10 | |
| 11 | 11 |  return static function (RectorConfig $rectorConfig): void { | 
| 12 | - $rectorConfig->paths([ | |
| 13 | - __DIR__ . '/src', | |
| 14 | - __DIR__ . '/tests', | |
| 15 | - ]); | |
| 12 | + $rectorConfig->paths([ | |
| 13 | + __DIR__ . '/src', | |
| 14 | + __DIR__ . '/tests', | |
| 15 | + ]); | |
| 16 | 16 | |
| 17 | - // register a single rule | |
| 18 | - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); | |
| 17 | + // register a single rule | |
| 18 | + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); | |
| 19 | 19 | |
| 20 | 20 | $rectorConfig->skip([RemoveUselessParamTagRector::class]); | 
| 21 | 21 | $rectorConfig->skip([MixedTypeRector::class]); | 
| @@ -8,10 +8,10 @@ | ||
| 8 | 8 | use Rector\Php80\Rector\FunctionLike\MixedTypeRector; | 
| 9 | 9 | use Rector\Set\ValueObject\LevelSetList; | 
| 10 | 10 | |
| 11 | -return static function (RectorConfig $rectorConfig): void { | |
| 11 | +return static function(RectorConfig $rectorConfig): void { | |
| 12 | 12 | $rectorConfig->paths([ | 
| 13 | - __DIR__ . '/src', | |
| 14 | - __DIR__ . '/tests', | |
| 13 | + __DIR__.'/src', | |
| 14 | + __DIR__.'/tests', | |
| 15 | 15 | ]); | 
| 16 | 16 | |
| 17 | 17 | // register a single rule | 
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | use PDO; | 
| 8 | 8 | |
| 9 | 9 |  class SqliteBuilder {
 | 
| 10 | - private MethodInvoker|null $methodInvoker = null; | |
| 10 | + private MethodInvoker | null $methodInvoker = null; | |
| 11 | 11 | |
| 12 | 12 | /** | 
| 13 | 13 | * @param string $filename | 
| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 |  	) { | 
| 52 | 52 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | 
| 53 | 53 | $this->pdo = $pdo; | 
| 54 | -		if($this->options['use-locking'] ?? true) { | |
| 54 | +		if ($this->options['use-locking'] ?? true) { | |
| 55 | 55 |  			$this->lock = $pdo->prepare('SELECT GET_LOCK(:name, 0)'); | 
| 56 | 56 |  			$this->unlock = $pdo->prepare('SELECT RELEASE_LOCK(:name)'); | 
| 57 | 57 | } | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | * @return bool | 
| 63 | 63 | */ | 
| 64 | 64 |  	public function has(string $key) { | 
| 65 | -		if($this->hasService === null) { | |
| 65 | +		if ($this->hasService === null) { | |
| 66 | 66 |  			$this->hasService = $this->pdo->prepare("SELECT COUNT(*) FROM `{$this->tableName}` WHERE service_key=:key;"); | 
| 67 | 67 | } | 
| 68 | 68 | $this->hasService->execute(['key' => $key]); | 
| @@ -75,9 +75,9 @@ discard block | ||
| 75 | 75 | * @return MySQLAttributeRepository|void | 
| 76 | 76 | */ | 
| 77 | 77 |  	public function register(string $key) { | 
| 78 | -		$this->handleException(function () use ($key) { | |
| 79 | -			if($this->services === null) { | |
| 80 | -				if($this->getServiceKeys === null) { | |
| 78 | +		$this->handleException(function() use ($key) { | |
| 79 | +			if ($this->services === null) { | |
| 80 | +				if ($this->getServiceKeys === null) { | |
| 81 | 81 |  					$this->getServiceKeys = $this->pdo->prepare("SELECT `service_key` FROM `{$this->tableName}`;"); | 
| 82 | 82 | } | 
| 83 | 83 |  				try { | 
| @@ -87,8 +87,8 @@ discard block | ||
| 87 | 87 | $this->getServiceKeys->closeCursor(); | 
| 88 | 88 | } | 
| 89 | 89 | } | 
| 90 | -			if(!in_array($key, $this->services, true)) { | |
| 91 | -				if($this->registerRow === null) { | |
| 90 | +			if (!in_array($key, $this->services, true)) { | |
| 91 | +				if ($this->registerRow === null) { | |
| 92 | 92 |  					$this->registerRow = $this->pdo->prepare("INSERT INTO `{$this->tableName}` (`service_key`) VALUES (:key)"); | 
| 93 | 93 | } | 
| 94 | 94 | $this->registerRow->execute(['key' => $key]); | 
| @@ -101,15 +101,15 @@ discard block | ||
| 101 | 101 | * @return object | 
| 102 | 102 | */ | 
| 103 | 103 |  	public function getRowByKey(string $key) { | 
| 104 | -		if($this->getData === null) { | |
| 104 | +		if ($this->getData === null) { | |
| 105 | 105 |  			$this->getData = $this->pdo->prepare("SELECT service_key, service_last_try, service_last_run, service_next_run FROM `{$this->tableName}` WHERE service_key=:key;"); | 
| 106 | 106 | } | 
| 107 | 107 |  		try { | 
| 108 | -			$this->handleException(function () use ($key) { | |
| 108 | +			$this->handleException(function() use ($key) { | |
| 109 | 109 | $this->getData->execute(['key' => $key]); | 
| 110 | 110 | }); | 
| 111 | 111 | $result = $this->getData->fetchObject(); | 
| 112 | -			if(!is_object($result)) { | |
| 112 | +			if (!is_object($result)) { | |
| 113 | 113 |  				throw new RuntimeException('Row not found'); | 
| 114 | 114 | } | 
| 115 | 115 | return $result; | 
| @@ -124,10 +124,10 @@ discard block | ||
| 124 | 124 | * @return void | 
| 125 | 125 | */ | 
| 126 | 126 |  	public function setLastTryDate(string $key, DateTimeInterface $datetime): void { | 
| 127 | -		if($this->updateTryDate === null) { | |
| 127 | +		if ($this->updateTryDate === null) { | |
| 128 | 128 |  			$this->updateTryDate = $this->pdo->prepare("INSERT INTO `{$this->tableName}` (service_key, service_last_try) VALUES (:key, :dt) ON DUPLICATE KEY UPDATE service_last_try=:dt"); | 
| 129 | 129 | } | 
| 130 | -		$this->handleException(function () use ($key, $datetime) { | |
| 130 | +		$this->handleException(function() use ($key, $datetime) { | |
| 131 | 131 |  			$this->updateTryDate->execute(['key' => $key, 'dt' => $datetime->format('Y-m-d H:i:s')]); | 
| 132 | 132 | }); | 
| 133 | 133 | } | 
| @@ -138,10 +138,10 @@ discard block | ||
| 138 | 138 | * @return void | 
| 139 | 139 | */ | 
| 140 | 140 |  	public function setLastRunDate(string $key, DateTimeInterface $datetime): void { | 
| 141 | -		if($this->updateRunDate === null) { | |
| 141 | +		if ($this->updateRunDate === null) { | |
| 142 | 142 |  			$this->updateRunDate = $this->pdo->prepare("INSERT INTO `{$this->tableName}` (service_key, service_last_run) VALUES (:key, :dt) ON DUPLICATE KEY UPDATE service_last_run=:dt"); | 
| 143 | 143 | } | 
| 144 | -		$this->handleException(function () use ($key, $datetime) { | |
| 144 | +		$this->handleException(function() use ($key, $datetime) { | |
| 145 | 145 |  			$this->updateRunDate->execute(['key' => $key, 'dt' => $datetime->format('Y-m-d H:i:s')]); | 
| 146 | 146 | }); | 
| 147 | 147 | } | 
| @@ -152,10 +152,10 @@ discard block | ||
| 152 | 152 | * @return void | 
| 153 | 153 | */ | 
| 154 | 154 |  	public function setNextRunDate(string $key, DateTimeInterface $datetime): void { | 
| 155 | -		if($this->updateNextDate === null) { | |
| 155 | +		if ($this->updateNextDate === null) { | |
| 156 | 156 |  			$this->updateNextDate = $this->pdo->prepare("INSERT INTO `{$this->tableName}` (service_key, service_next_run) VALUES (:key, :dt) ON DUPLICATE KEY UPDATE service_next_run=:dt"); | 
| 157 | 157 | } | 
| 158 | -		$this->handleException(function () use ($key, $datetime) { | |
| 158 | +		$this->handleException(function() use ($key, $datetime) { | |
| 159 | 159 |  			$this->updateNextDate->execute(['key' => $key, 'dt' => $datetime->format('Y-m-d H:i:s')]); | 
| 160 | 160 | }); | 
| 161 | 161 | } | 
| @@ -168,7 +168,7 @@ discard block | ||
| 168 | 168 |  	public function lockAndIterateServices(?DateTimeInterface $now, callable $fn): int { | 
| 169 | 169 | $data = (object) ['count' => 0]; | 
| 170 | 170 | $services = $this->fetchServices($now); | 
| 171 | -			foreach($services as $service) { | |
| 171 | +			foreach ($services as $service) { | |
| 172 | 172 |  				try { | 
| 173 | 173 | $this->lock($service->getKey()); | 
| 174 | 174 | $fn($service); | 
| @@ -185,15 +185,15 @@ discard block | ||
| 185 | 185 | * @return Service[] | 
| 186 | 186 | */ | 
| 187 | 187 |  	private function fetchServices(DateTimeInterface $now) { | 
| 188 | -		if($this->selectOverdueServices === null) { | |
| 188 | +		if ($this->selectOverdueServices === null) { | |
| 189 | 189 |  			$this->selectOverdueServices = $this->pdo->prepare("SELECT service_key, service_last_try, service_last_run, service_next_run FROM `{$this->tableName}` WHERE IFNULL(service_next_run, DATE('2000-01-01')) <= :dt ORDER BY service_last_try;"); | 
| 190 | 190 | } | 
| 191 | -		return $this->handleException(function () use ($now) { | |
| 191 | +		return $this->handleException(function() use ($now) { | |
| 192 | 192 |  			$this->selectOverdueServices->execute(['dt' => $now->format('Y-m-d H:i:d')]); | 
| 193 | 193 |  			try { | 
| 194 | 194 | $services = $this->selectOverdueServices->fetchAll(PDO::FETCH_ASSOC); | 
| 195 | 195 | $result = []; | 
| 196 | -				foreach($services as $service) { | |
| 196 | +				foreach ($services as $service) { | |
| 197 | 197 | $result[] = new Service($service['service_key']); | 
| 198 | 198 | } | 
| 199 | 199 | return $result; | 
| @@ -213,7 +213,7 @@ discard block | ||
| 213 | 213 |  			$lockName = sprintf('%s%s', $this->options['lock-prefix'] ?? '', $key); | 
| 214 | 214 | $this->lock->execute(['name' => $lockName]); | 
| 215 | 215 | $lockObtained = $this->lock->fetchColumn(0); | 
| 216 | -			if(!$lockObtained) { | |
| 216 | +			if (!$lockObtained) { | |
| 217 | 217 |  				throw new RuntimeException(sprintf('Could not obtain lock "%s"', $lockName)); | 
| 218 | 218 | } | 
| 219 | 219 |  		} finally { | 
| @@ -236,13 +236,13 @@ discard block | ||
| 236 | 236 |  		try { | 
| 237 | 237 | return $fn(); | 
| 238 | 238 |  		} catch (PDOException $e) { | 
| 239 | -			if($e->getCode() === self::MYSQL_ERR_TABLE_MSSING) { | |
| 239 | +			if ($e->getCode() === self::MYSQL_ERR_TABLE_MSSING) { | |
| 240 | 240 | // Field is missing, let's have a look what is going on... | 
| 241 | 241 |  				$this->pdo->exec("CREATE TABLE IF NOT EXISTS `{$this->tableName}` (`service_key` VARCHAR(255) NOT NULL DEFAULT '', `service_last_try` DATETIME NULL DEFAULT NULL, `service_last_run` DATETIME NULL DEFAULT NULL, `service_next_run` DATETIME NULL DEFAULT NULL, PRIMARY KEY (`service_key`));"); | 
| 242 | 242 | return $this->retry($fn); | 
| 243 | 243 | } | 
| 244 | 244 | |
| 245 | -			if($e->getCode() === self::MYSQL_ERR_TABLE_COLUMN_MSSING) { | |
| 245 | +			if ($e->getCode() === self::MYSQL_ERR_TABLE_COLUMN_MSSING) { | |
| 246 | 246 | // Field is missing, let's have a look what is going on... | 
| 247 | 247 | $this->checkIfOldTableVersion(); | 
| 248 | 248 | return $this->retry($fn); | 
| @@ -265,10 +265,10 @@ discard block | ||
| 265 | 265 |  	private function checkIfOldTableVersion() { | 
| 266 | 266 |  		$serviceNextRunField = $this->pdo->query("SHOW COLUMNS FROM `{$this->tableName}` LIKE 'service_next_run';")->fetchAll(PDO::FETCH_ASSOC); | 
| 267 | 267 | |
| 268 | -		if(!count($serviceNextRunField)) { | |
| 268 | +		if (!count($serviceNextRunField)) { | |
| 269 | 269 |  			$this->pdo->exec("ALTER TABLE `{$this->tableName}` ADD COLUMN `service_next_run` DATETIME NULL DEFAULT NULL AFTER `service_last_run`;"); | 
| 270 | 270 |  			$serviceTimeoutField = $this->pdo->query("SHOW COLUMNS FROM `{$this->tableName}` LIKE 'service_timeout';")->fetchAll(PDO::FETCH_ASSOC); | 
| 271 | -			if(count($serviceTimeoutField)) { | |
| 271 | +			if (count($serviceTimeoutField)) { | |
| 272 | 272 |  				$this->pdo->exec("UPDATE `{$this->tableName}` SET service_next_run = DATE_ADD(service_last_run, INTERVAL service_timeout SECOND)"); | 
| 273 | 273 |  				$this->pdo->exec("ALTER TABLE `{$this->tableName}` DROP COLUMN `service_timeout`;"); | 
| 274 | 274 | } | 
| @@ -74,7 +74,7 @@ discard block | ||
| 74 | 74 |  		try { | 
| 75 | 75 | $this->getData->execute(['key' => $key]); | 
| 76 | 76 | $result = $this->getData->fetchObject(); | 
| 77 | -			if(!is_object($result)) { | |
| 77 | +			if (!is_object($result)) { | |
| 78 | 78 |  				throw new RuntimeException('Row not found'); | 
| 79 | 79 | } | 
| 80 | 80 | return $result; | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 |  	public function lockAndIterateServices(DateTimeInterface $now, callable $fn): int { | 
| 92 | 92 | $count = 0; | 
| 93 | 93 | $services = $this->fetchServices($now); | 
| 94 | -		foreach($services as $service) { | |
| 94 | +		foreach ($services as $service) { | |
| 95 | 95 | $fn($service); | 
| 96 | 96 | } | 
| 97 | 97 | return $count; | 
| @@ -105,7 +105,7 @@ discard block | ||
| 105 | 105 | $this->selectServices->execute(['dt' => $now->format(self::SQLITE_DATETIME_FORMAT)]); | 
| 106 | 106 |  		try { | 
| 107 | 107 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); | 
| 108 | -			foreach($services as $service) { | |
| 108 | +			foreach ($services as $service) { | |
| 109 | 109 | yield new Service(key: $service['service_key']); | 
| 110 | 110 | } | 
| 111 | 111 |  		} finally { | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | */ | 
| 120 | 120 |  	private function migrate(int $version, string $statement): void { | 
| 121 | 121 |  		$currentVersion = (int) $this->pdo->query('PRAGMA user_version')->fetchColumn(0); | 
| 122 | -		if($currentVersion < $version) { | |
| 122 | +		if ($currentVersion < $version) { | |
| 123 | 123 | $this->pdo->exec($statement); | 
| 124 | 124 |  			$this->pdo->exec("PRAGMA user_version={$version}"); | 
| 125 | 125 | } | 
| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 | * @return $this | 
| 52 | 52 | */ | 
| 53 | 53 |  	public function on(string $event, callable $fn) { | 
| 54 | -		if(!array_key_exists($event, $this->listeners)) { | |
| 54 | +		if (!array_key_exists($event, $this->listeners)) { | |
| 55 | 55 | $this->listeners[$event] = []; | 
| 56 | 56 | } | 
| 57 | 57 | $this->listeners[$event][] = $fn; | 
| @@ -64,8 +64,8 @@ discard block | ||
| 64 | 64 | */ | 
| 65 | 65 |  	public function run(?DateTimeInterface $now = null): int { | 
| 66 | 66 | $dt = $now ?? date_create_immutable(); | 
| 67 | -		return $this->attributeRepository->lockAndIterateServices($dt, function (Service $service) { | |
| 68 | -			if(!array_key_exists($service->key, $this->services)) { | |
| 67 | +		return $this->attributeRepository->lockAndIterateServices($dt, function(Service $service) { | |
| 68 | +			if (!array_key_exists($service->key, $this->services)) { | |
| 69 | 69 | return; | 
| 70 | 70 | } | 
| 71 | 71 | $eventParams = ['serviceName' => $service->key]; | 
| @@ -73,7 +73,7 @@ discard block | ||
| 73 | 73 |  				$this->fireEvent('service-start', $eventParams); | 
| 74 | 74 | $serviceData = $this->services[$service->key]; | 
| 75 | 75 | $this->attributeRepository->setLastTryDate($service->key, date_create_immutable()); | 
| 76 | -				if($this->methodInvoker !== null) { | |
| 76 | +				if ($this->methodInvoker !== null) { | |
| 77 | 77 | $result = $this->methodInvoker->invoke($serviceData->fn, $eventParams); | 
| 78 | 78 |  				} else { | 
| 79 | 79 | $result = call_user_func($serviceData->fn, $service); | 
| @@ -81,13 +81,13 @@ discard block | ||
| 81 | 81 | $this->attributeRepository->setLastRunDate($service->key, date_create_immutable()); | 
| 82 | 82 | $nextRunDate = IntervalParser::getNext($serviceData->interval); | 
| 83 | 83 | $this->attributeRepository->setNextRunDate($serviceData->key, $nextRunDate); | 
| 84 | -				if($result !== false) { | |
| 84 | +				if ($result !== false) { | |
| 85 | 85 |  					$this->fireEvent('service-success', $eventParams); | 
| 86 | 86 | } | 
| 87 | 87 |  			} catch (Throwable $e) { | 
| 88 | 88 | $eventParams['exception'] = $e; | 
| 89 | 89 |  				$this->fireEvent('service-failure', $eventParams); | 
| 90 | -				if($this->logger !== null) { | |
| 90 | +				if ($this->logger !== null) { | |
| 91 | 91 |  					$this->logger->critical("{$service}: {$e->getMessage()}", ['exception' => $e]); | 
| 92 | 92 |  				} else { | 
| 93 | 93 |  					throw new RuntimeException("{$service}: {$e->getMessage()}", (int) $e->getCode(), $e); | 
| @@ -101,10 +101,10 @@ discard block | ||
| 101 | 101 | * @param array $params | 
| 102 | 102 | */ | 
| 103 | 103 |  	private function fireEvent(string $event, array $params) { | 
| 104 | -		if(array_key_exists($event, $this->listeners)) { | |
| 104 | +		if (array_key_exists($event, $this->listeners)) { | |
| 105 | 105 |  			try { | 
| 106 | -				foreach($this->listeners[$event] as $listener) { | |
| 107 | -					if($this->methodInvoker !== null) { | |
| 106 | +				foreach ($this->listeners[$event] as $listener) { | |
| 107 | +					if ($this->methodInvoker !== null) { | |
| 108 | 108 | $this->methodInvoker->invoke($listener, $params); | 
| 109 | 109 |  					} else { | 
| 110 | 110 | call_user_func($listener, $params['serviceName'] ?? null); |