Code Duplication    Length = 32-32 lines in 2 locations

src/Finders/EnvFileFinder.php 1 location

@@ 5-36 (lines=32) @@
2
3
namespace Bmitch\Envsync\Finders;
4
5
class EnvFileFinder
6
{
7
8
    /**
9
     * Regex pattern to use to find environment variables.
10
     * @var  string $contents Regular Expression.
11
     */
12
    public static $pattern = "/([A-Za-z_]{1,})=/";
13
14
    /**
15
     * Finds the environment variables within the $file.
16
     * @param  string $file Path and filename.
17
     * @return array
18
     */
19
    public static function find($file)
20
    {
21
        if (! file_exists($file)) {
22
            return [];
23
        }
24
25
        $contents = file_get_contents($file);
26
27
        $envs = [];
28
29
        preg_match_all(self::$pattern, $contents, $matches);
30
        if (isset($matches[1])) {
31
            $envs = $matches[1];
32
        }
33
34
        return $envs;
35
    }
36
}
37

src/Finders/PhpFileFinder.php 1 location

@@ 5-36 (lines=32) @@
2
3
namespace Bmitch\Envsync\Finders;
4
5
class PhpFileFinder
6
{
7
8
    /**
9
     * Regex pattern to use to find environment variables.
10
     * @var  string $contents Regular Expression.
11
     */
12
    public static $pattern = "/env\(['\"]([A-Za-z_]{1,})/";
13
14
    /**
15
     * Finds the environment variables within the $file.
16
     * @param  string $file Path and filename.
17
     * @return array
18
     */
19
    public static function find($file)
20
    {
21
        if (! file_exists($file)) {
22
            return [];
23
        }
24
25
        $contents = file_get_contents($file);
26
27
        $envs = [];
28
29
        preg_match_all(self::$pattern, $contents, $matches);
30
        if (isset($matches[1])) {
31
            $envs = $matches[1];
32
        }
33
34
        return $envs;
35
    }
36
}
37