Passed
Pull Request — master (#671)
by Vitor
04:30
created
lib/Provider/Channel/Telegram/Factory.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,38 +15,38 @@
 block discarded – undo
15 15
 
16 16
 class Factory extends AFactory {
17 17
 	/** @var array<string,IProvider> */
18
-	protected array $instances = [];
19
-	#[\Override]
18
+	protected array $instances = [ ];
19
+	#[\Override ]
20 20
 	protected function getPrefix(): string {
21 21
 		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\';
22 22
 	}
23 23
 
24
-	#[\Override]
24
+	#[\Override ]
25 25
 	protected function getSuffix(): string {
26 26
 		return '';
27 27
 	}
28 28
 
29
-	#[\Override]
29
+	#[\Override ]
30 30
 	protected function getBaseClass(): string {
31 31
 		return IProvider::class;
32 32
 	}
33 33
 
34
-	#[\Override]
34
+	#[\Override ]
35 35
 	public function isValid(string $fqcn): bool {
36 36
 		return defined("$fqcn::SCHEMA")
37 37
 			&& is_array($fqcn::SCHEMA);
38 38
 	}
39 39
 
40
-	#[\Override]
40
+	#[\Override ]
41 41
 	public function get(string $name): IProvider {
42
-		if (isset($this->instances[$name])) {
43
-			return $this->instances[$name];
42
+		if (isset($this->instances[ $name ])) {
43
+			return $this->instances[ $name ];
44 44
 		}
45 45
 		foreach ($this->getFqcnList() as $fqcn) {
46 46
 			if ($fqcn::getProviderId() === $name) {
47 47
 				$instance = \OCP\Server::get($fqcn);
48 48
 				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
49
-				$this->instances[$name] = $instance;
49
+				$this->instances[ $name ] = $instance;
50 50
 				return $instance;
51 51
 			}
52 52
 		}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/Drivers/Bot.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			<p>Enter this ID to receive your verification code below.</p>
38 38
 			HTML,
39 39
 		'fields' => [
40
-			['field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:'],
40
+			[ 'field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:' ],
41 41
 		],
42 42
 	];
43 43
 	public function __construct(
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 	) {
47 47
 	}
48 48
 
49
-	#[\Override]
50
-	public function send(string $identifier, string $message, array $extra = []): void {
49
+	#[\Override ]
50
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
51 51
 		if (empty($message)) {
52
-			$message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]);
52
+			$message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]);
53 53
 		}
54 54
 		$this->logger->debug("sending telegram message to $identifier, message: $message");
55 55
 		$botToken = $this->getBotToken();
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 		$this->logger->debug("telegram message to chat $identifier sent");
69 69
 	}
70 70
 
71
-	#[\Override]
71
+	#[\Override ]
72 72
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
73 73
 		$helper = new QuestionHelper();
74
-		$tokenQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' ');
74
+		$tokenQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' ');
75 75
 		$token = $helper->ask($input, $output, $tokenQuestion);
76 76
 		$this->setBotToken($token);
77 77
 		$output->writeln("Using $token.");
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/IProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 use Symfony\Component\Console\Output\OutputInterface;
16 16
 
17 17
 interface IProvider {
18
-	public const SCHEMA = [];
18
+	public const SCHEMA = [ ];
19 19
 
20 20
 	/**
21 21
 	 * @param string $identifier
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/AProvider.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,32 +22,32 @@
 block discarded – undo
22 22
 	/**
23 23
 	 * @throws MessageTransmissionException
24 24
 	 */
25
-	#[\Override]
25
+	#[\Override ]
26 26
 	abstract public function send(string $identifier, string $message);
27 27
 
28
-	#[\Override]
28
+	#[\Override ]
29 29
 	public function setAppConfig(IAppConfig $appConfig): void {
30 30
 		$this->appConfig = $appConfig;
31 31
 	}
32 32
 
33
-	#[\Override]
33
+	#[\Override ]
34 34
 	public static function idOverride(): ?string {
35 35
 		return null;
36 36
 	}
37 37
 
38
-	#[\Override]
38
+	#[\Override ]
39 39
 	public static function getProviderId(): string {
40
-		if (static::SCHEMA['id'] ?? null) {
41
-			return static::SCHEMA['id'];
40
+		if (static::SCHEMA[ 'id' ] ?? null) {
41
+			return static::SCHEMA[ 'id' ];
42 42
 		}
43 43
 		$id = self::getIdFromProviderFqcn(static::class);
44 44
 		if ($id === null) {
45
-			throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class);
45
+			throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class);
46 46
 		}
47 47
 		return $id;
48 48
 	}
49 49
 
50
-	#[\Override]
50
+	#[\Override ]
51 51
 	abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int;
52 52
 
53 53
 	private static function getIdFromProviderFqcn(string $fqcn): ?string {
Please login to merge, or discard this patch.
lib/Provider/AFactory.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
 
15 15
 abstract class AFactory {
16 16
 	/** @var array<string,AGateway|AProvider|ISMSProvider|ITelegramProvider> */
17
-	protected array $instances = [];
17
+	protected array $instances = [ ];
18 18
 	/** @var array<string> */
19
-	protected array $fqcn = [];
19
+	protected array $fqcn = [ ];
20 20
 
21 21
 	abstract protected function getPrefix(): string;
22 22
 	abstract protected function getSuffix(): string;
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	/** @return AGateway|AProvider|ISMSProvider|ITelegramProvider */
30 30
 	public function get(string $name): object {
31 31
 		$needle = strtolower($name);
32
-		if (isset($this->instances[$needle])) {
33
-			return $this->instances[$needle];
32
+		if (isset($this->instances[ $needle ])) {
33
+			return $this->instances[ $needle ];
34 34
 		}
35 35
 
36 36
 		foreach ($this->getFqcnList() as $fqcn) {
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 				continue;
40 40
 			}
41 41
 			$instance = \OCP\Server::get($fqcn);
42
-			$this->instances[$needle] = $instance;
42
+			$this->instances[ $needle ] = $instance;
43 43
 			return $instance;
44 44
 		}
45 45
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 			return $this->fqcn;
53 53
 		}
54 54
 
55
-		$loader = require __DIR__ . '/../../vendor/autoload.php';
55
+		$loader = require __DIR__.'/../../vendor/autoload.php';
56 56
 		foreach ($loader->getClassMap() as $fqcn => $_) {
57 57
 			$type = $this->typeFrom($fqcn);
58 58
 			if ($type === null) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			if (!$this->isValid($fqcn)) {
65 65
 				continue;
66 66
 			}
67
-			$this->fqcn[] = $fqcn;
67
+			$this->fqcn[ ] = $fqcn;
68 68
 		}
69 69
 		return $this->fqcn;
70 70
 	}
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 			return null;
80 80
 		}
81 81
 		$type = substr($fqcn, strlen($prefix));
82
-		$type = substr($type, 0, -strlen('\\' . $suffix));
82
+		$type = substr($type, 0, -strlen('\\'.$suffix));
83 83
 		if (strpos($type, '\\') !== false || $type === '') {
84 84
 			return null;
85 85
 		}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/Drivers/Client.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 			<p>Enter your Telegram number or username to receive your verification code below.</p>
39 39
 			HTML,
40 40
 		'fields' => [
41
-			['field' => 'api_id', 'prompt' => 'Please enter your Telegram api_id:'],
42
-			['field' => 'api_hash', 'prompt' => 'Please enter your Telegram api_hash:'],
41
+			[ 'field' => 'api_id', 'prompt' => 'Please enter your Telegram api_id:' ],
42
+			[ 'field' => 'api_hash', 'prompt' => 'Please enter your Telegram api_hash:' ],
43 43
 		],
44 44
 	];
45 45
 	public function __construct(
@@ -50,28 +50,28 @@  discard block
 block discarded – undo
50 50
 	) {
51 51
 	}
52 52
 
53
-	#[\Override]
54
-	public function send(string $identifier, string $message, array $extra = []): void {
53
+	#[\Override ]
54
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
55 55
 		$this->logger->debug("sending telegram message to $identifier, message: $message");
56 56
 
57 57
 		$sessionFile = $this->getSessionDirectory();
58 58
 
59
-		putenv('TELEGRAM_API_ID=' . $this->getApiId());
60
-		putenv('TELEGRAM_API_HASH=' . $this->getApiHash());
59
+		putenv('TELEGRAM_API_ID='.$this->getApiId());
60
+		putenv('TELEGRAM_API_HASH='.$this->getApiHash());
61 61
 
62
-		$path = realpath(__DIR__ . '/ClientCli/Cli.php');
63
-		$cmd = 'php ' . escapeshellarg($path) . ' '
62
+		$path = realpath(__DIR__.'/ClientCli/Cli.php');
63
+		$cmd = 'php '.escapeshellarg($path).' '
64 64
 			. 'telegram:send-message '
65
-			. '--session-directory ' . escapeshellarg($sessionFile)
66
-			. ' --to ' . escapeshellarg($identifier)
67
-			. ' --message ' . escapeshellarg($message);
65
+			. '--session-directory '.escapeshellarg($sessionFile)
66
+			. ' --to '.escapeshellarg($identifier)
67
+			. ' --message '.escapeshellarg($message);
68 68
 
69 69
 		$output = shell_exec($cmd);
70 70
 
71 71
 		$this->logger->debug("telegram message to chat $identifier sent");
72 72
 	}
73 73
 
74
-	#[\Override]
74
+	#[\Override ]
75 75
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
76 76
 		if (PHP_VERSION_ID < 80200) {
77 77
 			$output->writeln('The Telegram Client API provider requires PHP 8.2 or higher.');
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
 		$this->setApiId($apiId);
88 88
 		$this->setApiHash($apiHash);
89 89
 
90
-		putenv('TELEGRAM_API_ID=' . $apiId);
91
-		putenv('TELEGRAM_API_HASH=' . $apiHash);
90
+		putenv('TELEGRAM_API_ID='.$apiId);
91
+		putenv('TELEGRAM_API_HASH='.$apiHash);
92 92
 
93 93
 		$sessionFile = $this->getSessionDirectory();
94 94
 
95 95
 		$sessionFile = $this->getSessionDirectory();
96 96
 
97
-		$path = realpath(__DIR__ . '/ClientCli/Cli.php');
98
-		$cmd = 'php ' . escapeshellarg($path) . ' telegram:login --session-directory ' . escapeshellarg($sessionFile);
97
+		$path = realpath(__DIR__.'/ClientCli/Cli.php');
98
+		$cmd = 'php '.escapeshellarg($path).' telegram:login --session-directory '.escapeshellarg($sessionFile);
99 99
 
100 100
 		$response = shell_exec($cmd);
101 101
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		$output->writeln('');
106 106
 		$output->writeln("<comment>$cmd</comment>");
107 107
 		$output->writeln('');
108
-		$output->writeln('Make sure that the user to run the command is the same as the web server user: <info>' . $user['name'] . '</info>.');
108
+		$output->writeln('Make sure that the user to run the command is the same as the web server user: <info>'.$user[ 'name' ].'</info>.');
109 109
 		$output->writeln('');
110 110
 		$output->writeln('Follow the instructions in the command output.');
111 111
 		return 0;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 		}
121 121
 
122 122
 		$instanceId = $this->config->getSystemValueString('instanceid');
123
-		$appDataFolder = 'appdata_' . $instanceId;
124
-		$dataDirectory = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
125
-		$fullPath = $dataDirectory . '/' . $appDataFolder . '/' . Application::APP_ID . '/session.madeline';
123
+		$appDataFolder = 'appdata_'.$instanceId;
124
+		$dataDirectory = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data');
125
+		$fullPath = $dataDirectory.'/'.$appDataFolder.'/'.Application::APP_ID.'/session.madeline';
126 126
 
127 127
 		if (is_dir($fullPath) === false) {
128 128
 			$reflection = new \ReflectionClass($folder);
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/Drivers/ClientCli/Login.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use Symfony\Component\Console\Input\InputOption;
19 19
 use Symfony\Component\Console\Output\OutputInterface;
20 20
 
21
-#[AsCommand(name: 'telegram:login', description: 'Login into Telegram using the Client API')]
21
+#[AsCommand(name: 'telegram:login', description: 'Login into Telegram using the Client API') ]
22 22
 class Login extends Command {
23 23
 
24 24
 	protected function configure(): void {
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		try {
47 47
 			$settings = (new Settings())
48 48
 				->setAppInfo($appInfo)
49
-				->setLogger((new Logger())->setExtra($sessionDirectory . '/MadelineProto.log'));
49
+				->setLogger((new Logger())->setExtra($sessionDirectory.'/MadelineProto.log'));
50 50
 
51 51
 			$api = new API($sessionDirectory, $settings);
52 52
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
 			return Command::SUCCESS;
64 64
 		} catch (\Throwable $e) {
65
-			$output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
65
+			$output->writeln('<error>Error: '.$e->getMessage().'</error>');
66 66
 			return Command::FAILURE;
67 67
 		}
68 68
 	}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Provider/Drivers/ClientCli/SendMessage.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use Symfony\Component\Console\Input\InputOption;
19 19
 use Symfony\Component\Console\Output\OutputInterface;
20 20
 
21
-#[AsCommand(name: 'telegram:send-message', description: 'Send a message via Telegram Client API')]
21
+#[AsCommand(name: 'telegram:send-message', description: 'Send a message via Telegram Client API') ]
22 22
 class SendMessage extends Command {
23 23
 
24 24
 	protected function configure(): void {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 		try {
50 50
 			$settings = (new Settings())
51
-				->setLogger((new Logger())->setExtra($sessionDirectory . '/MadelineProto.log'));
51
+				->setLogger((new Logger())->setExtra($sessionDirectory.'/MadelineProto.log'));
52 52
 
53 53
 			$message = $input->getOption('message');
54 54
 			$peer = $input->getOption('to');
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			if (!str_starts_with($peer, '@')) {
61 61
 				try {
62 62
 					$result = $api->contacts->resolvePhone(phone: $peer);
63
-					$peer = $result['peer'];
63
+					$peer = $result[ 'peer' ];
64 64
 				} catch (RPCErrorException $e) {
65 65
 					if ($e->getMessage() === 'PHONE_NOT_OCCUPIED') {
66 66
 						$output->writeln('<error>Error: The phone number is not associated with any Telegram account.</error>');
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 			return Command::SUCCESS;
83 83
 		} catch (\Throwable $e) {
84
-			$output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
84
+			$output->writeln('<error>Error: '.$e->getMessage().'</error>');
85 85
 			return Command::FAILURE;
86 86
 		}
87 87
 	}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Gateway.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
 		parent::__construct($appConfig);
32 32
 	}
33 33
 
34
-	#[\Override]
35
-	public function send(string $identifier, string $message, array $extra = []): void {
34
+	#[\Override ]
35
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
36 36
 		$this->getProvider()->send($identifier, $message);
37 37
 	}
38 38
 
39
-	#[\Override]
39
+	#[\Override ]
40 40
 	final public function cliConfigure(InputInterface $input, OutputInterface $output): int {
41 41
 		$namespaces = $this->providerFactory->getFqcnList();
42
-		$schemas = [];
42
+		$schemas = [ ];
43 43
 		foreach ($namespaces as $ns) {
44
-			$schemas[] = $ns::SCHEMA;
44
+			$schemas[ ] = $ns::SCHEMA;
45 45
 		}
46 46
 		$names = array_column($schemas, 'name');
47 47
 
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
 		$choiceQuestion = new ChoiceQuestion('Please choose a Telegram provider:', $names);
50 50
 		$name = $helper->ask($input, $output, $choiceQuestion);
51 51
 		$selectedIndex = array_search($name, $names);
52
-		$schema = $schemas[$selectedIndex];
52
+		$schema = $schemas[ $selectedIndex ];
53 53
 
54
-		$provider = $this->getProvider($namespaces[$selectedIndex]::getProviderId());
54
+		$provider = $this->getProvider($namespaces[ $selectedIndex ]::getProviderId());
55 55
 
56 56
 		$provider->cliConfigure($input, $output, $provider, $schema);
57 57
 		return 0;
58 58
 	}
59 59
 
60
-	#[\Override]
60
+	#[\Override ]
61 61
 	public function getSettings(): array {
62 62
 		try {
63 63
 			$provider = $this->getProvider();
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 		return $provider::SCHEMA;
68 68
 	}
69 69
 
70
-	#[\Override]
71
-	public function isComplete(array $schema = []): bool {
70
+	#[\Override ]
71
+	public function isComplete(array $schema = [ ]): bool {
72 72
 		if (empty($schema)) {
73 73
 			try {
74 74
 				$provider = $this->getProvider();
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 		return parent::isComplete($schema);
81 81
 	}
82 82
 
83
-	#[\Override]
84
-	public function remove(array $schema = []): void {
83
+	#[\Override ]
84
+	public function remove(array $schema = [ ]): void {
85 85
 		if (empty($schema)) {
86 86
 			$schema = static::SCHEMA;
87 87
 		}
Please login to merge, or discard this patch.