Completed
Push — master ( 8c96d4...437363 )
by Jakub
02:32 queued 20s
created

Constants   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConstantsValues() 0 9 3
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
class Constants {
14 1
  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
?>