Completed
Pull Request — master (#18)
by Matt
04:55
created
src/Tasks/LDAPMemberSyncTask.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @var array
29 29
      */
30 30
     private static $dependencies = [
31
-        'ldapService' => '%$' . LDAPService::class,
31
+        'ldapService' => '%$'.LDAPService::class,
32 32
     ];
33 33
 
34 34
     /**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function getTitle()
52 52
     {
53
-        return _t(__CLASS__ . '.SYNCTITLE', 'Sync all users from Active Directory');
53
+        return _t(__CLASS__.'.SYNCTITLE', 'Sync all users from Active Directory');
54 54
     }
55 55
 
56 56
     /**
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
      */
155 155
     protected function log($message)
156 156
     {
157
-        $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message;
158
-        echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '<br>');
157
+        $message = sprintf('[%s] ', date('Y-m-d H:i:s')).$message;
158
+        echo Director::is_cli() ? ($message.PHP_EOL) : ($message.'<br>');
159 159
     }
160 160
 
161 161
     /**
Please login to merge, or discard this patch.
src/Tasks/LDAPMemberSyncOneTask.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @var array
28 28
      */
29 29
     private static $dependencies = [
30
-        'ldapService' => '%$' . LDAPService::class,
30
+        'ldapService' => '%$'.LDAPService::class,
31 31
     ];
32 32
 
33 33
     /**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function getTitle()
37 37
     {
38
-        return _t(__CLASS__ . '.SYNCONETITLE', 'Sync single user from LDAP');
38
+        return _t(__CLASS__.'.SYNCONETITLE', 'Sync single user from LDAP');
39 39
     }
40 40
 
41 41
     /**
Please login to merge, or discard this patch.
src/Iterators/LDAPIterator.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
         } else {
114 114
             $resultResource = ldap_search($resource, $baseDn, $this->getFilter());
115 115
         }
116
-        if (! is_resource($resultResource)) {
116
+        if (!is_resource($resultResource)) {
117 117
             /*
118 118
              * @TODO better exception msg
119 119
              */
120
-            throw new \Exception('ldap_search returned something wrong...' . ldap_error($resource));
120
+            throw new \Exception('ldap_search returned something wrong...'.ldap_error($resource));
121 121
         }
122 122
 
123 123
         $entries = ldap_get_entries($resource, $resultResource);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         $attributeValue = [];
205 205
 
206 206
         $limit = $offset + $maxPerRequest - 1;
207
-        $searchedAttribute = $attrName . ';range=' . $offset . '-' . $limit;
207
+        $searchedAttribute = $attrName.';range='.$offset.'-'.$limit;
208 208
 
209 209
         $ldap = $this->getLdap();
210 210
         $entry = $ldap->getEntry($dn, [
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
     }
235 235
     public function current()
236 236
     {
237
-        if (! is_array($this->current)) {
237
+        if (!is_array($this->current)) {
238 238
             $this->rewind();
239 239
         }
240
-        if (! is_array($this->current)) {
240
+        if (!is_array($this->current)) {
241 241
             return;
242 242
         }
243 243
 
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
     }
246 246
     public function key()
247 247
     {
248
-        if (! is_array($this->current)) {
248
+        if (!is_array($this->current)) {
249 249
             $this->rewind();
250 250
         }
251
-        if (! is_array($this->current)) {
251
+        if (!is_array($this->current)) {
252 252
             return;
253 253
         }
254 254
 
Please login to merge, or discard this patch.
src/Services/LDAPService.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      * @var array
60 60
      */
61 61
     private static $dependencies = [
62
-        'gateway' => '%$' . LDAPGateway::class
62
+        'gateway' => '%$'.LDAPGateway::class
63 63
     ];
64 64
 
65 65
     /**
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public static function get_cache()
137 137
     {
138
-        return Injector::inst()->get(CacheInterface::class . '.ldap');
138
+        return Injector::inst()->get(CacheInterface::class.'.ldap');
139 139
     }
140 140
 
141 141
     /**
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
         // show better errors than the defaults for various status codes returned by LDAP
218 218
         if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_ACCOUNT_LOCKED_OUT') !== false) {
219 219
             $message = _t(
220
-                __CLASS__ . '.ACCOUNTLOCKEDOUT',
221
-                'Your account has been temporarily locked because of too many failed login attempts. ' .
220
+                __CLASS__.'.ACCOUNTLOCKEDOUT',
221
+                'Your account has been temporarily locked because of too many failed login attempts. '.
222 222
                 'Please try again later.'
223 223
             );
224 224
         }
225 225
         if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_LOGON_FAILURE') !== false) {
226 226
             $message = _t(
227
-                __CLASS__ . '.INVALIDCREDENTIALS',
227
+                __CLASS__.'.INVALIDCREDENTIALS',
228 228
                 'The provided details don\'t seem to be correct. Please try again.'
229 229
             );
230 230
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function getNodes($cached = true, $attributes = [])
248 248
     {
249 249
         $cache = self::get_cache();
250
-        $cacheKey = 'nodes' . md5(implode('', $attributes));
250
+        $cacheKey = 'nodes'.md5(implode('', $attributes));
251 251
         $results = $cache->has($cacheKey);
252 252
 
253 253
         if (!$results || !$cached) {
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     {
278 278
         $searchLocations = $this->config()->groups_search_locations ?: [null];
279 279
         $cache = self::get_cache();
280
-        $cacheKey = 'groups' . md5(implode('', array_merge($searchLocations, $attributes)));
280
+        $cacheKey = 'groups'.md5(implode('', array_merge($searchLocations, $attributes)));
281 281
         $results = $cache->has($cacheKey);
282 282
 
283 283
         if (!$results || !$cached) {
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
         }
546 546
 
547 547
         $member->IsExpired = ($data['useraccountcontrol'] & 2) == 2;
548
-        $member->LastSynced = (string)DBDatetime::now();
548
+        $member->LastSynced = (string) DBDatetime::now();
549 549
 
550 550
         foreach ($member->config()->ldap_field_mappings as $attribute => $field) {
551 551
             // Special handling required for attributes that don't exist in the response.
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
                 } else {
567 567
                     $this->getLogger()->debug(
568 568
                         sprintf(
569
-                            'Attribute %s configured in Member.ldap_field_mappings, ' .
569
+                            'Attribute %s configured in Member.ldap_field_mappings, '.
570 570
                             'but no available attribute in AD data (GUID: %s, Member ID: %s)',
571 571
                             $attribute,
572 572
                             $data['objectguid'],
@@ -754,14 +754,14 @@  discard block
 block discarded – undo
754 754
         }
755 755
 
756 756
         // Lookup the previous mappings and see if there is any mappings no longer present.
757
-        $unmappedGroups = $member->Groups()->alterDataQuery(function (DataQuery $query) {
757
+        $unmappedGroups = $member->Groups()->alterDataQuery(function(DataQuery $query) {
758 758
             // join with the Group_Members table because we only want those group members assigned by this module.
759 759
             $query->leftJoin("Group_Members", "Group_Members.GroupID = Group.ID");
760 760
             $query->where("IsImportedFromLDAP = 1");
761 761
         });
762 762
 
763 763
         // Don't remove associations which have just been added and we know are already correct!
764
-        if(!empty($mappedGroupIDs)){
764
+        if (!empty($mappedGroupIDs)) {
765 765
             $unmappedGroups = $unmappedGroups->filter("GroupID:NOT", $mappedGroupIDs);
766 766
         }
767 767
 
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
             $group->Description = $data['description'];
796 796
         }
797 797
         $group->DN = $data['dn'];
798
-        $group->LastSynced = (string)DBDatetime::now();
798
+        $group->LastSynced = (string) DBDatetime::now();
799 799
         $group->write();
800 800
 
801 801
         // Mappings on this group are automatically maintained to contain just the group's DN.
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
                 ),
859 859
             ]);
860 860
         } catch (Exception $e) {
861
-            throw new ValidationException('LDAP synchronisation failure: ' . $e->getMessage());
861
+            throw new ValidationException('LDAP synchronisation failure: '.$e->getMessage());
862 862
         }
863 863
 
864 864
         $user = $this->getUserByUsername($member->Username);
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
                 'distinguishedname' => $dn
903 903
             ]);
904 904
         } catch (Exception $e) {
905
-            throw new ValidationException('LDAP group creation failure: ' . $e->getMessage());
905
+            throw new ValidationException('LDAP group creation failure: '.$e->getMessage());
906 906
         }
907 907
 
908 908
         $data = $this->getGroupByDN($dn);
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             try {
1068 1068
                 $this->update($groupDn, ['member' => $members]);
1069 1069
             } catch (Exception $e) {
1070
-                throw new ValidationException('LDAP group membership remove failure: ' . $e->getMessage());
1070
+                throw new ValidationException('LDAP group membership remove failure: '.$e->getMessage());
1071 1071
             }
1072 1072
         }
1073 1073
     }
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
         try {
1094 1094
             $this->update($groupDn, ['member' => $members]);
1095 1095
         } catch (Exception $e) {
1096
-            throw new ValidationException('LDAP group membership add failure: ' . $e->getMessage());
1096
+            throw new ValidationException('LDAP group membership add failure: '.$e->getMessage());
1097 1097
         }
1098 1098
     }
1099 1099
 
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
         try {
1177 1177
             $this->delete($data['distinguishedname']);
1178 1178
         } catch (Exception $e) {
1179
-            throw new ValidationException('LDAP delete user failed: ' . $e->getMessage());
1179
+            throw new ValidationException('LDAP delete user failed: '.$e->getMessage());
1180 1180
         }
1181 1181
     }
1182 1182
 
Please login to merge, or discard this patch.
tests/php/Model/LDAPFakeMember.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
      *
21 21
      * @return int|void
22 22
      */
23
-    public function write(){
23
+    public function write() {
24 24
         // Noop
25 25
     }
26 26
 }
Please login to merge, or discard this patch.
tests/php/Services/LDAPServiceTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         $member->write();
153 153
 
154 154
         // Pretend we're the module, and generate some mappings.
155
-        Group::get()->each(function ($group) use ($member) {
155
+        Group::get()->each(function($group) use ($member) {
156 156
             $group->Members()->add($member, [
157 157
                 'IsImportedFromLDAP' => '1'
158 158
             ]);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             ]
183 183
         );
184 184
 
185
-        Config::modify()->set(LDAPService::class,'reset_missing_attributes', true);
185
+        Config::modify()->set(LDAPService::class, 'reset_missing_attributes', true);
186 186
 
187 187
         $member = new Member();
188 188
         $member->GUID = '123';
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
             ]
216 216
         );
217 217
 
218
-        Config::modify()->set(LDAPService::class,'reset_missing_attributes', true);
218
+        Config::modify()->set(LDAPService::class, 'reset_missing_attributes', true);
219 219
 
220 220
         // Create a test 'image' for this member.
221 221
         /** @var File $file */
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ]
255 255
         );
256 256
 
257
-        Config::modify()->set(LDAPService::class,'reset_missing_attributes', true);
257
+        Config::modify()->set(LDAPService::class, 'reset_missing_attributes', true);
258 258
 
259 259
         // Create a test 'image' for this member.
260 260
         /** @var File $file */
Please login to merge, or discard this patch.