Skip to content

Commit a4a99ed

Browse files
committed
Slugify instances don't need to be class member variables.
1 parent 30045ca commit a4a99ed

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/LdapGroupSyncCommand.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
class LdapGroupSyncCommand extends \Symfony\Component\Console\Command\Command
1717
{
18-
private $logger = null;
19-
private $dryRun = false;
20-
21-
private $slugifyGitlabName = null;
22-
private $slugifyGitlabPath = null;
18+
private $logger = null;
19+
private $dryRun = false;
2320

2421
/**
2522
* Configures the current command.
@@ -51,20 +48,6 @@ public function execute(InputInterface $input, OutputInterface $output): ?int
5148
$this->logger->warning("Dry run enabled: No changes will be persisted.");
5249
}
5350

54-
$this->slugifyGitlabName = new Slugify([
55-
"regexp" => "/([^A-Za-z0-9]|-_\. )+/",
56-
"separator" => " ",
57-
"lowercase" => false,
58-
"trim" => true,
59-
]);
60-
61-
$this->slugifyGitlabPath = new Slugify([
62-
"regexp" => "/([^A-Za-z0-9]|-_\.)+/",
63-
"separator" => "-",
64-
"lowercase" => true,
65-
"trim" => true,
66-
]);
67-
6851

6952

7053
// Load configuration
@@ -763,6 +746,20 @@ private function getLdapGroupsAndUsers(array $config, array &$groups, int &$grou
763746
*/
764747
private function deployGitlabGroupsAndUsers(array $config, string $gitlabInstance, array $gitlabConfig, array $ldapGroups, int $ldapGroupsNum, array $ldapUsers, int $ldapUsersNum): void
765748
{
749+
$slugifyGitlabName = new Slugify([
750+
"regexp" => "/([^A-Za-z0-9]|-_\. )+/",
751+
"separator" => " ",
752+
"lowercase" => false,
753+
"trim" => true,
754+
]);
755+
756+
$slugifyGitlabPath = new Slugify([
757+
"regexp" => "/([^A-Za-z0-9]|-_\.)+/",
758+
"separator" => "-",
759+
"lowercase" => true,
760+
"trim" => true,
761+
]);
762+
766763
// Connect
767764
$this->logger->notice("Establishing Gitlab connection.", [
768765
"instance" => $gitlabInstance,
@@ -842,8 +839,8 @@ private function deployGitlabGroupsAndUsers(array $config, string $gitlabInstanc
842839
continue;
843840
}
844841

845-
$gitlabGroupName = $this->slugifyGitlabName->slugify($ldapGroupName);
846-
$gitlabGroupPath = $this->slugifyGitlabPath->slugify($ldapGroupName);
842+
$gitlabGroupName = $slugifyGitlabName->slugify($ldapGroupName);
843+
$gitlabGroupPath = $slugifyGitlabPath->slugify($ldapGroupName);
847844

848845
if (!in_array($gitlabGroupName, $groupsSync["found"])) {
849846
$this->logger->info(sprintf("Directory group \"%s\" is not in Gitlab.", $ldapGroupName));
@@ -872,7 +869,7 @@ private function deployGitlabGroupsAndUsers(array $config, string $gitlabInstanc
872869
continue;
873870
}
874871

875-
$gitlabGroupPath = $this->slugifyGitlabPath->slugify($gitlabGroupName);
872+
$gitlabGroupPath = $slugifyGitlabPath->slugify($gitlabGroupName);
876873

877874
if (!in_array($gitlabGroupName, $ldapGroups)) {
878875
$this->logger->info(sprintf("Gitlab group \"%s\" is not in directory.", $gitlabGroupName));
@@ -903,7 +900,7 @@ private function deployGitlabGroupsAndUsers(array $config, string $gitlabInstanc
903900
continue;
904901
}
905902

906-
$gitlabGroupPath = $this->slugifyGitlabPath->slugify($gitlabGroupName);
903+
$gitlabGroupPath = $slugifyGitlabPath->slugify($gitlabGroupName);
907904

908905
$usersSync = [
909906
"found" => [],

0 commit comments

Comments
 (0)