@@ -30,50 +30,50 @@ |
||
30 | 30 | namespace OCA\User_LDAP; |
31 | 31 | |
32 | 32 | class WizardResult { |
33 | - protected $changes = []; |
|
34 | - protected $options = []; |
|
35 | - protected $markedChange = false; |
|
33 | + protected $changes = []; |
|
34 | + protected $options = []; |
|
35 | + protected $markedChange = false; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $key |
|
39 | - * @param mixed $value |
|
40 | - */ |
|
41 | - public function addChange($key, $value) { |
|
42 | - $this->changes[$key] = $value; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param string $key |
|
39 | + * @param mixed $value |
|
40 | + */ |
|
41 | + public function addChange($key, $value) { |
|
42 | + $this->changes[$key] = $value; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - public function markChange() { |
|
47 | - $this->markedChange = true; |
|
48 | - } |
|
46 | + public function markChange() { |
|
47 | + $this->markedChange = true; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $key |
|
52 | - * @param array|string $values |
|
53 | - */ |
|
54 | - public function addOptions($key, $values) { |
|
55 | - if (!is_array($values)) { |
|
56 | - $values = [$values]; |
|
57 | - } |
|
58 | - $this->options[$key] = $values; |
|
59 | - } |
|
50 | + /** |
|
51 | + * @param string $key |
|
52 | + * @param array|string $values |
|
53 | + */ |
|
54 | + public function addOptions($key, $values) { |
|
55 | + if (!is_array($values)) { |
|
56 | + $values = [$values]; |
|
57 | + } |
|
58 | + $this->options[$key] = $values; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function hasChanges() { |
|
65 | - return (count($this->changes) > 0 || $this->markedChange); |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function hasChanges() { |
|
65 | + return (count($this->changes) > 0 || $this->markedChange); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getResultArray() { |
|
72 | - $result = []; |
|
73 | - $result['changes'] = $this->changes; |
|
74 | - if (count($this->options) > 0) { |
|
75 | - $result['options'] = $this->options; |
|
76 | - } |
|
77 | - return $result; |
|
78 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getResultArray() { |
|
72 | + $result = []; |
|
73 | + $result['changes'] = $this->changes; |
|
74 | + if (count($this->options) > 0) { |
|
75 | + $result['options'] = $this->options; |
|
76 | + } |
|
77 | + return $result; |
|
78 | + } |
|
79 | 79 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | \OC_JSON::checkAppEnabled('user_ldap'); |
31 | 31 | \OC_JSON::callCheck(); |
32 | 32 | |
33 | -$prefix = (string)$_POST['ldap_serverconfig_chooser']; |
|
33 | +$prefix = (string) $_POST['ldap_serverconfig_chooser']; |
|
34 | 34 | |
35 | 35 | // Checkboxes are not submitted, when they are unchecked. Set them manually. |
36 | 36 | // only legacy checkboxes (Advanced and Expert tab) need to be handled here, |
@@ -18,11 +18,11 @@ |
||
18 | 18 | // only legacy checkboxes (Advanced and Expert tab) need to be handled here, |
19 | 19 | // the Wizard-like tabs handle it on their own |
20 | 20 | $chkboxes = ['ldap_configuration_active', 'ldap_override_main_server', |
21 | - 'ldap_turn_off_cert_check']; |
|
21 | + 'ldap_turn_off_cert_check']; |
|
22 | 22 | foreach ($chkboxes as $boxid) { |
23 | - if (!isset($_POST[$boxid])) { |
|
24 | - $_POST[$boxid] = 0; |
|
25 | - } |
|
23 | + if (!isset($_POST[$boxid])) { |
|
24 | + $_POST[$boxid] = 0; |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $ldapWrapper = new LDAP(); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | $readOnly = false; |
80 | - $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
80 | + $readOnlyIndex = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
81 | 81 | if (isset($calendar[$readOnlyIndex])) { |
82 | 82 | $readOnly = $calendar[$readOnlyIndex]; |
83 | 83 | } |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | $calendarTableData[] = [ |
86 | 86 | $calendar['uri'], |
87 | 87 | $calendar['{DAV:}displayname'], |
88 | - $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'], |
|
89 | - $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], |
|
88 | + $calendar['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal'], |
|
89 | + $calendar['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD.'}owner-displayname'], |
|
90 | 90 | $readOnly ? ' x ' : ' ✓ ', |
91 | 91 | ]; |
92 | 92 | } |
@@ -15,61 +15,61 @@ |
||
15 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
16 | 16 | |
17 | 17 | class ListCalendars extends Command { |
18 | - public function __construct( |
|
19 | - protected IUserManager $userManager, |
|
20 | - private CalDavBackend $caldav, |
|
21 | - ) { |
|
22 | - parent::__construct(); |
|
23 | - } |
|
18 | + public function __construct( |
|
19 | + protected IUserManager $userManager, |
|
20 | + private CalDavBackend $caldav, |
|
21 | + ) { |
|
22 | + parent::__construct(); |
|
23 | + } |
|
24 | 24 | |
25 | - protected function configure(): void { |
|
26 | - $this |
|
27 | - ->setName('dav:list-calendars') |
|
28 | - ->setDescription('List all calendars of a user') |
|
29 | - ->addArgument('uid', |
|
30 | - InputArgument::REQUIRED, |
|
31 | - 'User for whom all calendars will be listed'); |
|
32 | - } |
|
25 | + protected function configure(): void { |
|
26 | + $this |
|
27 | + ->setName('dav:list-calendars') |
|
28 | + ->setDescription('List all calendars of a user') |
|
29 | + ->addArgument('uid', |
|
30 | + InputArgument::REQUIRED, |
|
31 | + 'User for whom all calendars will be listed'); |
|
32 | + } |
|
33 | 33 | |
34 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
35 | - $user = $input->getArgument('uid'); |
|
36 | - if (!$this->userManager->userExists($user)) { |
|
37 | - throw new \InvalidArgumentException("User <$user> is unknown."); |
|
38 | - } |
|
34 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
35 | + $user = $input->getArgument('uid'); |
|
36 | + if (!$this->userManager->userExists($user)) { |
|
37 | + throw new \InvalidArgumentException("User <$user> is unknown."); |
|
38 | + } |
|
39 | 39 | |
40 | - $calendars = $this->caldav->getCalendarsForUser("principals/users/$user"); |
|
40 | + $calendars = $this->caldav->getCalendarsForUser("principals/users/$user"); |
|
41 | 41 | |
42 | - $calendarTableData = []; |
|
43 | - foreach ($calendars as $calendar) { |
|
44 | - // skip birthday calendar |
|
45 | - if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
46 | - continue; |
|
47 | - } |
|
42 | + $calendarTableData = []; |
|
43 | + foreach ($calendars as $calendar) { |
|
44 | + // skip birthday calendar |
|
45 | + if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
46 | + continue; |
|
47 | + } |
|
48 | 48 | |
49 | - $readOnly = false; |
|
50 | - $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
51 | - if (isset($calendar[$readOnlyIndex])) { |
|
52 | - $readOnly = $calendar[$readOnlyIndex]; |
|
53 | - } |
|
49 | + $readOnly = false; |
|
50 | + $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
51 | + if (isset($calendar[$readOnlyIndex])) { |
|
52 | + $readOnly = $calendar[$readOnlyIndex]; |
|
53 | + } |
|
54 | 54 | |
55 | - $calendarTableData[] = [ |
|
56 | - $calendar['uri'], |
|
57 | - $calendar['{DAV:}displayname'], |
|
58 | - $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'], |
|
59 | - $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], |
|
60 | - $readOnly ? ' x ' : ' ✓ ', |
|
61 | - ]; |
|
62 | - } |
|
55 | + $calendarTableData[] = [ |
|
56 | + $calendar['uri'], |
|
57 | + $calendar['{DAV:}displayname'], |
|
58 | + $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'], |
|
59 | + $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], |
|
60 | + $readOnly ? ' x ' : ' ✓ ', |
|
61 | + ]; |
|
62 | + } |
|
63 | 63 | |
64 | - if (count($calendarTableData) > 0) { |
|
65 | - $table = new Table($output); |
|
66 | - $table->setHeaders(['URI', 'Displayname', 'Owner principal', 'Owner displayname', 'Writable']) |
|
67 | - ->setRows($calendarTableData); |
|
64 | + if (count($calendarTableData) > 0) { |
|
65 | + $table = new Table($output); |
|
66 | + $table->setHeaders(['URI', 'Displayname', 'Owner principal', 'Owner displayname', 'Writable']) |
|
67 | + ->setRows($calendarTableData); |
|
68 | 68 | |
69 | - $table->render(); |
|
70 | - } else { |
|
71 | - $output->writeln("<info>User <$user> has no calendars</info>"); |
|
72 | - } |
|
73 | - return self::SUCCESS; |
|
74 | - } |
|
69 | + $table->render(); |
|
70 | + } else { |
|
71 | + $output->writeln("<info>User <$user> has no calendars</info>"); |
|
72 | + } |
|
73 | + return self::SUCCESS; |
|
74 | + } |
|
75 | 75 | } |
@@ -30,67 +30,67 @@ |
||
30 | 30 | use OCP\WorkflowEngine\IOperation; |
31 | 31 | |
32 | 32 | class LogContext { |
33 | - /** @var array */ |
|
34 | - protected $details; |
|
33 | + /** @var array */ |
|
34 | + protected $details; |
|
35 | 35 | |
36 | - public function setDescription(string $description): LogContext { |
|
37 | - $this->details['message'] = $description; |
|
38 | - return $this; |
|
39 | - } |
|
36 | + public function setDescription(string $description): LogContext { |
|
37 | + $this->details['message'] = $description; |
|
38 | + return $this; |
|
39 | + } |
|
40 | 40 | |
41 | - public function setScopes(array $scopes): LogContext { |
|
42 | - $this->details['scopes'] = []; |
|
43 | - foreach ($scopes as $scope) { |
|
44 | - if ($scope instanceof ScopeContext) { |
|
45 | - switch ($scope->getScope()) { |
|
46 | - case IManager::SCOPE_ADMIN: |
|
47 | - $this->details['scopes'][] = ['scope' => 'admin']; |
|
48 | - break; |
|
49 | - case IManager::SCOPE_USER: |
|
50 | - $this->details['scopes'][] = [ |
|
51 | - 'scope' => 'user', |
|
52 | - 'uid' => $scope->getScopeId(), |
|
53 | - ]; |
|
54 | - break; |
|
55 | - default: |
|
56 | - continue 2; |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
60 | - return $this; |
|
61 | - } |
|
41 | + public function setScopes(array $scopes): LogContext { |
|
42 | + $this->details['scopes'] = []; |
|
43 | + foreach ($scopes as $scope) { |
|
44 | + if ($scope instanceof ScopeContext) { |
|
45 | + switch ($scope->getScope()) { |
|
46 | + case IManager::SCOPE_ADMIN: |
|
47 | + $this->details['scopes'][] = ['scope' => 'admin']; |
|
48 | + break; |
|
49 | + case IManager::SCOPE_USER: |
|
50 | + $this->details['scopes'][] = [ |
|
51 | + 'scope' => 'user', |
|
52 | + 'uid' => $scope->getScopeId(), |
|
53 | + ]; |
|
54 | + break; |
|
55 | + default: |
|
56 | + continue 2; |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | + return $this; |
|
61 | + } |
|
62 | 62 | |
63 | - public function setOperation(?IOperation $operation): LogContext { |
|
64 | - if ($operation instanceof IOperation) { |
|
65 | - $this->details['operation'] = [ |
|
66 | - 'class' => get_class($operation), |
|
67 | - 'name' => $operation->getDisplayName(), |
|
68 | - ]; |
|
69 | - } |
|
70 | - return $this; |
|
71 | - } |
|
63 | + public function setOperation(?IOperation $operation): LogContext { |
|
64 | + if ($operation instanceof IOperation) { |
|
65 | + $this->details['operation'] = [ |
|
66 | + 'class' => get_class($operation), |
|
67 | + 'name' => $operation->getDisplayName(), |
|
68 | + ]; |
|
69 | + } |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | - public function setEntity(?IEntity $entity): LogContext { |
|
74 | - if ($entity instanceof IEntity) { |
|
75 | - $this->details['entity'] = [ |
|
76 | - 'class' => get_class($entity), |
|
77 | - 'name' => $entity->getName(), |
|
78 | - ]; |
|
79 | - } |
|
80 | - return $this; |
|
81 | - } |
|
73 | + public function setEntity(?IEntity $entity): LogContext { |
|
74 | + if ($entity instanceof IEntity) { |
|
75 | + $this->details['entity'] = [ |
|
76 | + 'class' => get_class($entity), |
|
77 | + 'name' => $entity->getName(), |
|
78 | + ]; |
|
79 | + } |
|
80 | + return $this; |
|
81 | + } |
|
82 | 82 | |
83 | - public function setConfiguration(array $configuration): LogContext { |
|
84 | - $this->details['configuration'] = $configuration; |
|
85 | - return $this; |
|
86 | - } |
|
83 | + public function setConfiguration(array $configuration): LogContext { |
|
84 | + $this->details['configuration'] = $configuration; |
|
85 | + return $this; |
|
86 | + } |
|
87 | 87 | |
88 | - public function setEventName(string $eventName): LogContext { |
|
89 | - $this->details['eventName'] = $eventName; |
|
90 | - return $this; |
|
91 | - } |
|
88 | + public function setEventName(string $eventName): LogContext { |
|
89 | + $this->details['eventName'] = $eventName; |
|
90 | + return $this; |
|
91 | + } |
|
92 | 92 | |
93 | - public function getDetails(): array { |
|
94 | - return $this->details; |
|
95 | - } |
|
93 | + public function getDetails(): array { |
|
94 | + return $this->details; |
|
95 | + } |
|
96 | 96 | } |
@@ -30,13 +30,13 @@ |
||
30 | 30 | |
31 | 31 | class GlobalWorkflowsController extends AWorkflowController { |
32 | 32 | |
33 | - /** @var ScopeContext */ |
|
34 | - private $scopeContext; |
|
33 | + /** @var ScopeContext */ |
|
34 | + private $scopeContext; |
|
35 | 35 | |
36 | - protected function getScopeContext(): ScopeContext { |
|
37 | - if ($this->scopeContext === null) { |
|
38 | - $this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN); |
|
39 | - } |
|
40 | - return $this->scopeContext; |
|
41 | - } |
|
36 | + protected function getScopeContext(): ScopeContext { |
|
37 | + if ($this->scopeContext === null) { |
|
38 | + $this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN); |
|
39 | + } |
|
40 | + return $this->scopeContext; |
|
41 | + } |
|
42 | 42 | } |
@@ -30,19 +30,19 @@ |
||
30 | 30 | use OCP\IL10N; |
31 | 31 | |
32 | 32 | class SFTP_Key extends Backend { |
33 | - public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { |
|
34 | - $this |
|
35 | - ->setIdentifier('\OC\Files\Storage\SFTP_Key') |
|
36 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
37 | - ->setText($l->t('SFTP with secret key login')) |
|
38 | - ->addParameters([ |
|
39 | - new DefinitionParameter('host', $l->t('Host')), |
|
40 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
41 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
42 | - ]) |
|
43 | - ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
44 | - ->setLegacyAuthMechanism($legacyAuth) |
|
45 | - ->deprecateTo($sftpBackend) |
|
46 | - ; |
|
47 | - } |
|
33 | + public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { |
|
34 | + $this |
|
35 | + ->setIdentifier('\OC\Files\Storage\SFTP_Key') |
|
36 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
37 | + ->setText($l->t('SFTP with secret key login')) |
|
38 | + ->addParameters([ |
|
39 | + new DefinitionParameter('host', $l->t('Host')), |
|
40 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
41 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
42 | + ]) |
|
43 | + ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
44 | + ->setLegacyAuthMechanism($legacyAuth) |
|
45 | + ->deprecateTo($sftpBackend) |
|
46 | + ; |
|
47 | + } |
|
48 | 48 | } |
@@ -25,19 +25,19 @@ |
||
25 | 25 | namespace OCA\Files_External\Config; |
26 | 26 | |
27 | 27 | class UserPlaceholderHandler extends UserContext implements IConfigHandler { |
28 | - use SimpleSubstitutionTrait; |
|
28 | + use SimpleSubstitutionTrait; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param mixed $optionValue |
|
32 | - * @return mixed the same type as $optionValue |
|
33 | - * @since 16.0.0 |
|
34 | - */ |
|
35 | - public function handle($optionValue) { |
|
36 | - $this->placeholder = 'user'; |
|
37 | - $uid = $this->getUserId(); |
|
38 | - if ($uid === null) { |
|
39 | - return $optionValue; |
|
40 | - } |
|
41 | - return $this->processInput($optionValue, $uid); |
|
42 | - } |
|
30 | + /** |
|
31 | + * @param mixed $optionValue |
|
32 | + * @return mixed the same type as $optionValue |
|
33 | + * @since 16.0.0 |
|
34 | + */ |
|
35 | + public function handle($optionValue) { |
|
36 | + $this->placeholder = 'user'; |
|
37 | + $uid = $this->getUserId(); |
|
38 | + if ($uid === null) { |
|
39 | + return $optionValue; |
|
40 | + } |
|
41 | + return $this->processInput($optionValue, $uid); |
|
42 | + } |
|
43 | 43 | } |
@@ -31,57 +31,57 @@ |
||
31 | 31 | * @since 16.0.0 |
32 | 32 | */ |
33 | 33 | trait SimpleSubstitutionTrait { |
34 | - /** |
|
35 | - * @var string the placeholder without $ prefix |
|
36 | - * @since 16.0.0 |
|
37 | - */ |
|
38 | - protected $placeholder; |
|
34 | + /** |
|
35 | + * @var string the placeholder without $ prefix |
|
36 | + * @since 16.0.0 |
|
37 | + */ |
|
38 | + protected $placeholder; |
|
39 | 39 | |
40 | - /** @var string */ |
|
41 | - protected $sanitizedPlaceholder; |
|
40 | + /** @var string */ |
|
41 | + protected $sanitizedPlaceholder; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param mixed $optionValue |
|
45 | - * @param string $replacement |
|
46 | - * @return mixed |
|
47 | - * @since 16.0.0 |
|
48 | - */ |
|
49 | - private function processInput($optionValue, string $replacement) { |
|
50 | - $this->checkPlaceholder(); |
|
51 | - if (is_array($optionValue)) { |
|
52 | - foreach ($optionValue as &$value) { |
|
53 | - $value = $this->substituteIfString($value, $replacement); |
|
54 | - } |
|
55 | - } else { |
|
56 | - $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | - } |
|
58 | - return $optionValue; |
|
59 | - } |
|
43 | + /** |
|
44 | + * @param mixed $optionValue |
|
45 | + * @param string $replacement |
|
46 | + * @return mixed |
|
47 | + * @since 16.0.0 |
|
48 | + */ |
|
49 | + private function processInput($optionValue, string $replacement) { |
|
50 | + $this->checkPlaceholder(); |
|
51 | + if (is_array($optionValue)) { |
|
52 | + foreach ($optionValue as &$value) { |
|
53 | + $value = $this->substituteIfString($value, $replacement); |
|
54 | + } |
|
55 | + } else { |
|
56 | + $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | + } |
|
58 | + return $optionValue; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @throws \RuntimeException |
|
63 | - */ |
|
64 | - protected function checkPlaceholder(): void { |
|
65 | - $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | - if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | - throw new \RuntimeException(sprintf( |
|
68 | - 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | - )); |
|
70 | - } |
|
71 | - if ($this->sanitizedPlaceholder === '') { |
|
72 | - throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | - } |
|
74 | - } |
|
61 | + /** |
|
62 | + * @throws \RuntimeException |
|
63 | + */ |
|
64 | + protected function checkPlaceholder(): void { |
|
65 | + $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | + if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | + throw new \RuntimeException(sprintf( |
|
68 | + 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | + )); |
|
70 | + } |
|
71 | + if ($this->sanitizedPlaceholder === '') { |
|
72 | + throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param mixed $value |
|
78 | - * @param string $replacement |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - protected function substituteIfString($value, string $replacement) { |
|
82 | - if (is_string($value)) { |
|
83 | - return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | - } |
|
85 | - return $value; |
|
86 | - } |
|
76 | + /** |
|
77 | + * @param mixed $value |
|
78 | + * @param string $replacement |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + protected function substituteIfString($value, string $replacement) { |
|
82 | + if (is_string($value)) { |
|
83 | + return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | + } |
|
85 | + return $value; |
|
86 | + } |
|
87 | 87 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function checkPlaceholder(): void { |
65 | 65 | $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
66 | - if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
66 | + if (!(bool) \preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | 67 | throw new \RuntimeException(sprintf( |
68 | 68 | 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
69 | 69 | )); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function substituteIfString($value, string $replacement) { |
82 | 82 | if (is_string($value)) { |
83 | - return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
83 | + return str_ireplace('$'.$this->sanitizedPlaceholder, $replacement, $value); |
|
84 | 84 | } |
85 | 85 | return $value; |
86 | 86 | } |
@@ -60,11 +60,11 @@ |
||
60 | 60 | // at least on PHP 5.6 usort turned out to be not stable. So we add |
61 | 61 | // the current index to the value and compare it on a draw |
62 | 62 | $i = 0; |
63 | - $workArray = array_map(function ($element) use (&$i) { |
|
63 | + $workArray = array_map(function($element) use (&$i) { |
|
64 | 64 | return [$i++, $element]; |
65 | 65 | }, $byType); |
66 | 66 | |
67 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
67 | + usort($workArray, function($a, $b) use ($commenters, $type) { |
|
68 | 68 | $r = $this->compare($a[1], $b[1], $commenters[$type]); |
69 | 69 | if ($r === 0) { |
70 | 70 | $r = $a[0] - $b[0]; |
@@ -9,83 +9,83 @@ |
||
9 | 9 | use OCP\Comments\ICommentsManager; |
10 | 10 | |
11 | 11 | class CommentersSorter implements ISorter { |
12 | - public function __construct( |
|
13 | - private ICommentsManager $commentsManager, |
|
14 | - ) { |
|
15 | - } |
|
12 | + public function __construct( |
|
13 | + private ICommentsManager $commentsManager, |
|
14 | + ) { |
|
15 | + } |
|
16 | 16 | |
17 | - public function getId(): string { |
|
18 | - return 'commenters'; |
|
19 | - } |
|
17 | + public function getId(): string { |
|
18 | + return 'commenters'; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Sorts people who commented on the given item atop (descelating) of the |
|
23 | - * others |
|
24 | - * |
|
25 | - * @param array &$sortArray |
|
26 | - * @param array $context |
|
27 | - */ |
|
28 | - public function sort(array &$sortArray, array $context): void { |
|
29 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
30 | - if (count($commenters) === 0) { |
|
31 | - return; |
|
32 | - } |
|
21 | + /** |
|
22 | + * Sorts people who commented on the given item atop (descelating) of the |
|
23 | + * others |
|
24 | + * |
|
25 | + * @param array &$sortArray |
|
26 | + * @param array $context |
|
27 | + */ |
|
28 | + public function sort(array &$sortArray, array $context): void { |
|
29 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
30 | + if (count($commenters) === 0) { |
|
31 | + return; |
|
32 | + } |
|
33 | 33 | |
34 | - foreach ($sortArray as $type => &$byType) { |
|
35 | - if (!isset($commenters[$type])) { |
|
36 | - continue; |
|
37 | - } |
|
34 | + foreach ($sortArray as $type => &$byType) { |
|
35 | + if (!isset($commenters[$type])) { |
|
36 | + continue; |
|
37 | + } |
|
38 | 38 | |
39 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
40 | - // the current index to the value and compare it on a draw |
|
41 | - $i = 0; |
|
42 | - $workArray = array_map(function ($element) use (&$i) { |
|
43 | - return [$i++, $element]; |
|
44 | - }, $byType); |
|
39 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
40 | + // the current index to the value and compare it on a draw |
|
41 | + $i = 0; |
|
42 | + $workArray = array_map(function ($element) use (&$i) { |
|
43 | + return [$i++, $element]; |
|
44 | + }, $byType); |
|
45 | 45 | |
46 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
47 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
48 | - if ($r === 0) { |
|
49 | - $r = $a[0] - $b[0]; |
|
50 | - } |
|
51 | - return $r; |
|
52 | - }); |
|
46 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
47 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
48 | + if ($r === 0) { |
|
49 | + $r = $a[0] - $b[0]; |
|
50 | + } |
|
51 | + return $r; |
|
52 | + }); |
|
53 | 53 | |
54 | - // and remove the index values again |
|
55 | - $byType = array_column($workArray, 1); |
|
56 | - } |
|
57 | - } |
|
54 | + // and remove the index values again |
|
55 | + $byType = array_column($workArray, 1); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return array<string, array<string, int>> |
|
61 | - */ |
|
62 | - protected function retrieveCommentsInformation(string $type, string $id): array { |
|
63 | - $comments = $this->commentsManager->getForObject($type, $id); |
|
64 | - if (count($comments) === 0) { |
|
65 | - return []; |
|
66 | - } |
|
59 | + /** |
|
60 | + * @return array<string, array<string, int>> |
|
61 | + */ |
|
62 | + protected function retrieveCommentsInformation(string $type, string $id): array { |
|
63 | + $comments = $this->commentsManager->getForObject($type, $id); |
|
64 | + if (count($comments) === 0) { |
|
65 | + return []; |
|
66 | + } |
|
67 | 67 | |
68 | - $actors = []; |
|
69 | - foreach ($comments as $comment) { |
|
70 | - if (!isset($actors[$comment->getActorType()])) { |
|
71 | - $actors[$comment->getActorType()] = []; |
|
72 | - } |
|
73 | - if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
74 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
75 | - } else { |
|
76 | - $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
77 | - } |
|
78 | - } |
|
79 | - return $actors; |
|
80 | - } |
|
68 | + $actors = []; |
|
69 | + foreach ($comments as $comment) { |
|
70 | + if (!isset($actors[$comment->getActorType()])) { |
|
71 | + $actors[$comment->getActorType()] = []; |
|
72 | + } |
|
73 | + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
74 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
75 | + } else { |
|
76 | + $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
77 | + } |
|
78 | + } |
|
79 | + return $actors; |
|
80 | + } |
|
81 | 81 | |
82 | - protected function compare(array $a, array $b, array $commenters): int { |
|
83 | - $a = $a['value']['shareWith']; |
|
84 | - $b = $b['value']['shareWith']; |
|
82 | + protected function compare(array $a, array $b, array $commenters): int { |
|
83 | + $a = $a['value']['shareWith']; |
|
84 | + $b = $b['value']['shareWith']; |
|
85 | 85 | |
86 | - $valueA = $commenters[$a] ?? 0; |
|
87 | - $valueB = $commenters[$b] ?? 0; |
|
86 | + $valueA = $commenters[$a] ?? 0; |
|
87 | + $valueB = $commenters[$b] ?? 0; |
|
88 | 88 | |
89 | - return $valueB - $valueA; |
|
90 | - } |
|
89 | + return $valueB - $valueA; |
|
90 | + } |
|
91 | 91 | } |