CommandValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 5
c 3
b 0
f 1
dl 0
loc 18
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValidKey() 0 7 2
1
<?php
2
3
namespace msztorc\LaravelEnv\Commands\Traits;
4
5
use InvalidArgumentException;
6
7
trait CommandValidator
8
{
9
10
    private $invalidKeyException = 'Invalid environment key. Only use upper letters, digits, and underscores. A variable must start with the letter.';
11
12
    /**
13
     * Check if a given string is valid as an environment variable key.
14
     *
15
     * @param string $key
16
     * @return bool
17
     */
18
    protected function isValidKey(string $key): bool
19
    {
20
        if (!preg_match('/^[A-Z_]\w*$/', $key)) {
21
            throw new InvalidArgumentException($this->invalidKeyException);
22
        }
23
24
        return true;
25
    }
26
}
27