Code Duplication    Length = 47-48 lines in 2 locations

src/Criteria/Relation.php 1 location

@@ 18-65 (lines=48) @@
15
/**
16
 * Class Relation
17
 */
18
class Relation extends Criterion
19
{
20
    /**
21
     * @var Field
22
     */
23
    private $relation;
24
25
    /**
26
     * @var \Closure|null
27
     */
28
    private $inner;
29
30
    /**
31
     * Relation constructor.
32
     * @param string $relation
33
     * @param Query $parent
34
     * @param \Closure|null $inner
35
     */
36
    public function __construct(Query $parent, string $relation, \Closure $inner = null)
37
    {
38
        parent::__construct($parent);
39
40
        $this->relation = $this->field($relation);
41
        $this->inner = $inner;
42
    }
43
44
    /**
45
     * @return Field
46
     */
47
    public function getRelation(): Field
48
    {
49
        return $this->relation;
50
    }
51
52
    /**
53
     * @return Query
54
     */
55
    public function getRelatedQuery(): Query
56
    {
57
        $related = $this->query->create();
58
59
        if ($this->inner) {
60
            ($this->inner)($related);
61
        }
62
63
        return $related;
64
    }
65
}
66

src/Criteria/WhereGroup.php 1 location

@@ 17-63 (lines=47) @@
14
/**
15
 * Class WhereGroup
16
 */
17
class WhereGroup extends Criterion
18
{
19
    /**
20
     * @var bool
21
     */
22
    private $conjunction;
23
24
    /**
25
     * @var \Closure
26
     */
27
    private $then;
28
29
    /**
30
     * Group constructor.
31
     * @param Query $parent
32
     * @param \Closure $then
33
     * @param bool $conjunction
34
     */
35
    public function __construct(Query $parent, \Closure $then, bool $conjunction = true)
36
    {
37
        parent::__construct($parent);
38
39
        $this->then = $then;
40
        $this->conjunction = $conjunction;
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isAnd(): bool
47
    {
48
        return $this->conjunction;
49
    }
50
51
    /**
52
     * @return Query
53
     */
54
    public function getQuery(): Query
55
    {
56
        $query = $this->query->create()
57
            ->withAlias($this->query->getAlias());
58
59
        ($this->then)($query);
60
61
        return $query;
62
    }
63
}
64