| Total Complexity | 10 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | trait PermissionTrait |
||
| 6 | { |
||
| 7 | private $name; |
||
| 8 | private $id; |
||
| 9 | |||
| 10 | public function getName(): string |
||
| 13 | } |
||
| 14 | |||
| 15 | public function getValue(): int |
||
| 16 | { |
||
| 17 | return $this->id; |
||
| 18 | } |
||
| 19 | |||
| 20 | public static function forName(string $name): PermissionInterface |
||
| 21 | { |
||
| 22 | $names = explode("_", strtolower($name)); |
||
| 23 | $func = $names[0]; |
||
| 24 | if (count($names) > 1) { |
||
| 25 | for ($i = 1; $i < count($names); $i += 1) { |
||
|
|
|||
| 26 | $func .= ucfirst($names[$i]); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | return self::$func(); |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function values(): array |
||
| 45 | } |
||
| 46 | } |
||
| 47 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: