Completed
Push — master ( 646730...43a697 )
by Vitaly
05:45
created

Base::amountByRelationID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: VITALYIEGOROV
5
 * Date: 08.12.15
6
 * Time: 22:14
7
 */
8
namespace samsoncms\api\query;
9
10
use samsonframework\orm\QueryInterface;
11
12
/**
13
 * Generic SamsonCMS query for retrieving entities that have relation between each other
14
 * through other relational entity.
15
 *
16
 * @package samsoncms\api
17
 */
18
class Base
19
{
20
    /** Deletion flag field name */
21
    const DELETE_FLAG_FIELD = 'Active';
22
23
    /** @var QueryInterface Database query instance */
24
    protected $query;
25
26
    /** @var string Entity identifier */
27
    protected $identifier;
28
29
    /** @var string Entity primary field name */
30
    protected $primaryField;
31
32
    /** @var array Collection of entity identifiers for filtering */
33
    protected $filteringIDs;
34
35
    /**
36
     * Entity constructor.
37
     * @param QueryInterface $query Database query instance
38
     * @param string $identifier Entity identifier
39
     * @param array $filteringIDs Collection of entity identifiers for filtering
40
     */
41
    public function __construct(
42
        QueryInterface $query,
43
        $identifier,
44
        $filteringIDs = array()
45
    ) {
46
        $this->query = $query;
47
        $this->identifier = $identifier;
48
        $this->primaryField = $identifier::$_primary;
49
        $this->filteringIDs = $filteringIDs;
50
    }
51
52
    /**
53
     * Get current entity instances collection by their identifiers.
54
     * Method can accept different query executors.
55
     *
56
     * @param string|array $entityIDs Entity identifier or their collection
57
     * @param string $executor Method name for query execution
58
     * @return mixed[] Collection of entity instances
59
     */
60
    public function byIDs($entityIDs, $executor)
61
    {
62
        return $this->query
63
            ->entity($this->identifier)
64
            ->where($this->primaryField, $entityIDs)
0 ignored issues
show
Bug introduced by
It seems like $entityIDs defined by parameter $entityIDs on line 60 can also be of type array; however, samsonframework\orm\QueryInterface::where() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
65
            ->where(self::DELETE_FLAG_FIELD, 1)
66
            ->$executor();
67
    }
68
}
69