Enforcer::__add()   A
last analyzed

Complexity

Conditions 4
Paths 9

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 4
nc 9
nop 2
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\Common;
24
25
use ReflectionClass;
26
use ReflectionException;
27
28
/**
29
 * Class Enforcer
30
 *
31
 * @package DBD\Entity\Common
32
 */
33
class Enforcer
34
{
35
    /**
36
     * @param $class
37
     * @param $c
38
     *
39
     * @throws EntityException
40
     */
41
    public static function __add($class, $c)
42
    {
43
        try {
44
            $reflection = new ReflectionClass($class);
45
            $constantsForced = $reflection->getConstants();
46
            foreach ($constantsForced as $constant => $value) {
47
                if (constant("$c::$constant") == "abstract") {
48
                    trigger_error(sprintf("Undefined constant %s in %s", $constant, $c), E_USER_ERROR);
49
                }
50
            }
51
        } catch (ReflectionException $e) {
52
            throw new EntityException($e->getMessage());
53
        }
54
    }
55
}
56