ConstantsTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConstants() 0 4 1
A toArray() 0 4 1
A isValid() 0 4 1
1
<?php
2
3
namespace Deltatag\Enum;
4
5
/**
6
 * Trait ConstantsTrait
7
 *
8
 * Provides constant features.
9
 *
10
 * @package Deltatag\Enum
11
 */
12
trait ConstantsTrait
13
{
14
	/**
15
	 * Fetch all constants of enum class
16
	 *
17
	 * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,integer|double|string|boolean>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
18
	 */
19
	public static function getConstants()
20
	{
21
		return (new \ReflectionClass(static::class))->getConstants();
22
	}
23
24
	/**
25
	 * Helper for getConstants()
26
	 *
27
	 * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,integer|double|string|boolean>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
28
	 */
29
	public static function toArray()
30
	{
31
		return self::getConstants();
32
	}
33
34
	/**
35
	 * Check if given value is valid value
36
	 *
37
	 * @param mixed $value
38
	 * @return bool
39
	 */
40
	public static function isValid($value)
41
	{
42
		return in_array($value, static::getConstants());
43
	}
44
}