SelectorValidationTrait::validateSelector()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Listing\Traits;
9
10
use Spiral\Listing\Exceptions\InvalidSelectorException;
11
use Spiral\ODM\Entities\DocumentSelector;
12
use Spiral\ORM\Entities\RecordSelector;
13
use Spiral\Pagination\PaginatorAwareInterface;
14
15
trait SelectorValidationTrait
16
{
17
    /**
18
     * @param PaginatorAwareInterface|RecordSelector|DocumentSelector $selector
19
     *
20
     * @throws InvalidSelectorException
21
     */
22
    protected function validateSelector(PaginatorAwareInterface $selector)
23
    {
24
        if (!$selector instanceof RecordSelector && !$selector instanceof DocumentSelector) {
25
            throw new InvalidSelectorException(
26
                "Only instance of Record/Document selectors are allowed, '"
27
                . get_class($selector) . "'"
28
            );
29
        }
30
    }
31
}