Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractRelationship
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getForeignTable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getForeignKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getChildRelationships
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setChildRelationships
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getEagerRelationships
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Db\Record\Relationships;
15
16use Pop\Db\Record\Collection;
17
18/**
19 * Relationship class for "has one" relationships
20 *
21 * @category   Pop
22 * @package    Pop\Db
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    6.5.0
27 */
28abstract class AbstractRelationship implements RelationshipInterface
29{
30
31    /**
32     * Foreign table class
33     * @var ?string
34     */
35    protected ?string $foreignTable = null;
36
37    /**
38     * Foreign key
39     * @var ?string
40     */
41    protected ?string $foreignKey = null;
42
43    /**
44     * Relationship options
45     * @var ?array
46     */
47    protected ?array $options = null;
48
49    /**
50     * Relationship children
51     * @var ?string
52     */
53    protected ?string $children = null;
54
55    /**
56     * Constructor
57     *
58     * Instantiate the relationship object
59     *
60     * @param string $foreignTable
61     * @param string $foreignKey
62     * @param ?array $options
63     */
64    public function __construct(string $foreignTable, string $foreignKey, ?array $options = null)
65    {
66        $this->foreignTable = $foreignTable;
67        $this->foreignKey   = $foreignKey;
68        $this->options      = $options;
69    }
70
71    /**
72     * Get foreign table class
73     *
74     * @return string|null
75     */
76    public function getForeignTable(): string|null
77    {
78        return $this->foreignTable;
79    }
80
81    /**
82     * Get foreign key
83     *
84     * @return string|null
85     */
86    public function getForeignKey(): string|null
87    {
88        return $this->foreignKey;
89    }
90
91    /**
92     * Get options
93     *
94     * @return array|null
95     */
96    public function getOptions(): array|null
97    {
98        return $this->options;
99    }
100
101    /**
102     * Get child relationships
103     *
104     * @return string|null
105     */
106    public function getChildRelationships(): string|null
107    {
108        return $this->children;
109    }
110
111    /**
112     * Set children child relationships
113     *
114     * @param  string $children
115     * @return static
116     */
117    public function setChildRelationships(string $children): static
118    {
119        $this->children = $children;
120        return $this;
121    }
122
123    /**
124     * Get eager relationships
125     *
126     * @param  array $ids
127     * @throws Exception
128     * @return array
129     */
130    abstract public function getEagerRelationships(array $ids): array;
131
132}