This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Swatty007\LaravelVersioningHelper\Console\Command; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use Illuminate\Console\Command; |
||
7 | use Illuminate\Support\Facades\App; |
||
8 | use Illuminate\Support\Facades\Cache; |
||
9 | use Illuminate\Support\Facades\Config; |
||
10 | use PHLAK\SemVer; |
||
11 | |||
12 | class VersioningHelper extends Command |
||
13 | { |
||
14 | /** |
||
15 | * The name and signature of the console command. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $signature = 'versioning:helper |
||
20 | {--major= : Major Version} |
||
21 | {--minor= : Minor Version} |
||
22 | {--patch= : Patch Version} |
||
23 | {--preRelease= : Pre-Release Version} |
||
24 | {--build= : Build Version} |
||
25 | |||
26 | {--incrementMajor : Increment Major Version} |
||
27 | {--incrementMinor : Increment Minor Version} |
||
28 | {--incrementPatch : Increment Patch Version} |
||
29 | |||
30 | {--parse=true : Defines version should be parsed. (Automatically applies build & modification date from your versioning system) } |
||
31 | '; |
||
32 | |||
33 | /** |
||
34 | * The console command description. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $description = 'Helper Command to set your applications version.'; |
||
39 | |||
40 | /** |
||
41 | * Current Version |
||
42 | * |
||
43 | */ |
||
44 | public SemVer\Version $version; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
45 | |||
46 | /** |
||
47 | * Defines the modification date of our current revision |
||
48 | * |
||
49 | * @var Carbon |
||
50 | */ |
||
51 | public Carbon $modificationDate; |
||
52 | |||
53 | /** |
||
54 | * Defines the current PHP runtime at which our application runs |
||
55 | * @var string |
||
56 | */ |
||
57 | public string $runtime; |
||
58 | |||
59 | /** |
||
60 | * Create a new command instance. |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | public function __construct() |
||
65 | { |
||
66 | parent::__construct(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Execute the console command. |
||
71 | * |
||
72 | * @return int |
||
73 | * @throws SemVer\Exceptions\InvalidVersionException |
||
74 | */ |
||
75 | public function handle(): int |
||
76 | { |
||
77 | $this->version = new SemVer\Version(); |
||
78 | |||
79 | $currentVersion = Cache::pull(config('laravel-versioning-helper.version_key')) ?? Config::get(config('laravel-versioning-helper.version_key')); |
||
80 | if ($currentVersion) { |
||
81 | $this->version->setVersion($currentVersion); |
||
82 | } |
||
83 | |||
84 | $this->applyOptions(); |
||
85 | |||
86 | $this->info("Current Version: " . $currentVersion); |
||
87 | $this->line("New Version: " . $this->version); |
||
88 | |||
89 | $this->parseBuild(); |
||
90 | |||
91 | $this->saveVersion(); |
||
92 | |||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Helper Method to apply our Commands Options |
||
98 | * |
||
99 | */ |
||
100 | private function applyOptions() |
||
101 | { |
||
102 | $options = $this->options(); |
||
103 | |||
104 | if (isset($options['major'])) { |
||
105 | $this->version->setMajor($options['major']); |
||
106 | } |
||
107 | if (isset($options['minor'])) { |
||
108 | $this->version->setMinor($options['minor']); |
||
109 | } |
||
110 | if (isset($options['patch'])) { |
||
111 | $this->version->setPatch($options['patch']); |
||
112 | } |
||
113 | if (isset($options['preRelease'])) { |
||
114 | $this->version->setPreRelease($options['preRelease']); |
||
115 | } |
||
116 | if (isset($options['build'])) { |
||
117 | $this->version->setBuild($options['build']); |
||
118 | } |
||
119 | |||
120 | if ($options['incrementMajor']) { |
||
121 | $this->version->incrementMajor(); |
||
122 | } |
||
123 | if ($options['incrementMinor']) { |
||
124 | $this->version->incrementMinor(); |
||
125 | } |
||
126 | if ($options['incrementPatch']) { |
||
127 | $this->version->incrementPatch(); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Helper Method to assemble a version string based on our used repository system |
||
133 | * |
||
134 | */ |
||
135 | private function parseBuild() |
||
136 | { |
||
137 | $versioningSystem = config('laravel-versioning-helper.versioning_system'); |
||
138 | |||
139 | switch ($versioningSystem) { |
||
140 | case 'git': |
||
141 | // For git we can use the tag to receive our version number as fallback |
||
142 | $currentVersion = config('laravel-versioning-helper.version') ?? exec('git describe --tags --abbrev=0'); |
||
143 | // And the latest hash as our revision Nr |
||
144 | $revision = trim(exec('git log --pretty="%h" -n1 HEAD')); |
||
145 | $modificationDate = Carbon::parse(trim(exec('git log -n1 --pretty=%ci HEAD'))); |
||
146 | break; |
||
147 | case 'svn': |
||
148 | // For SVN we have to take our version from our config & assume it was set by a build script! |
||
149 | $currentVersion = config('laravel-versioning-helper.version'); |
||
150 | // and SVNs latest rev as our revision |
||
151 | $revision = exec("svn info | grep 'Last Changed Rev' | awk '{ print $4; }'"); |
||
152 | $modificationDate = Carbon::parse(trim(exec("svn info | grep 'Last Changed Date' | awk '{ print $4 \" \" $5; }'"))); |
||
153 | break; |
||
154 | case 'self-updater': |
||
155 | $currentVersion = config('laravel-versioning-helper.version'); |
||
156 | $revision = ''; |
||
157 | $modificationDate = Carbon::parse(config('self-update.version_date')); |
||
158 | break; |
||
159 | default: |
||
160 | $currentVersion = '0.0.0'; |
||
161 | $revision = ''; |
||
162 | $modificationDate = Carbon::now(); |
||
163 | break; |
||
164 | } |
||
165 | |||
166 | if ($modificationDate) { |
||
167 | $this->modificationDate = $modificationDate; |
||
168 | } |
||
169 | |||
170 | if ($currentVersion && $this->options()['parse']) { |
||
171 | $this->version->setVersion($currentVersion); |
||
172 | $this->version->setBuild($revision); |
||
173 | } |
||
174 | |||
175 | if (!App::environment('production')) { |
||
176 | $this->runtime = 'PHP v' . PHP_VERSION; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Helper Method to save our applications version within the system |
||
182 | */ |
||
183 | private function saveVersion() |
||
184 | { |
||
185 | Cache::put(config('laravel-versioning-helper.version_key'), $this->version); |
||
186 | Cache::put(config('laravel-versioning-helper.modification_date_key'), $this->modificationDate); |
||
187 | Cache::put(config('laravel-versioning-helper.runtime_key'), $this->runtime); |
||
188 | } |
||
189 | } |
||
190 |