ConstantsTrait::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
}