Passed
Branchfeature/useWidgetsNamespaces (eb4650)
by Robin
02:57
created

AppRecordSet::trimSetName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
// -------------------------------------------------------------------------
4
// OVIDENTIA http://www.ovidentia.org
5
// Ovidentia is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2, or (at your option)
8
// any later version.
9
//
10
// This program is distributed in the hope that it will be useful, but
11
// WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18
// USA.
19
// -------------------------------------------------------------------------
20
/**
21
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
22
 * @copyright Copyright (c) 2022 by SI4YOU ({@link https://www.siforyou.com})
23
 */
24
namespace Capwelton\LibApp\Set;
25
26
use Capwelton\LibApp\AppObjectInterface;
27
use Capwelton\LibApp\Func_App;
28
use Capwelton\LibApp\AppAccessManager;
29
use Capwelton\LibApp\Exceptions\AppNotFoundException;
30
use Capwelton\LibApp\Exceptions\AppDeletedRecordException;
31
use Capwelton\LibOrm\ORMRecordSet;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\ORMRecordSet was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Capwelton\LibOrm\Field\ORMFkField;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\Field\ORMFkField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Capwelton\LibOrm\Exceptions\ORMBackEndSelectException;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\Excepti...MBackEndSelectException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Capwelton\LibOrm\Exceptions\ORMException;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\Exceptions\ORMException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use Capwelton\LibOrm\Criteria\ORMCriteria;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\Criteria\ORMCriteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use Capwelton\LibOrm\ORMIterator;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\ORMIterator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Capwelton\LibOrm\Criteria\ORMCriterion;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\Criteria\ORMCriterion was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use Capwelton\LibOrm\MySql\ORMMySqlRecordSet;
0 ignored issues
show
Bug introduced by
The type Capwelton\LibOrm\MySql\ORMMySqlRecordSet was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
40
/**
41
 * @property ORMPkField $id
42
 *
43
 * @method AppRecord get(mixed $criteria)
44
 * @method AppRecord request(mixed $criteria)
45
 * @method AppRecord[]|ORMMySqlRecordSet select(ORMCriteria $criteria = null)
46
 * @method AppRecord newRecord()
47
 */
48
class AppRecordSet extends ORMRecordSet implements AppObjectInterface
49
{
50
    
51
    /**
52
     * @var Func_App
53
     */
54
    protected $app = null;
55
    
56
    protected $accessRights = null;
57
    
58
    /**
59
     * @var AppAccessManager
60
     */
61
    private $accessManager = null;
62
    
63
    /**
64
     * @var array
65
     */
66
    private $customFields = null;
67
    
68
    /**
69
     * @param Func_App $app
70
     */
71
    public function __construct(Func_App $app)
72
    {
73
        parent::__construct();
74
        $this->setApp($app);
75
        $this->accessRights = array();
76
        
77
        $this->setAccessManager($app->AccessManager());
78
        $this->setPrimaryKey('id');
79
    }
80
    
81
    /**
82
     * {@inheritdoc}
83
     * @see AppObjectInterface::setApp()
84
     */
85
    public function setApp(Func_App $app)
86
    {
87
        $this->app = $app;
88
        return $this;
89
    }
90
    
91
    /**
92
     * {@inheritdoc}
93
     * @see AppObjectInterface::App()
94
     */
95
    public function App()
96
    {
97
        return $this->app;
98
    }
99
    
100
    /**
101
     * @param string $setName
102
     */
103
    protected function trimSetName($setName)
104
    {
105
        if(strpos($setName, '_') === false){
106
            return $setName;
107
        }
108
        $pos = strrpos($setName, '\\');
109
        if($pos === false){
110
            return explode('_', $setName)[1];
111
        }
112
        return substr($setName, $pos + 1);
113
    }
114
    
115
    /**
116
     * Similar to the ORMRecordSet::join() method but instanciates the
117
     * joined RecordSet using App methods.
118
     *
119
     * @see ORMRecordSet::join()
120
     */
121
    public function join($fkFieldName)
122
    {
123
        $fkField = $this->getField($fkFieldName);
124
        if(! ($fkField instanceof ORMFkField)){
125
            return $this;
126
        }
127
        $setName = $fkField->getForeignSetName();
128
        
129
        if(! $setName || 'Set' === $setName){
130
            throw new \Exception('The set name is missing on foreign key field ' . $fkFieldName);
131
        }
132
        
133
        $appSetName = $this->trimSetName($setName);
134
        $set = $this->App()->$appSetName();
135
        $set->setName($fkField->getName());
136
        $set->setDescription($fkField->getDescription());
137
        
138
        $this->aField[$fkFieldName] = $set;
0 ignored issues
show
Bug Best Practice introduced by
The property aField does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
139
        $set->setParentSet($this);
140
        return $this;
141
    }
142
    
143
    // /**
144
    // *
145
    // * @param string $accessName
146
    // * @param string $type
147
    // */
148
    // public function addAccessRight($accessName, $type = 'acl')
149
    // {
150
    // $this->accessRights[$accessName] = $type;
151
    // }
152
    
153
    // /**
154
    // * @return array
155
    // */
156
    // public function getAccessRights()
157
    // {
158
    // return $this->accessRights;
159
    // }
160
    
161
    /**
162
     * @return AppCustomField[]
163
     */
164
    public function getCustomFields()
165
    {
166
        $App = $this->App();
167
        
168
        if(null === $this->customFields){
169
            $this->customFields = array();
170
            
171
            if(isset($App->CustomField)){
0 ignored issues
show
Bug Best Practice introduced by
The property CustomField does not exist on Capwelton\LibApp\Func_App. Since you implemented __get, consider adding a @property annotation.
Loading history...
172
                $customFieldSet = $App->CustomFieldSet();
173
                $object = mb_substr(get_class($this), mb_strlen($App->classPrefix), - mb_strlen('Set'));
174
                try{
175
                    $customFields = $customFieldSet->select($customFieldSet->object->is($object));
176
                    
177
                    foreach ($customFields as $customfield){
178
                        $this->customFields[] = $customfield;
179
                        
180
                        /*@var $customfield AppCustomField */
181
                    }
182
                }
183
                catch (ORMBackEndSelectException $e){
184
                    // table does not exist, this error is thrown by the install program while creating the sets
185
                }
186
            }
187
        }
188
        
189
        return $this->customFields;
190
    }
191
    
192
    /**
193
     * @return AppCustomField[]
194
     */
195
    public function selectCustomFields()
196
    {
197
        $App = $this->App();
198
        
199
        $customFieldSet = $App->CustomFieldSet();
200
        $object = mb_substr(get_class($this), mb_strlen($App->classPrefix), - mb_strlen('Set'));
201
        
202
        $customFields = $customFieldSet->select($customFieldSet->object->is($object));
203
        
204
        return $customFields;
205
    }
206
    
207
    /**
208
     * @return self
209
     */
210
    public function addCustomFields()
211
    {
212
        $customFields = $this->selectCustomFields();
213
        foreach ($customFields as $customField){
214
            /*@var $customField AppCustomField */
215
            $description = $customField->name;
216
            $ormField = $customField->getORMField()->setDescription($description);
217
            if($ormField instanceof ORMFkField){
218
                $this->hasOne($customField->fieldname, $ormField->getForeignSetName())
219
                    ->setDescription($description);
220
            }
221
            else{
222
                $this->addFields($ormField);
223
            }
224
        }
225
        
226
        return $this;
227
    }
228
    
229
    /**
230
     * Similar to ORMRecordSet::get() method but throws a AppNotFoundException if the
231
     * record is not found.
232
     *
233
     * @since 1.0.18
234
     * @throws ORMException::
235
     * @throws AppNotFoundException
236
     *
237
     * @param ORMCriteria|string $mixedParam
238
     *            Criteria for selecting records
239
     *            or the value for selecting record
240
     * @param string $sPropertyName
241
     *            The name of the property on which
242
     *            the value applies. If not
243
     *            specified or null, the set's
244
     *            primary key will be used.
245
     * @return AppRecord
246
     */
247
    public function request($mixedParam = null, $sPropertyName = null)
248
    {
249
        $record = $this->get($mixedParam, $sPropertyName);
0 ignored issues
show
Unused Code introduced by
The call to Capwelton\LibApp\Set\AppRecordSet::get() has too many arguments starting with $sPropertyName. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

249
        /** @scrutinizer ignore-call */ 
250
        $record = $this->get($mixedParam, $sPropertyName);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
250
        if(! isset($record)){
251
            // This will remove the default criteria for TraceableRecords and
252
            // fetch even 'deleted' ones.
253
            $this->setDefaultCriteria(null);
254
            $record = $this->get($mixedParam, $sPropertyName);
255
            if(isset($record)){
256
                throw new AppDeletedRecordException($record, $mixedParam);
0 ignored issues
show
Unused Code introduced by
The call to Capwelton\LibApp\Excepti...xception::__construct() has too many arguments starting with $mixedParam. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

256
                throw /** @scrutinizer ignore-call */ new AppDeletedRecordException($record, $mixedParam);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
257
            }
258
            throw new AppNotFoundException($this, $mixedParam);
259
        }
260
        return $record;
261
    }
262
    
263
    /**
264
     * Returns an iterator of traceableRecord linked to the specified source,
265
     * optionally filtered on the specified link type.
266
     *
267
     * @param
268
     *            AppRecord | array $source source can be an array of record
269
     * @param string $linkType
270
     *
271
     * @return ORMIterator
272
     */
273
    public function selectLinkedTo($source, $linkType = null)
274
    {
275
        $linkSet = $this->App()->LinkSet();
276
        if(is_array($source) || ($source instanceof \Iterator)){
277
            return $linkSet->selectForSources($source, $this->getRecordClassName(), $linkType);
278
        }
279
        else{
280
            return $linkSet->selectForSource($source, $this->getRecordClassName(), $linkType);
281
        }
282
    }
283
    
284
    /**
285
     * Returns an iterator of traceableRecord linked to the specified target,
286
     * optionally filtered on the specified link type.
287
     *
288
     * @param
289
     *            AppRecord | array $target target can be an array of record
290
     * @param string $linkType
291
     *
292
     * @return ORMIterator
293
     */
294
    public function selectLinkedFrom($target, $linkType = null)
295
    {
296
        $linkSet = $this->App()->LinkSet();
297
        if(is_array($target) || ($target instanceof \Iterator)){
298
            return $linkSet->selectForTargets($target, $this->getRecordClassName(), $linkType);
299
        }
300
        else{
301
            return $linkSet->selectForTarget($target, $this->getRecordClassName(), $linkType);
302
        }
303
    }
304
    
305
    /**
306
     * Returns a criteria usable to select records of this set which are source of app_Links to the specified AppRecord.
307
     *
308
     * @param AppRecord $target
309
     * @param string $linkType
310
     * @return ORMCriteria
311
     */
312
    public function isSourceOf(AppRecord $target, $linkType = null)
313
    {
314
        $App = $this->App();
315
        $linkSet = $App->LinkSet();
316
        
317
        $recordClassName = $this->getRecordClassName();
318
        $linkSet->hasOne('sourceId', $recordClassName);
319
        
320
        $criteria = $linkSet->targetClass->is($target->getClassName())
321
            ->_AND_($linkSet->targetId->is($target->id))
322
            ->_AND_($linkSet->sourceClass->is($this->newRecord()
323
            ->getClassName()));
324
        if(isset($linkType)){
325
            if(is_array($linkType)){
0 ignored issues
show
introduced by
The condition is_array($linkType) is always false.
Loading history...
326
                $criteria = $criteria->_AND_($linkSet->type->in($linkType));
327
            }
328
            else{
329
                $criteria = $criteria->_AND_($linkSet->type->is($linkType));
330
            }
331
        }
332
        $criteria = $this->id->in($criteria);
333
        
334
        return $criteria;
335
    }
336
    
337
    /**
338
     * Returns a criteria usable to select records of this set which are target of app_Links to the specified AppRecord.
339
     *
340
     * @param AppRecord $source
341
     * @param null|string|string[] $linkType
342
     * @return ORMCriteria
343
     */
344
    public function isTargetOf(AppRecord $source, $linkType = null)
345
    {
346
        $App = $this->App();
347
        $linkSet = $App->LinkSet();
348
        
349
        $recordClassName = $this->getRecordClassName();
350
        $linkSet->hasOne('targetId', $recordClassName);
351
        
352
        $criteria = $linkSet->sourceClass->is($source->getClassName())
353
            ->_AND_($linkSet->sourceId->is($source->id))
354
            ->_AND_($linkSet->targetClass->is($this->newRecord()
355
            ->getClassName()));
356
        if(isset($linkType)){
357
            if(is_array($linkType)){
358
                $criteria = $criteria->_AND_($linkSet->type->in($linkType));
359
            }
360
            else{
361
                $criteria = $criteria->_AND_($linkSet->type->is($linkType));
362
            }
363
        }
364
        $criteria = $this->id->in($criteria);
365
        
366
        return $criteria;
367
    }
368
    
369
    /**
370
     * Returns a criteria usable to select records of this set which are target of app_Links from the specified AppRecords.
371
     *
372
     * @since 1.0.23
373
     * @param AppRecord[] $sources
374
     * @param null|string|string[] $linkType
375
     * @return ORMCriteria
376
     */
377
    public function isTargetOfAny($sources, $linkType = null)
378
    {
379
        $App = $this->App();
380
        $linkSet = $App->LinkSet();
381
        $recordClassName = $linkSet->getRecordClassName();
382
        $linkSet->hasOne('targetId', $recordClassName);
383
        
384
        $sourceIdsByClasses = array();
385
        foreach ($sources as $source){
386
            $sourceClass = $source->getClassName();
387
            if(! isset($sourceIdsByClasses[$sourceClass])){
388
                $sourceIdsByClasses[$sourceClass] = array();
389
            }
390
            $sourceIdsByClasses[$sourceClass][] = $source->id;
391
        }
392
        
393
        $sourcesCriteria = array();
394
        foreach ($sourceIdsByClasses as $sourceClass => $sourceIds){
395
            $sourcesCriteria[] = $linkSet->sourceClass->is($sourceClass)->_AND_($linkSet->sourceId->in($sourceIds));
396
        }
397
        
398
        $criteria = $linkSet->all($linkSet->targetClass->is($this->newRecord()
399
            ->getClassName()), $linkSet->any($sourcesCriteria));
400
        if(isset($linkType)){
401
            if(is_array($linkType)){
402
                $criteria = $criteria->_AND_($linkSet->type->in($linkType));
403
            }
404
            else{
405
                $criteria = $criteria->_AND_($linkSet->type->is($linkType));
406
            }
407
        }
408
        $criteria = $this->id->in($criteria);
409
        
410
        return $criteria;
411
    }
412
    
413
    /**
414
     * Returns a criteria usable to select records of this set which are source of app_Links to the specified AppRecords.
415
     *
416
     * @since 1.0.23
417
     * @param AppRecord[] $targets
418
     * @param string|null $linkType
419
     * @return ORMCriteria
420
     */
421
    public function isSourceOfAny($targets, $linkType = null)
422
    {
423
        $App = $this->App();
424
        $linkSet = $App->LinkSet();
425
        $recordClassName = $this->getRecordClassName();
426
        $linkSet->hasOne('sourceId', $recordClassName);
427
        
428
        $targetIdsByClasses = array();
429
        foreach ($targets as $target){
430
            $targetClass = $target->getClassName();
431
            if(! isset($targetIdsByClasses[$targetClass])){
432
                $targetIdsByClasses[$targetClass] = array();
433
            }
434
            $targetIdsByClasses[$targetClass][] = $target->id;
435
        }
436
        
437
        $targetsCriteria = array();
438
        foreach ($targetIdsByClasses as $targetClass => $targetIds){
439
            $targetsCriteria[] = $linkSet->targetClass->is($targetClass)->_AND_($linkSet->targetId->in($targetIds));
440
        }
441
        
442
        $criteria = $linkSet->all($linkSet->sourceClass->is($this->newRecord()
443
            ->getClassName()), $linkSet->any($targetsCriteria));
444
        if(isset($linkType)){
445
            if(is_array($linkType)){
0 ignored issues
show
introduced by
The condition is_array($linkType) is always false.
Loading history...
446
                $criteria = $criteria->_AND_($linkSet->type->in($linkType));
447
            }
448
            else{
449
                $criteria = $criteria->_AND_($linkSet->type->is($linkType));
450
            }
451
        }
452
        $criteria = $this->id->in($criteria);
453
        
454
        return $criteria;
455
    }
456
    
457
    /**
458
     * @param AppAccessManager $accessManager
459
     * @return self
460
     */
461
    public function setAccessManager(AppAccessManager $accessManager)
462
    {
463
        $this->accessManager = $accessManager;
464
        return $this;
465
    }
466
    
467
    /**
468
     * @return AppAccessManager
469
     */
470
    public function getAccessManager()
471
    {
472
        return $this->accessManager;
473
    }
474
    
475
    /**
476
     * Defines if records can be created by the current user.
477
     *
478
     * @return boolean
479
     */
480
    public function isCreatable()
481
    {
482
        return false;
483
    }
484
    
485
    /**
486
     * @return ORMCriteria
487
     */
488
    public function isReadable()
489
    {
490
        return $this->hasAccess('read');
491
    }
492
    
493
    /**
494
     * @return ORMCriteria
495
     */
496
    public function isUpdatable()
497
    {
498
        return $this->hasAccess('update');
499
    }
500
    
501
    /**
502
     * @return ORMCriteria
503
     */
504
    public function isDeletable()
505
    {
506
        return $this->hasAccess('delete');
507
    }
508
    
509
    /**
510
     * Returns a criterion matching records that can be put to trash by the current user.
511
     *
512
     * @return ORMCriterion
513
     */
514
    public function isRemovable()
515
    {
516
        return $this->isUpdatable();
517
    }
518
    
519
    /**
520
     * Returns a criterion matching records that can be restored from the trash by the current user.
521
     *
522
     * @return ORMCriterion
523
     */
524
    public function isRestorable()
525
    {
526
        return $this->isUpdatable();
527
    }
528
    
529
    /**
530
     * Returns a criterion matching records deletable by the current user.
531
     *
532
     * @param string $accessType
533
     * @param int|null $user
534
     *
535
     * @return ORMCriterion
536
     */
537
    public function hasAccess($accessType, $user = null)
538
    {
539
        $accessManager = $this->getAccessManager();
540
        return $accessManager->getAccessCriterion($this, $accessType, $user);
541
    }
542
    
543
    /**
544
     * Returns a criteria usable to select records of this set associated to the specified tags.
545
     *
546
     * @array	$tags		An array of tag ids
547
     * @string	$type		The link type [optional]
548
     * @return ORMCriteria
549
     */
550
    public function haveTagLabels($tagLabels, $linkType = null)
551
    {
552
        $App = $this->App();
553
        $linkSet = $App->LinkSet();
554
        
555
        /* @var $tagSet AppRecordSet */
556
        $tagSet = $App->TagSet();
0 ignored issues
show
Bug introduced by
The method TagSet() does not exist on Capwelton\LibApp\Func_App. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

556
        /** @scrutinizer ignore-call */ 
557
        $tagSet = $App->TagSet();
Loading history...
557
        $tagClassName = $tagSet->getRecordClassName();
558
        
559
        $linkSet->joinTarget($tagClassName);
560
        $criteria = $linkSet->sourceClass->is($this->getRecordClassName())
561
            ->_AND_($linkSet->targetClass->is($tagClassName));
562
        
563
        if(is_array($tagLabels)){
564
            $criteria = $criteria->_AND_($linkSet->targetId->label->in($tagLabels));
565
        }
566
        else{
567
            $criteria = $criteria->_AND_($linkSet->targetId->label->is($tagLabels));
568
        }
569
        if(isset($linkType)){
570
            $criteria = $criteria->_AND_($linkSet->type->is($linkType));
571
        }
572
        $links = $linkSet->select($criteria);
0 ignored issues
show
Unused Code introduced by
The call to Capwelton\LibApp\Set\AppLinkSet::select() has too many arguments starting with $criteria. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

572
        /** @scrutinizer ignore-call */ 
573
        $links = $linkSet->select($criteria);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
573
        
574
        $ids = array();
575
        foreach ($links as $link){
576
            $ids[$link->sourceId] = $link->sourceId;
577
        }
578
        
579
        return $this->id->in($ids);
580
    }
581
    
582
    public function getVisibilityCriteriaFields()
583
    {
584
        $fields = $this->getFields();
585
        $manyRelations = $this->getHasManyRelations();
586
        foreach ($manyRelations as $fieldName => $manyRelation){
587
            $fields[$fieldName] = $manyRelation;
588
        }
589
        return $fields;
590
    }
591
}