AppInfo::isVersionTagDev()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\Helpers\Laravel;
4
5
use Illuminate\Support\Facades\Cache;
6
use Sfneal\Helpers\Laravel\Support\CacheKey;
7
use Sfneal\Helpers\Laravel\Support\Changelog;
8
use Sfneal\Helpers\Strings\StringHelpers;
9
10
class AppInfo
11
{
12
    /**
13
     * Retrieve the Application's version.
14
     *
15
     * @return string
16
     */
17
    public static function version(): string
18
    {
19
        return Cache::rememberForever(
20
            // Cache key
21
            (new CacheKey('version'))->execute(),
22
23
            // Value to cache
24
            function () {
25
                return trim(config('app-info.version')).(self::isEnvDevelopment() ? ' (dev)' : '');
26
            }
27
        );
28
    }
29
30
    /**
31
     * Retrieve an array of changes made to a particular application version.
32
     *
33
     * @param  string|null  $version
34
     * @return array|null
35
     */
36
    public static function versionChanges(string $version = null): ?array
37
    {
38
        // Get current version changes if $version wasn't passed
39
        return (new Changelog())->versionChanges($version ?? self::version());
40
    }
41
42
    /**
43
     * Retrieve the Application's changelog.
44
     *
45
     * @return array
46
     */
47
    public static function changelog(): array
48
    {
49
        return (new Changelog())->changelog();
50
    }
51
52
    /**
53
     * Determine if a particular Version is running.
54
     *
55
     * @param  string  $version
56
     * @return mixed
57
     */
58
    public static function isVersion(string $version): bool
59
    {
60
        return self::version() == $version;
61
    }
62
63
    /**
64
     * Determine if a particular Version is running.
65
     *
66
     * @param  string  $version
67
     * @return mixed
68
     */
69
    public static function isNotVersion(string $version): bool
70
    {
71
        return ! self::isVersion($version);
72
    }
73
74
    /**
75
     * Determine if a 'beta' version is running.
76
     *
77
     * @return mixed
78
     */
79
    public static function isVersionTagBeta(): bool
80
    {
81
        return self::isVersionTag('beta');
82
    }
83
84
    /**
85
     * Determine if a 'dev' version is running.
86
     *
87
     * @return mixed
88
     */
89
    public static function isVersionTagDev(): bool
90
    {
91
        return self::isVersionTag('dev');
92
    }
93
94
    /**
95
     * Determine if a particular tag version is running (beta, dev, staging, etc..).
96
     *
97
     * @param  string  $tag
98
     * @return mixed
99
     */
100
    public static function isVersionTag(string $tag): bool
101
    {
102
        return Cache::rememberForever(
103
            // Cache key
104
            (new CacheKey('version', "is-{$tag}"))->execute(),
105
106
            // Value to cache
107
            function () use ($tag) {
108
                return (new StringHelpers(self::version()))->inString($tag);
109
            }
110
        );
111
    }
112
113
    /**
114
     * Determine if the Application is running in a 'production' environment.
115
     *
116
     * @return bool
117
     */
118
    public static function isEnvProduction(): bool
119
    {
120
        return self::isEnv('production');
121
    }
122
123
    /**
124
     * Determine if the Application is running in a 'development' environment.
125
     *
126
     * @return bool
127
     */
128
    public static function isEnvDevelopment(): bool
129
    {
130
        return self::isEnv('development');
131
    }
132
133
    /**
134
     * Determine if the Application is running in a 'testing' environment.
135
     *
136
     * @return bool
137
     */
138
    public static function isEnvTesting(): bool
139
    {
140
        return self::isEnv('testing');
141
    }
142
143
    /**
144
     * Determine if the application is in a particular environment.
145
     *
146
     * @param  string  $env
147
     * @return bool
148
     */
149
    public static function isEnv(string $env): bool
150
    {
151
        return self::env() == $env;
152
    }
153
154
    /**
155
     * Retrieve the application's environment.
156
     *
157
     * @return string|null
158
     */
159
    public static function env(): ?string
160
    {
161
        return config('app.env');
162
    }
163
}
164