Completed
Push — feature/EVO-5751-text-search-j... ( 24ba67...00ee94 )
by
unknown
11:26
created

DocumentModel   D

Complexity

Total Complexity 51

Size/Duplication

Total Lines 501
Duplicated Lines 2.79 %

Coupling/Cohesion

Components 2
Dependencies 19

Test Coverage

Coverage 34.97%

Importance

Changes 16
Bugs 3 Features 0
Metric Value
wmc 51
c 16
b 3
f 0
lcom 2
cbo 19
dl 14
loc 501
ccs 64
cts 183
cp 0.3497
rs 4.1704

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getRepository() 0 4 1
A setRepository() 0 7 1
D findAll() 14 100 17
A hasCustomSearchIndex() 0 11 3
A getMongoDBVersion() 0 11 2
A insertRecord() 0 12 3
A find() 0 4 1
A updateRecord() 0 22 3
A deleteRecord() 0 18 3
A flush() 0 4 1
A deleteById() 0 9 1
A recordExists() 0 4 1
A selectSingleFields() 0 14 1
A getEntityClass() 0 8 2
A getConnectionName() 0 6 1
A doRqlQuery() 0 6 1
A checkIfOriginRecord() 0 15 4
A getDefaultLimit() 0 8 2
A setFilterByAuthUser() 0 5 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like DocumentModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DocumentModel, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Use doctrine odm as backend
4
 */
5
6
namespace Graviton\RestBundle\Model;
7
8
use Doctrine\ODM\MongoDB\DocumentManager;
9
use Doctrine\ODM\MongoDB\DocumentRepository;
10
use Graviton\RestBundle\Service\RqlTranslator;
11
use Graviton\Rql\Node\SearchNode;
12
use Graviton\SchemaBundle\Model\SchemaModel;
13
use Graviton\SecurityBundle\Entities\SecurityUser;
14
use Symfony\Bridge\Monolog\Logger;
15
use Symfony\Component\HttpFoundation\Request;
16
use Doctrine\ODM\MongoDB\Query\Builder;
17
use Graviton\Rql\Visitor\MongoOdm as Visitor;
18
use Xiag\Rql\Parser\AbstractNode;
19
use Xiag\Rql\Parser\Node\LimitNode;
20
use Xiag\Rql\Parser\Node\Query\AbstractLogicOperatorNode;
21
use Xiag\Rql\Parser\Query;
22
use Graviton\ExceptionBundle\Exception\RecordOriginModifiedException;
23
use Xiag\Rql\Parser\Exception\SyntaxErrorException as RqlSyntaxErrorException;
24
use Graviton\SchemaBundle\Document\Schema as SchemaDocument;
25
use Xiag\Rql\Parser\Query as XiagQuery;
26
27
/**
28
 * Use doctrine odm as backend
29
 *
30
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
31
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
32
 * @link    http://swisscom.ch
33
 */
34
class DocumentModel extends SchemaModel implements ModelInterface
35
{
36
    /**
37
     * @var string
38
     */
39
    protected $description;
40
    /**
41
     * @var string[]
42
     */
43
    protected $fieldTitles;
44
    /**
45
     * @var string[]
46
     */
47
    protected $fieldDescriptions;
48
    /**
49
     * @var string[]
50
     */
51
    protected $requiredFields = array();
52
    /**
53
     * @var string[]
54
     */
55
    protected $searchableFields = array();
56
    /**
57
     * @var DocumentRepository
58
     */
59
    private $repository;
60
    /**
61
     * @var Visitor
62
     */
63
    private $visitor;
64
    /**
65
     * @var array
66
     */
67
    protected $notModifiableOriginRecords;
68
    /**
69
     * @var  integer
70
     */
71
    private $paginationDefaultLimit;
72
73
    /**
74
     * @var boolean
75
     */
76
    protected $filterByAuthUser;
77
78
    /**
79
     * @var string
80
     */
81
    protected $filterByAuthField;
82
83
    /**
84
     * @var RqlTranslator
85
     */
86
    protected $translator;
87
88
    /**
89
     * @var DocumentManager
90
     */
91
    protected $manager;
92
93
    /**
94
     * @param Visitor       $visitor                    rql query visitor
95
     * @param RqlTranslator $translator                 Translator for query modification
96
     * @param array         $notModifiableOriginRecords strings with not modifiable recordOrigin values
97
     * @param integer       $paginationDefaultLimit     amount of data records to be returned when in pagination context
98
     */
99 4
    public function __construct(
100
        Visitor $visitor,
101
        RqlTranslator $translator,
102
        $notModifiableOriginRecords,
103
        $paginationDefaultLimit
104
    ) {
105 4
        parent::__construct();
106 4
        $this->visitor = $visitor;
107 4
        $this->translator = $translator;
108 4
        $this->notModifiableOriginRecords = $notModifiableOriginRecords;
109 4
        $this->paginationDefaultLimit = (int) $paginationDefaultLimit;
110 4
    }
111
112
    /**
113
     * get repository instance
114
     *
115
     * @return DocumentRepository
116
     */
117 2
    public function getRepository()
118
    {
119 2
        return $this->repository;
120
    }
121
122
    /**
123
     * create new app model
124
     *
125
     * @param DocumentRepository $repository Repository of countries
126
     *
127
     * @return \Graviton\RestBundle\Model\DocumentModel
128
     */
129 4
    public function setRepository(DocumentRepository $repository)
130
    {
131 4
        $this->repository = $repository;
132 4
        $this->manager = $repository->getDocumentManager();
133
134 4
        return $this;
135
    }
136
137
    /**
138
     * {@inheritDoc}
139
     *
140
     * @param Request        $request The request object
141
     * @param SecurityUser   $user    SecurityUser Object
0 ignored issues
show
Documentation introduced by
Should the type for parameter $user not be null|SecurityUser?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
142
     * @param SchemaDocument $schema  Schema model used for search fields extraction
0 ignored issues
show
Documentation introduced by
Should the type for parameter $schema not be null|SchemaDocument?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
143
     *
144
     * @return array
145
     */
146
    public function findAll(Request $request, SecurityUser $user = null, SchemaDocument $schema = null)
147
    {
148
        $pageNumber = $request->query->get('page', 1);
149
        $numberPerPage = (int) $request->query->get('perPage', $this->getDefaultLimit());
150
        $startAt = ($pageNumber - 1) * $numberPerPage;
151
        // Only 1 search text node allowed.
152
        $hasSearch = false;
153
        /** @var XiagQuery $queryParams */
154
        $xiagQuery = $request->attributes->get('rqlQuery');
155
156
        /** @var \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder */
157
        $queryBuilder = $this->repository
158
            ->createQueryBuilder();
159
160
        // *** do we have an RQL expression, do we need to filter data?
161
        if ($request->attributes->get('hasRql', false)) {
162
            $innerQuery = $request->attributes->get('rqlQuery')->getQuery();
163
            $queryBuilder = $this->doRqlQuery(
164
                $queryBuilder,
165
                $this->translator->translateSearchQuery($xiagQuery, ['_grv_id'])
166
            );
167
            if ($this->hasCustomSearchIndex()) {
168
                if ($innerQuery instanceof AbstractLogicOperatorNode) {
169
                    foreach ($innerQuery->getQueries() as $innerRql) {
170 View Code Duplication
                        if (!$hasSearch && $innerRql instanceof SearchNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
                            $searchString = implode(' ', $innerRql->getSearchTerms());
172
                            $queryBuilder->addAnd(
173
                                $queryBuilder->expr()->text($searchString)
0 ignored issues
show
Bug introduced by
The method expr does only exist in Doctrine\ODM\MongoDB\Query\Builder, but not in Doctrine\ODM\MongoDB\Query\Expr.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
174
                            );
175
                            $hasSearch = true;
176
                        }
177
                    }
178 View Code Duplication
                } elseif ($innerQuery instanceof SearchNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
                    $searchString = implode(' ', $innerQuery->getSearchTerms());
180
                    $queryBuilder->addAnd(
181
                        $queryBuilder->expr()->text($searchString)
182
                    );
183
                    $hasSearch = true;
184
                }
185
            }
186
        } else {
187
            // @todo [lapistano]: seems the offset is missing for this query.
188
            /** @var \Doctrine\ODM\MongoDB\Query\Builder $qb */
189
            $queryBuilder->find($this->repository->getDocumentName());
190
        }
191
192
        /** @var LimitNode $rqlLimit */
193
        $rqlLimit = $xiagQuery->getLimit();
194
        
195
        // define offset and limit
196
        if (!$rqlLimit || !$rqlLimit->getOffset()) {
197
            $queryBuilder->skip($startAt);
0 ignored issues
show
Bug introduced by
The method skip does only exist in Doctrine\ODM\MongoDB\Query\Builder, but not in Doctrine\ODM\MongoDB\Query\Expr.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
198
        } else {
199
            $startAt = (int) $queryParams->getLimit()->getOffset();
200
            $queryBuilder->skip($startAt);
201
        }
202
203
        if (!$rqlLimit || is_null($rqlLimit->getLimit())) {
204
            $queryBuilder->limit($numberPerPage);
0 ignored issues
show
Bug introduced by
The method limit does only exist in Doctrine\ODM\MongoDB\Query\Builder, but not in Doctrine\ODM\MongoDB\Query\Expr.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
205
        } else {
206
            $numberPerPage = (int) $queryParams->getLimit()->getLimit();
207
            $queryBuilder->limit($numberPerPage);
208
        }
209
210
        // Limit can not be negative nor null.
211
        if ($numberPerPage < 1) {
212
            throw new RqlSyntaxErrorException('negative or null limit in rql');
213
        }
214
215
        /**
216
         * add a default sort on id if none was specified earlier
217
         *
218
         * not specifying something to sort on leads to very weird cases when fetching references
219
         * If search node, sort by Score
220
         * TODO Review this sorting, not 100% sure
221
         */
222
        if ($hasSearch && !array_key_exists('sort', $queryBuilder->getQuery()->getQuery())) {
223
            $queryBuilder->sortMeta('score', 'textScore');
0 ignored issues
show
Bug introduced by
The method sortMeta does only exist in Doctrine\ODM\MongoDB\Query\Builder, but not in Doctrine\ODM\MongoDB\Query\Expr.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
224
        } elseif (!array_key_exists('sort', $queryBuilder->getQuery()->getQuery())) {
225
            $queryBuilder->sort('_id');
226
        }
227
228
        // run query
229
        $query = $queryBuilder->getQuery();
230
        $records = array_values($query->execute()->toArray());
231
232
        $totalCount = $query->count();
233
        $numPages = (int) ceil($totalCount / $numberPerPage);
234
        $page = (int) ceil($startAt / $numberPerPage) + 1;
235
        if ($numPages > 1) {
236
            $request->attributes->set('paging', true);
237
            $request->attributes->set('page', $page);
238
            $request->attributes->set('numPages', $numPages);
239
            $request->attributes->set('startAt', $startAt);
240
            $request->attributes->set('perPage', $numberPerPage);
241
            $request->attributes->set('totalCount', $totalCount);
242
        }
243
244
        return $records;
245
    }
246
247
    /**
248
     * @param string $prefix the prefix for custom text search indexes
249
     * @return bool
250
     * @throws \Doctrine\ODM\MongoDB\MongoDBException
251
     */
252
    private function hasCustomSearchIndex($prefix = 'search')
253
    {
254
        $collection = $this->repository->getDocumentManager()->getDocumentCollection($this->repository->getClassName());
255
        $indexesInfo = $collection->getIndexInfo();
256
        foreach ($indexesInfo as $indexInfo) {
257
            if ($indexInfo['name']==$prefix.$collection->getName().'Index') {
258
                return true;
259
            }
260
        }
261
        return false;
262
    }
263
264
    /**
265
     * @return string the version of the MongoDB as a string
266
     */
267
    private function getMongoDBVersion()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
268
    {
269
        $buildInfo = $this->repository->getDocumentManager()->getDocumentDatabase(
270
            $this->repository->getClassName()
271
        )->command(['buildinfo'=>1]);
272
        if (isset($buildInfo['version'])) {
273
            return $buildInfo['version'];
274
        } else {
275
            return "unkown";
276
        }
277
    }
278
279
    /**
280
     * @param object $entity       entity to insert
281
     * @param bool   $returnEntity true to return entity
282
     * @param bool   $doFlush      if we should flush or not after insert
283
     *
284
     * @return Object|null
285
     */
286
    public function insertRecord($entity, $returnEntity = true, $doFlush = true)
287
    {
288
        $this->checkIfOriginRecord($entity);
289
        $this->manager->persist($entity);
290
291
        if ($doFlush) {
292
            $this->manager->flush($entity);
293
        }
294
        if ($returnEntity) {
295
            return $this->find($entity->getId());
296
        }
297
    }
298
299
    /**
300
     * @param string $documentId id of entity to find
301
     *
302
     * @return Object
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
303
     */
304 4
    public function find($documentId)
305
    {
306 4
        return $this->repository->find($documentId);
307
    }
308
309
    /**
310
     * {@inheritDoc}
311
     *
312
     * @param string $documentId   id of entity to update
313
     * @param Object $entity       new entity
314
     * @param bool   $returnEntity true to return entity
315
     *
316
     * @return Object|null
317
     */
318 2
    public function updateRecord($documentId, $entity, $returnEntity = true)
319
    {
320
        // In both cases the document attribute named originRecord must not be 'core'
321 2
        $this->checkIfOriginRecord($entity);
322 2
        $this->checkIfOriginRecord($this->selectSingleFields($documentId, ['recordOrigin']));
0 ignored issues
show
Bug introduced by
It seems like $this->selectSingleField... array('recordOrigin')) targeting Graviton\RestBundle\Mode...l::selectSingleFields() can also be of type array or null; however, Graviton\RestBundle\Mode...::checkIfOriginRecord() does only seem to accept object, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
323
324 2
        if (!is_null($documentId)) {
325 2
            $this->deleteById($documentId);
326
            // detach so odm knows it's gone
327 2
            $this->manager->detach($entity);
328 2
            $this->manager->clear();
329 1
        }
330
331 2
        $entity = $this->manager->merge($entity);
332
333 2
        $this->manager->persist($entity);
334 2
        $this->manager->flush($entity);
335
336 2
        if ($returnEntity) {
337
            return $entity;
338
        }
339 2
    }
340
341
    /**
342
     * {@inheritDoc}
343
     *
344
     * @param string|object $id id of entity to delete or entity instance
345
     *
346
     * @return null|Object
347
     */
348
    public function deleteRecord($id)
349
    {
350
        if (is_object($id)) {
351
            $entity = $id;
352
        } else {
353
            $entity = $this->find($id);
354
        }
355
356
        $return = $entity;
357
        if ($entity) {
358
            $this->checkIfOriginRecord($entity);
359
            $this->manager->remove($entity);
360
            $this->manager->flush();
361
            $return = null;
362
        }
363
364
        return $return;
365
    }
366
367
    /**
368
     * Triggers a flush on the DocumentManager
369
     *
370
     * @param null $document optional document
371
     *
372
     * @return void
373
     */
374
    public function flush($document = null)
375
    {
376
        $this->manager->flush($document);
377
    }
378
379
    /**
380
     * A low level delete without any checks
381
     *
382
     * @param mixed $id record id
383
     *
384
     * @return void
385
     */
386 2
    private function deleteById($id)
387
    {
388 2
        $builder = $this->repository->createQueryBuilder();
389
        $builder
390 2
            ->remove()
391 2
            ->field('id')->equals($id)
392 2
            ->getQuery()
393 2
            ->execute();
394 2
    }
395
396
    /**
397
     * Checks in a performant way if a certain record id exists in the database
398
     *
399
     * @param mixed $id record id
400
     *
401
     * @return bool true if it exists, false otherwise
402
     */
403 4
    public function recordExists($id)
0 ignored issues
show
Coding Style introduced by
function recordExists() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
404
    {
405 4
        return is_array($this->selectSingleFields($id, ['id'], false));
406
    }
407
408
    /**
409
     * Returns a set of fields from an existing resource in a performant manner.
410
     * If you need to check certain fields on an object (and don't need everything), this
411
     * is a better way to get what you need.
412
     * If the record is not present, you will receive null. If you don't need an hydrated
413
     * instance, make sure to pass false there.
414
     *
415
     * @param mixed $id      record id
416
     * @param array $fields  list of fields you need.
417
     * @param bool  $hydrate whether to hydrate object or not
418
     *
419
     * @return array|null|object
420
     */
421 4
    public function selectSingleFields($id, array $fields, $hydrate = true)
422
    {
423 4
        $builder = $this->repository->createQueryBuilder();
424 4
        $idField = $this->repository->getClassMetadata()->getIdentifier()[0];
425
426
        $record = $builder
427 4
            ->field($idField)->equals($id)
428 4
            ->select($fields)
429 4
            ->hydrate($hydrate)
430 4
            ->getQuery()
431 4
            ->getSingleResult();
432
433 4
        return $record;
434
    }
435
436
    /**
437
     * get classname of entity
438
     *
439
     * @return string|null
440
     */
441 4
    public function getEntityClass()
442
    {
443 4
        if ($this->repository instanceof DocumentRepository) {
444 4
            return $this->repository->getDocumentName();
445
        }
446
447
        return null;
448
    }
449
450
    /**
451
     * {@inheritDoc}
452
     *
453
     * Currently this is being used to build the route id used for redirecting
454
     * to newly made documents. It might benefit from having a different name
455
     * for those purposes.
456
     *
457
     * We might use a convention based mapping here:
458
     * Graviton\CoreBundle\Document\App -> mongodb://graviton_core
459
     * Graviton\CoreBundle\Entity\Table -> mysql://graviton_core
460
     *
461
     * @todo implement this in a more convention based manner
462
     *
463
     * @return string
464
     */
465
    public function getConnectionName()
466
    {
467
        $bundle = strtolower(substr(explode('\\', get_class($this))[1], 0, -6));
468
469
        return 'graviton.' . $bundle;
470
    }
471
472
    /**
473
     * Does the actual query using the RQL Bundle.
474
     *
475
     * @param Builder $queryBuilder Doctrine ODM QueryBuilder
476
     * @param Query   $query        query from parser
477
     *
478
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be Builder|\Doctrine\ODM\MongoDB\Query\Expr?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
479
     */
480
    protected function doRqlQuery($queryBuilder, Query $query)
481
    {
482
        $this->visitor->setBuilder($queryBuilder);
483
484
        return $this->visitor->visit($query);
485
    }
486
487
    /**
488
     * Checks the recordOrigin attribute of a record and will throw an exception if value is not allowed
489
     *
490
     * @param Object $record record
491
     *
492
     * @return void
493
     */
494 14
    protected function checkIfOriginRecord($record)
495
    {
496 7
        if ($record instanceof RecordOriginInterface
497 14
            && !$record->isRecordOriginModifiable()
498 7
        ) {
499 6
            $values = $this->notModifiableOriginRecords;
500 6
            $originValue = strtolower(trim($record->getRecordOrigin()));
501
502 6
            if (in_array($originValue, $values)) {
503 2
                $msg = sprintf("Must not be one of the following keywords: %s", implode(', ', $values));
504
505 2
                throw new RecordOriginModifiedException($msg);
506
            }
507 2
        }
508 12
    }
509
510
    /**
511
     * Determines the configured amount fo data records to be returned in pagination context.
512
     *
513
     * @return int
514
     */
515
    private function getDefaultLimit()
516
    {
517
        if (0 < $this->paginationDefaultLimit) {
518
            return $this->paginationDefaultLimit;
519
        }
520
521
        return 10;
522
    }
523
524
    /**
525
     * @param Boolean $active active
526
     * @param String  $field  field
527
     * @return void
528
     */
529 4
    public function setFilterByAuthUser($active, $field)
530
    {
531 4
        $this->filterByAuthUser = is_bool($active) ? $active : false;
532 4
        $this->filterByAuthField = $field;
533 4
    }
534
}
535