Constants::getConstantsValues()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Utils;
5
6
use Nette\Utils\Strings;
7
8
/**
9
 * Constants
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class Constants {
14
  use \Nette\StaticClass;
15
  
16
  /**
17
   * Get values of all constants from class $class whose name starts with $prefix
18
   *
19
   * @throws \ReflectionException
20
   */
21
  public static function getConstantsValues(string $class, string $prefix = ""): array {
22 1
    $values = [];
23 1
    $constants = (new \ReflectionClass($class))->getConstants();
24 1
    foreach($constants as $name => $value) {
25 1
      if(Strings::startsWith($name, $prefix)) {
26 1
        $values[] = $value;
27
      }
28
    }
29 1
    return $values;
30
  }
31
}
32
?>