Issues (2)

src/DBD/Entity/Complex.php (1 issue)

Severity
1
<?php
2
/********************************************************************************
3
 *   Apache License, Version 2.0                                                *
4
 *                                                                              *
5
 *   Copyright [2020] [Nurlan Mukhanov <[email protected]>]                      *
6
 *                                                                              *
7
 *   Licensed under the Apache License, Version 2.0 (the "License");            *
8
 *   you may not use this file except in compliance with the License.           *
9
 *   You may obtain a copy of the License at                                    *
10
 *                                                                              *
11
 *       http://www.apache.org/licenses/LICENSE-2.0                             *
12
 *                                                                              *
13
 *   Unless required by applicable law or agreed to in writing, software        *
14
 *   distributed under the License is distributed on an "AS IS" BASIS,          *
15
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
16
 *   See the License for the specific language governing permissions and        *
17
 *   limitations under the License.                                             *
18
 *                                                                              *
19
 ********************************************************************************/
20
21
declare(strict_types=1);
22
23
namespace DBD\Entity;
24
25
use DBD\Entity\Common\EntityException;
26
27
/**
28
 * Use Complex when you need JOIN several tables and select all in once
29
 * Corresponding property with Entity type must be defined in base entity class
30
 *
31
 * @package DBD\Entity
32
 */
33
class Complex
34
{
35
    const TYPE = "complexClass";
36
    /** @var string $complexClass full class name with namespace */
37
    public $complexClass;
38
39
    /**
40
     * Complex constructor.
41
     *
42
     * @param string|array $complexNameOrArray
43
     * @throws EntityException
44
     */
45
    public function __construct($complexNameOrArray)
46
    {
47
        if (isset($complexNameOrArray)) {
48
            if (is_string($complexNameOrArray)) {
49
                $this->complexClass = $complexNameOrArray;
50
            } else if (is_array($complexNameOrArray)) {
0 ignored issues
show
The condition is_array($complexNameOrArray) is always true.
Loading history...
51
                foreach ($complexNameOrArray as $key => $value) {
52
                    $this->$key = $value;
53
                }
54
            } else {
55
                throw new EntityException("Complex constructor accepts only string or array");
56
            }
57
        }
58
59
        if (!isset($this->complexClass)) {
60
            throw new EntityException("Complex className not set");
61
        }
62
    }
63
}
64