InternalEnforcer::updatePolicyInternal()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 11.4436

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 6
nop 4
dl 0
loc 20
ccs 4
cts 11
cp 0.3636
crap 11.4436
rs 9.5555
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
declare(strict_types=1);
4
5
namespace Casbin;
6
7
use Casbin\Exceptions\NotImplementedException;
8
use Casbin\Log\Log;
9
use Casbin\Model\Policy;
10
use Casbin\Persist\BatchAdapter;
11
use Casbin\Persist\UpdatableAdapter;
12
use Casbin\Persist\WatcherEx;
13
use Casbin\Persist\WatcherUpdatable;
14
15
/**
16
 * InternalEnforcer = CoreEnforcer + Internal API.
17
 *
18
 * @author [email protected]
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
19
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
20
class InternalEnforcer extends CoreEnforcer
21
{
22
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
     * @return bool
24
     */
25 99
    protected function shouldPersist(): bool
26
    {
27 99
        return !is_null($this->adapter) && $this->autoSave;
28
    }
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @return bool
32
     */
33 96
    protected function shouldNotify(): bool
34
    {
35 96
        return !is_null($this->watcher) && $this->autoNotifyWatcher;
36
    }
37
38
    /**
39
     * Adds a rule to the current policy without notify.
40
     * 
41
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
42
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
43
     * @param array $rule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
44
     * 
45
     * @return bool
46
     */
47 48
    protected function addPolicyWithoutNotifyInternal(string $sec, string $ptype, array $rule): bool
48
    {
49 48
        if ($this->model->hasPolicy($sec, $ptype, $rule)) {
50 3
            return false;
51
        }
52
53 48
        if ($this->shouldPersist()) {
54
            try {
55 45
                $this->adapter->addPolicy($sec, $ptype, $rule);
56 45
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
            }
58
        }
59
60 48
        $this->model->addPolicy($sec, $ptype, $rule);
61
62 48
        if ($sec == "g") {
63 21
            $this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, [$rule]);
64
        }
65
66 48
        return true;
67
    }
68
69
    /**
70
     * Adds rules to the current policy without notify.
71
     * If autoRemoveRepeat == true, existing rules are automatically filtered
72
     * Otherwise, false is returned directly.
73
     * 
74
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
75
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
76
     * @param array $rules
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
77
     * @param bool $autoRemoveRepeat
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
78
     * 
79
     * @return bool
80
     */
81 27
    protected function addPoliciesWithoutNotifyInternal(string $sec, string $ptype, array $rules, bool $autoRemoveRepeat): bool
82
    {
83 27
        if (!$autoRemoveRepeat) {
84 27
            if ($this->model->hasPolicies($sec, $ptype, $rules)) {
85 9
                return false;
86
            }
87
        }
88
89 27
        if ($this->shouldPersist() && $this->adapter instanceof BatchAdapter) {
90
            try {
91 27
                $this->adapter->addPolicies($sec, $ptype, $rules);
92 21
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
93
            }
94
        }
95
96 27
        $this->model->addPolicies($sec, $ptype, $rules);
97
98 27
        if ($sec == "g") {
99 6
            $this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $rules);
100
        }
101
102 27
        return true;
103
    }
104
105
    /**
106
     * Updates a rule from the current policy without notify.
107
     * 
108
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
109
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
110
     * @param array $oldRule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
111
     * @param array $newRule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
112
     * 
113
     * @return bool
114
     */
115 3
    protected function updatePolicyWithoutNotifyInternal(string $sec, string $ptype, array $oldRule, array $newRule): bool
116
    {
117 3
        if ($this->shouldPersist() && $this->adapter instanceof UpdatableAdapter) {
118
            try {
119 3
                $this->adapter->updatePolicy($sec, $ptype, $oldRule, $newRule);
120 3
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
121
            }
122
        }
123
124 3
        $ruleUpdated = $this->model->updatePolicy($sec, $ptype, $oldRule, $newRule);
125 3
        if (!$ruleUpdated) {
126
            return false;
127
        }
128
129 3
        if ($sec == "g") {
130
            // remove the old rule
131
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, [$oldRule]);
132
133
            // add the new rule
134
            $this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, [$newRule]);
135
        }
136
137 3
        return true;
138
    }
139
140
    /**
141
     * Updates rules from the current policy without notify.
142
     * 
143
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
144
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
145
     * @param array $oldRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
146
     * @param array $newRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
147
     * 
148
     * @return bool
149
     */
150 3
    protected function updatePoliciesWithoutNotifyInternal(string $sec, string $ptype, array $oldRules, array $newRules): bool
151
    {
152 3
        if ($this->shouldPersist() && $this->adapter instanceof UpdatableAdapter) {
153
            try {
154 3
                $this->adapter->updatePolicies($sec, $ptype, $oldRules, $newRules);
155 3
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
156
            }
157
        }
158
159 3
        $ruleUpdated = $this->model->updatePolicies($sec, $ptype, $oldRules, $newRules);
160 3
        if (!$ruleUpdated) {
161 3
            return false;
162
        }
163
164 3
        if ($sec == "g") {
165
            // remove the old rule
166
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $oldRules);
167
168
            // add the new rule
169
            $this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $newRules);
170
        }
171
172 3
        return true;
173
    }
174
175
    /**
176
     * Removes a rule from the current policy without notify.
177
     * 
178
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
179
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
180
     * @param array $rule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
181
     * 
182
     * @return bool
183
     */
184 33
    protected function removePolicyWithoutNotifyInternal(string $sec, string $ptype, array $rule): bool
185
    {
186 33
        if ($this->shouldPersist()) {
187
            try {
188 33
                $this->adapter->removePolicy($sec, $ptype, $rule);
189 33
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
190
            }
191
        }
192
193 33
        $ruleRemoved = $this->model->removePolicy($sec, $ptype, $rule);
194 33
        if (!$ruleRemoved) {
195 3
            return false;
196
        }
197
198 33
        if ($sec == "g") {
199 18
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, [$rule]);
200
        }
201
202 33
        return true;
203
    }
204
205
    /**
206
     * Removes rules from the current policy without notify.
207
     * 
208
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
209
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
210
     * @param array $rules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
211
     * 
212
     * @return bool
213
     */
214 15
    protected function removePoliciesWithoutNotifyInternal(string $sec, string $ptype, array $rules): bool
215
    {
216 15
        if (!$this->model->hasPolicies($sec, $ptype, $rules)) {
217 6
            return false;
218
        }
219
220 15
        if ($this->shouldPersist() && $this->adapter instanceof BatchAdapter) {
221
            try {
222 15
                $this->adapter->removePolicies($sec, $ptype, $rules);
223 15
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
224
            }
225
        }
226
227 15
        $ruleRemoved = $this->model->removePolicies($sec, $ptype, $rules);
228 15
        if (!$ruleRemoved) {
229
            return false;
230
        }
231
232 15
        if ($sec == "g") {
233 12
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $rules);
234
        }
235
236 15
        return true;
237
    }
238
239
    /**
240
     * Removes rules based on field filters from the current policy without notify.
241
     * 
242
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
243
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
244
     * @param int $fieldIndex
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
245
     * @param string ...$fieldValues
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
246
     * 
247
     * @return bool
248
     */
249 24
    protected function removeFilteredPolicyWithoutNotifyInternal(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): bool
250
    {
251 24
        if ($this->shouldPersist()) {
252
            try {
253 24
                $this->adapter->removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues);
254 24
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
255
            }
256
        }
257
258 24
        $ruleRemoved = $this->model->removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues);
259 24
        if (!$ruleRemoved) {
0 ignored issues
show
introduced by
The condition $ruleRemoved is always false.
Loading history...
260
            return false;
261
        }
262
263 24
        if ($sec == "g") {
264 12
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $ruleRemoved);
265
        }
266
267 24
        return true;
268
    }
269
270
    /**
271
     * Updates rules based on field filters from the current policy without notify.
272
     * 
273
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
274
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
275
     * @param array $newRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
276
     * @param int $fieldIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
277
     * @param string ...$fieldValues
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
278
     * 
279
     * @return array
280
     */
281 6
    protected function updateFilteredPoliciesWithoutNotifyInternal(string $sec, string $ptype, array $newRules, int $fieldIndex, string ...$fieldValues): array
282
    {
283 6
        $oldRules = [];
284 6
        if ($this->shouldPersist()) {
285
            try {
286 6
                if ($this->adapter instanceof UpdatableAdapter) {
287 6
                    $oldRules = $this->adapter->updateFilteredPolicies($sec, $ptype, $newRules, $fieldIndex, ...$fieldValues);
288
                }
289 3
            } catch (NotImplementedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
290
            }
291
        }
292
293 6
        $ruleChanged = $this->model->removePolicies($sec, $ptype, $oldRules);
294 6
        $this->model->addPolicies($sec, $ptype, $newRules);
295
296 6
        $ruleChanged = $ruleChanged && count($newRules) !== 0;
297 6
        if (!$ruleChanged) {
298 3
            return [];
299
        }
300
301 6
        if ($sec == "g") {
302
            // remove the old rules
303
            $this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $oldRules);
304
            // add the new rules
305
            $this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $newRules);
306
        }
307
308 6
        return $oldRules;
309
    }
310
311
    /**
312
     * Adds a rule to the current policy.
313
     *
314
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
315
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
316
     * @param array $rule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
317
     *
318
     * @return bool
319
     */
320 48
    protected function addPolicyInternal(string $sec, string $ptype, array $rule): bool
321
    {
322 48
        if (!$this->addPolicyWithoutNotifyInternal($sec, $ptype, $rule)) {
323 3
            return false;
324
        }
325
326 48
        if ($this->shouldNotify()) {
327 3
            if ($this->watcher instanceof WatcherEx) {
328
                $this->watcher->updateForAddPolicy($sec, $ptype, ...$rule);
329
            } else {
330 3
                $this->watcher->update();
331
            }
332
        }
333
334 48
        return true;
335
    }
336
337
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $autoRemoveRepeat should have a doc-comment as per coding-style.
Loading history...
338
     * Adds rules to the current policy.
339
     *
340
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
341
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
342
     * @param array $rules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
343
     *
344
     * @return bool
345
     * @throws Exceptions\CasbinException
346
     */
347 24
    protected function addPoliciesInternal(string $sec, string $ptype, array $rules, bool $autoRemoveRepeat): bool
348
    {
349 24
        if (!$this->addPoliciesWithoutNotifyInternal($sec, $ptype, $rules, $autoRemoveRepeat)) {
350 9
            return false;
351
        }
352
353 24
        if ($this->shouldNotify()) {
354
            $this->watcher->update();
355
        }
356
357 24
        return true;
358
    }
359
360
    /**
361
     * Updates a rule from the current policy.
362
     * 
363
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
364
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
365
     * @param string[] $oldRule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
366
     * @param string[] $newRule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
367
     *
368
     * @return bool
369
     */
370 3
    protected function updatePolicyInternal(string $sec, string $ptype, array $oldRule, array $newRule): bool
371
    {
372 3
        if (!$this->updatePolicyWithoutNotifyInternal($sec, $ptype, $oldRule, $newRule)) {
373
            return false;
374
        }
375
376 3
        if ($this->shouldNotify()) {
377
            try {
378
                if ($this->watcher instanceof WatcherUpdatable) {
379
                    $this->watcher->updateForUpdatePolicy($oldRule, $newRule);
380
                } else {
381
                    $this->watcher->update();
382
                }
383
            } catch (\Exception $e) {
384
                Log::logPrint("An exception occurred:" . $e->getMessage());
385
                return false;
386
            }
387
        }
388
389 3
        return true;
390
    }
391
392
    /**
393
     * Updates rules from the current policy.
394
     * 
395
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
396
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
397
     * @param string[][] $oldRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
398
     * @param string[][] $newRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
399
     * 
400
     * @return bool
401
     */
402 3
    protected function updatePoliciesInternal(string $sec, string $ptype, array $oldRules, array $newRules): bool
403
    {
404 3
        if (!$this->updatePoliciesWithoutNotifyInternal($sec, $ptype, $oldRules, $newRules)) {
405 3
            return false;
406
        }
407
408 3
        if ($this->shouldNotify()) {
409
            try {
410 3
                if ($this->watcher instanceof WatcherUpdatable) {
411 3
                    $this->watcher->updateForUpdatePolicies($oldRules, $newRules);
412
                } else {
413 3
                    $this->watcher->update();
414
                }
415 3
            } catch (\Exception $e) {
416 3
                Log::logPrint("An exception occurred:" . $e->getMessage());
417 3
                return false;
418
            }
419
        }
420
421 3
        return true;
422
    }
423
424
    /**
425
     * Removes a rule from the current policy.
426
     *
427
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
428
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
429
     * @param array $rule
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
430
     *
431
     * @return bool
432
     */
433 33
    protected function removePolicyInternal(string $sec, string $ptype, array $rule): bool
434
    {
435 33
        if (!$this->removePolicyWithoutNotifyInternal($sec, $ptype, $rule)) {
436 3
            return false;
437
        }
438
439 33
        if ($this->shouldNotify()) {
440
            if ($this->watcher instanceof WatcherEx) {
441
                $this->watcher->updateForRemovePolicy($sec, $ptype, ...$rule);
442
            } else {
443
                $this->watcher->update();
444
            }
445
        }
446
447 33
        return true;
448
    }
449
450
    /**
451
     * Removes a rules from the current policy.
452
     *
453
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
454
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
455
     * @param array $rules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
456
     *
457
     * @return bool
458
     */
459 15
    protected function removePoliciesInternal(string $sec, string $ptype, array $rules): bool
460
    {
461 15
        if (!$this->removePoliciesWithoutNotifyInternal($sec, $ptype, $rules)) {
462 6
            return false;
463
        }
464
465 15
        if ($this->shouldNotify()) {
466
            // error intentionally ignored
467
            $this->watcher->update();
468
        }
469
470 15
        return true;
471
    }
472
473
    /**
474
     * Removes rules based on field filters from the current policy.
475
     *
476
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
477
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
478
     * @param int $fieldIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
479
     * @param string ...$fieldValues
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
480
     *
481
     * @return bool
482
     */
483 24
    protected function removeFilteredPolicyInternal(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): bool
484
    {
485 24
        if (!$this->removeFilteredPolicyWithoutNotifyInternal($sec, $ptype, $fieldIndex, ...$fieldValues)) {
486
            return false;
487
        }
488
489 24
        if ($this->shouldNotify()) {
490
            // error intentionally ignored
491
            if ($this->watcher instanceof WatcherEx) {
492
                $this->watcher->updateForRemoveFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues);
493
            } else {
494
                $this->watcher->update();
495
            }
496
        }
497
498 24
        return true;
499
    }
500
501
    /**
502
     * Removes rules based on field filters from the current policy.
503
     * 
504
     * @param string $sec
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
505
     * @param string $ptype
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
506
     * @param array $newRules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
507
     * @param int $fieldIndex
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
508
     * @param string ...$fieldValues
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
509
     * 
510
     * @return bool
511
     */
512 6
    protected function updateFilteredPoliciesInternal(string $sec, string $ptype, array $newRules, int $fieldIndex, string ...$fieldValues): bool
513
    {
514 6
        $oldRules = $this->updateFilteredPoliciesWithoutNotifyInternal($sec, $ptype, $newRules, $fieldIndex, ...$fieldValues);
515 6
        if(count($oldRules) === 0) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
516 3
            return false;
517
        }
518
519 6
        if ($this->shouldNotify()) {
520
            // error intentionally ignored
521 3
            if ($this->watcher instanceof WatcherUpdatable) {
522 3
                $this->watcher->updateForUpdatePolicies($oldRules, $newRules);
523
            } else {
524 3
                $this->watcher->update();
525
            }
526 3
            return true;
527
        }
528
529 3
        return true;
530
    }
531
}
532