@@ -33,6 +33,6 @@ |
||
| 33 | 33 | $length = strlen($number); |
| 34 | 34 | $start = $length - 3; |
| 35 | 35 | |
| 36 | - return str_repeat('*', $start) . substr($number, $start); |
|
| 36 | + return str_repeat('*', $start).substr($number, $start); |
|
| 37 | 37 | } |
| 38 | 38 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | class Application extends App implements IBootstrap { |
| 20 | 20 | public const APP_ID = 'twofactor_gateway'; |
| 21 | 21 | |
| 22 | - public function __construct(array $urlParams = []) { |
|
| 22 | + public function __construct(array $urlParams = [ ]) { |
|
| 23 | 23 | parent::__construct(self::APP_ID, $urlParams); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - #[\Override] |
|
| 26 | + #[\Override ] |
|
| 27 | 27 | public function register(IRegistrationContext $context): void { |
| 28 | 28 | $providerFactory = Server::get(Factory::class); |
| 29 | 29 | $fqcn = $providerFactory->getFqcnList(); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - #[\Override] |
|
| 35 | + #[\Override ] |
|
| 36 | 36 | public function boot(IBootContext $context): void { |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -10,17 +10,17 @@ |
||
| 10 | 10 | namespace OCA\TwoFactorGateway\Provider; |
| 11 | 11 | |
| 12 | 12 | class Factory extends AFactory { |
| 13 | - #[\Override] |
|
| 13 | + #[\Override ] |
|
| 14 | 14 | protected function getPrefix(): string { |
| 15 | 15 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - #[\Override] |
|
| 18 | + #[\Override ] |
|
| 19 | 19 | protected function getSuffix(): string { |
| 20 | 20 | return 'Provider'; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - #[\Override] |
|
| 23 | + #[\Override ] |
|
| 24 | 24 | protected function getBaseClass(): string { |
| 25 | 25 | return AProvider::class; |
| 26 | 26 | } |
@@ -10,9 +10,9 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | abstract class AFactory { |
| 12 | 12 | /** @var array<string,object> */ |
| 13 | - protected array $instances = []; |
|
| 13 | + protected array $instances = [ ]; |
|
| 14 | 14 | /** @var array<string> */ |
| 15 | - protected array $fqcn = []; |
|
| 15 | + protected array $fqcn = [ ]; |
|
| 16 | 16 | |
| 17 | 17 | abstract protected function getPrefix(): string; |
| 18 | 18 | abstract protected function getSuffix(): string; |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function get(string $name): object { |
| 26 | 26 | $needle = strtolower($name); |
| 27 | - if (isset($this->instances[$needle])) { |
|
| 28 | - return $this->instances[$needle]; |
|
| 27 | + if (isset($this->instances[ $needle ])) { |
|
| 28 | + return $this->instances[ $needle ]; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | foreach ($this->getFqcnList() as $fqcn) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | continue; |
| 35 | 35 | } |
| 36 | 36 | $instance = \OCP\Server::get($fqcn); |
| 37 | - $this->instances[$needle] = $instance; |
|
| 37 | + $this->instances[ $needle ] = $instance; |
|
| 38 | 38 | return $instance; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | return $this->fqcn; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $loader = require __DIR__ . '/../../vendor/autoload.php'; |
|
| 50 | + $loader = require __DIR__.'/../../vendor/autoload.php'; |
|
| 51 | 51 | foreach ($loader->getClassMap() as $fqcn => $_) { |
| 52 | 52 | $type = $this->typeFrom($fqcn); |
| 53 | 53 | if ($type === null) { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | if (!$this->isValid($fqcn)) { |
| 60 | 60 | continue; |
| 61 | 61 | } |
| 62 | - $this->fqcn[] = $fqcn; |
|
| 62 | + $this->fqcn[ ] = $fqcn; |
|
| 63 | 63 | } |
| 64 | 64 | return $this->fqcn; |
| 65 | 65 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | return null; |
| 75 | 75 | } |
| 76 | 76 | $type = substr($fqcn, strlen($prefix)); |
| 77 | - $type = substr($type, 0, -strlen('\\' . $suffix)); |
|
| 77 | + $type = substr($type, 0, -strlen('\\'.$suffix)); |
|
| 78 | 78 | if (strpos($type, '\\') !== false || $type === '') { |
| 79 | 79 | return null; |
| 80 | 80 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | protected IGateway $gateway; |
| 38 | 38 | |
| 39 | 39 | private function getSessionKey(): string { |
| 40 | - return 'twofactor_gateway_' . $this->getGatewayName() . '_secret'; |
|
| 40 | + return 'twofactor_gateway_'.$this->getGatewayName().'_secret'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function __construct( |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | $fqcn = static::class; |
| 60 | 60 | $parts = explode('\\', $fqcn); |
| 61 | - [$name] = array_slice($parts, -2, 1); |
|
| 61 | + [ $name ] = array_slice($parts, -2, 1); |
|
| 62 | 62 | $this->gatewayName = strtolower($name); |
| 63 | 63 | return $this->gatewayName; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - #[\Override] |
|
| 66 | + #[\Override ] |
|
| 67 | 67 | public function getId(): string { |
| 68 | - return 'gateway_' . $this->getGatewayName(); |
|
| 68 | + return 'gateway_'.$this->getGatewayName(); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | private function getSecret(): string { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | return $secret; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - #[\Override] |
|
| 82 | + #[\Override ] |
|
| 83 | 83 | public function getTemplate(IUser $user): ITemplate { |
| 84 | 84 | $secret = $this->getSecret(); |
| 85 | 85 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $this->l10n->t('%s is your Nextcloud authentication code', [ |
| 92 | 92 | $secret |
| 93 | 93 | ]), |
| 94 | - ['code' => $secret], |
|
| 94 | + [ 'code' => $secret ], |
|
| 95 | 95 | ); |
| 96 | 96 | } catch (MessageTransmissionException) { |
| 97 | 97 | return $this->templateManager->getTemplate('twofactor_gateway', 'error'); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | return $tmpl; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - #[\Override] |
|
| 105 | + #[\Override ] |
|
| 106 | 106 | public function verifyChallenge(IUser $user, string $challenge): bool { |
| 107 | 107 | $valid = $this->session->exists($this->getSessionKey()) |
| 108 | 108 | && $this->session->get($this->getSessionKey()) === $challenge; |
@@ -114,31 +114,31 @@ discard block |
||
| 114 | 114 | return $valid; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - #[\Override] |
|
| 117 | + #[\Override ] |
|
| 118 | 118 | public function isTwoFactorAuthEnabledForUser(IUser $user): bool { |
| 119 | 119 | return $this->stateStorage->get($user, $this->getGatewayName())->getState() === StateStorage::STATE_ENABLED; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - #[\Override] |
|
| 122 | + #[\Override ] |
|
| 123 | 123 | public function getPersonalSettings(IUser $user): IPersonalProviderSettings { |
| 124 | - $this->initialState->provideInitialState('settings-' . $this->gateway->getProviderId(), $this->gateway->getSettings()); |
|
| 124 | + $this->initialState->provideInitialState('settings-'.$this->gateway->getProviderId(), $this->gateway->getSettings()); |
|
| 125 | 125 | return new PersonalSettings( |
| 126 | 126 | $this->getGatewayName(), |
| 127 | 127 | $this->gateway->isComplete(), |
| 128 | 128 | ); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - #[\Override] |
|
| 131 | + #[\Override ] |
|
| 132 | 132 | public function getLightIcon(): String { |
| 133 | 133 | return Server::get(IURLGenerator::class)->imagePath(Application::APP_ID, 'app.svg'); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - #[\Override] |
|
| 136 | + #[\Override ] |
|
| 137 | 137 | public function getDarkIcon(): String { |
| 138 | 138 | return Server::get(IURLGenerator::class)->imagePath(Application::APP_ID, 'app-dark.svg'); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - #[\Override] |
|
| 141 | + #[\Override ] |
|
| 142 | 142 | public function disableFor(IUser $user) { |
| 143 | 143 | $state = $this->stateStorage->get($user, $this->getGatewayName()); |
| 144 | 144 | if ($state->getState() === StateStorage::STATE_ENABLED) { |
@@ -12,17 +12,17 @@ |
||
| 12 | 12 | use OCA\TwoFactorGateway\Provider\AFactory; |
| 13 | 13 | |
| 14 | 14 | class Factory extends AFactory { |
| 15 | - #[\Override] |
|
| 15 | + #[\Override ] |
|
| 16 | 16 | protected function getPrefix(): string { |
| 17 | 17 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - #[\Override] |
|
| 20 | + #[\Override ] |
|
| 21 | 21 | protected function getSuffix(): string { |
| 22 | 22 | return 'Gateway'; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - #[\Override] |
|
| 25 | + #[\Override ] |
|
| 26 | 26 | protected function getBaseClass(): string { |
| 27 | 27 | return AGateway::class; |
| 28 | 28 | } |
@@ -20,28 +20,28 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function __call(string $name, array $args) { |
| 22 | 22 | if (!preg_match('/^(?<operation>get|set|delete)(?<field>[A-Z][A-Za-z0-9_]*)$/', $name, $matches)) { |
| 23 | - throw new ConfigurationException('Invalid method ' . $name); |
|
| 23 | + throw new ConfigurationException('Invalid method '.$name); |
|
| 24 | 24 | } |
| 25 | - $field = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $matches['field'])); |
|
| 25 | + $field = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $matches[ 'field' ])); |
|
| 26 | 26 | $key = $this->keyFromField($field); |
| 27 | 27 | |
| 28 | - switch ($matches['operation']) { |
|
| 28 | + switch ($matches[ 'operation' ]) { |
|
| 29 | 29 | case 'get': |
| 30 | 30 | $val = (string)$this->getAppConfig()->getValueString(Application::APP_ID, $key, ''); |
| 31 | 31 | if ($val === '') { |
| 32 | - throw new ConfigurationException('No value set for ' . $field); |
|
| 32 | + throw new ConfigurationException('No value set for '.$field); |
|
| 33 | 33 | } |
| 34 | 34 | return $val; |
| 35 | 35 | |
| 36 | 36 | case 'set': |
| 37 | - $this->getAppConfig()->setValueString(Application::APP_ID, $key, (string)($args[0] ?? '')); |
|
| 37 | + $this->getAppConfig()->setValueString(Application::APP_ID, $key, (string)($args[ 0 ] ?? '')); |
|
| 38 | 38 | return $this; |
| 39 | 39 | |
| 40 | 40 | case 'delete': |
| 41 | 41 | $this->getAppConfig()->deleteKey(Application::APP_ID, $key); |
| 42 | 42 | return $this; |
| 43 | 43 | } |
| 44 | - throw new ConfigurationException('Invalid operation ' . $matches['operation']); |
|
| 44 | + throw new ConfigurationException('Invalid operation '.$matches[ 'operation' ]); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | private function keyFromField(string $field): string { |
| 51 | 51 | $fields = array_column($this->getSchemaFields(), 'field'); |
| 52 | 52 | if (!in_array($field, $fields, true)) { |
| 53 | - throw new ConfigurationException('Invalid configuration field: ' . $field . ', check SCHEMA at ' . static::class); |
|
| 53 | + throw new ConfigurationException('Invalid configuration field: '.$field.', check SCHEMA at '.static::class); |
|
| 54 | 54 | } |
| 55 | - return $this->getProviderId() . '_' . $field; |
|
| 55 | + return $this->getProviderId().'_'.$field; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @throws ConfigurationException |
| 71 | 71 | */ |
| 72 | 72 | protected function getSchemaFields(): array { |
| 73 | - return static::getSchema()['fields']; |
|
| 73 | + return static::getSchema()[ 'fields' ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @throws ConfigurationException |
| 79 | 79 | */ |
| 80 | 80 | public static function getSchema(): array { |
| 81 | - if (!defined(static::class . '::SCHEMA')) { |
|
| 81 | + if (!defined(static::class.'::SCHEMA')) { |
|
| 82 | 82 | throw new ConfigurationException('No SCHEMA defined'); |
| 83 | 83 | } |
| 84 | 84 | return static::SCHEMA; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | abstract class AGateway implements IGateway { |
| 20 | 20 | use TConfigurable; |
| 21 | - public const SCHEMA = []; |
|
| 21 | + public const SCHEMA = [ ]; |
|
| 22 | 22 | |
| 23 | 23 | public function __construct( |
| 24 | 24 | public IAppConfig $appConfig, |
@@ -28,41 +28,41 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @throws MessageTransmissionException |
| 30 | 30 | */ |
| 31 | - #[\Override] |
|
| 32 | - abstract public function send(IUser $user, string $identifier, string $message, array $extra = []): void; |
|
| 31 | + #[\Override ] |
|
| 32 | + abstract public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void; |
|
| 33 | 33 | |
| 34 | - #[\Override] |
|
| 35 | - public function isComplete(array $schema = []): bool { |
|
| 34 | + #[\Override ] |
|
| 35 | + public function isComplete(array $schema = [ ]): bool { |
|
| 36 | 36 | if (empty($schema)) { |
| 37 | 37 | $schema = static::SCHEMA; |
| 38 | 38 | } |
| 39 | 39 | $set = $this->appConfig->getKeys(Application::APP_ID); |
| 40 | - $fields = array_column($schema['fields'], 'field'); |
|
| 41 | - $fields = array_map(fn ($f) => $this->getProviderId() . '_' . $f, $fields); |
|
| 40 | + $fields = array_column($schema[ 'fields' ], 'field'); |
|
| 41 | + $fields = array_map(fn ($f) => $this->getProviderId().'_'.$f, $fields); |
|
| 42 | 42 | $intersect = array_intersect($fields, $set); |
| 43 | 43 | return count($intersect) === count($fields); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - #[\Override] |
|
| 46 | + #[\Override ] |
|
| 47 | 47 | public function getSettings(): array { |
| 48 | - $settings = []; |
|
| 49 | - if (isset(static::SCHEMA['instructions'])) { |
|
| 50 | - $settings['instructions'] = static::SCHEMA['instructions']; |
|
| 48 | + $settings = [ ]; |
|
| 49 | + if (isset(static::SCHEMA[ 'instructions' ])) { |
|
| 50 | + $settings[ 'instructions' ] = static::SCHEMA[ 'instructions' ]; |
|
| 51 | 51 | } |
| 52 | - $settings['name'] = static::SCHEMA['name']; |
|
| 52 | + $settings[ 'name' ] = static::SCHEMA[ 'name' ]; |
|
| 53 | 53 | return $settings; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - #[\Override] |
|
| 56 | + #[\Override ] |
|
| 57 | 57 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
| 58 | 58 | |
| 59 | - #[\Override] |
|
| 60 | - public function remove(array $schema = []): void { |
|
| 59 | + #[\Override ] |
|
| 60 | + public function remove(array $schema = [ ]): void { |
|
| 61 | 61 | if (empty($schema)) { |
| 62 | 62 | $schema = static::SCHEMA; |
| 63 | 63 | } |
| 64 | - foreach ($schema['fields'] as $field) { |
|
| 65 | - $method = 'delete' . $this->toCamel($field['field']); |
|
| 64 | + foreach ($schema[ 'fields' ] as $field) { |
|
| 65 | + $method = 'delete'.$this->toCamel($field[ 'field' ]); |
|
| 66 | 66 | $this->{$method}(); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $field))); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - #[\Override] |
|
| 74 | + #[\Override ] |
|
| 75 | 75 | public static function getProviderId(): string { |
| 76 | 76 | $id = self::deriveIdFromFqcn(static::class); |
| 77 | 77 | if ($id === null) { |
| 78 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
| 78 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
| 79 | 79 | } |
| 80 | 80 | return $id; |
| 81 | 81 | } |
@@ -23,15 +23,15 @@ |
||
| 23 | 23 | * |
| 24 | 24 | * @throws MessageTransmissionException |
| 25 | 25 | */ |
| 26 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void; |
|
| 26 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void; |
|
| 27 | 27 | |
| 28 | - public function isComplete(array $schema = []): bool; |
|
| 28 | + public function isComplete(array $schema = [ ]): bool; |
|
| 29 | 29 | |
| 30 | 30 | public function getSettings(): array; |
| 31 | 31 | |
| 32 | 32 | public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
| 33 | 33 | |
| 34 | - public function remove(array $schema = []): void; |
|
| 34 | + public function remove(array $schema = [ ]): void; |
|
| 35 | 35 | |
| 36 | 36 | public static function getProviderId(): string; |
| 37 | 37 | } |