Skip to content

Commit 0d7d4eb

Browse files
authored
Merge pull request #89 from codedge/#83-version-avail-false
Fix #83, Return nothing if no new version is available
2 parents 1ae905a + 47cd5d1 commit 0d7d4eb

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/SourceRepositoryTypes/HttpRepositoryType.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Codedge\Updater\Events\UpdateSucceeded;
1212
use Codedge\Updater\Traits\SupportPrivateAccessToken;
1313
use Codedge\Updater\Traits\UseVersionFile;
14+
use Exception;
1415
use GuzzleHttp\Client;
1516
use Illuminate\Database\Eloquent\Collection;
1617
use Illuminate\Support\Facades\File;
@@ -70,7 +71,7 @@ public function __construct(Client $client, array $config)
7071
* @param string $currentVersion
7172
*
7273
* @throws \InvalidArgumentException
73-
* @throws \Exception
74+
* @throws Exception
7475
*
7576
* @return bool
7677
*/
@@ -102,14 +103,14 @@ public function isNewVersionAvailable($currentVersion = ''): bool
102103
*
103104
* @param string $version
104105
*
105-
* @throws \Exception
106+
* @throws Exception
106107
*
107108
* @return mixed
108109
*/
109110
public function fetch($version = '')
110111
{
111112
if (($releaseCollection = $this->getPackageReleases())->isEmpty()) {
112-
throw new \Exception('Cannot find a release to update. Please check the repository you\'re pulling from');
113+
throw new Exception('Cannot find a release to update. Please check the repository you\'re pulling from');
113114
}
114115

115116
$release = $releaseCollection->first();
@@ -122,7 +123,7 @@ public function fetch($version = '')
122123
if (! $version) {
123124
$release = $releaseCollection->where('name', $version)->first();
124125
if (! $release) {
125-
throw new \Exception('Given version was not found in release list.');
126+
throw new Exception('Given version was not found in release list.');
126127
}
127128
}
128129

@@ -205,21 +206,19 @@ public function getVersionInstalled($prepend = '', $append = ''): string
205206
* Example: 2.6.5 or v2.6.5.
206207
*
207208
* @param string $prepend Prepend a string to the latest version
208-
* @param string $append Append a string to the latest version
209-
*
210-
* @throws \Exception
209+
* @param string $append Append a string to the latest version
211210
*
212211
* @return string
212+
* @throws Exception
213213
*/
214214
public function getVersionAvailable($prepend = '', $append = ''): string
215215
{
216-
$version = '';
217216
if ($this->versionFileExists()) {
218217
$version = $this->getVersionFile();
219218
} else {
220219
$releaseCollection = $this->getPackageReleases();
221220
if ($releaseCollection->isEmpty()) {
222-
throw new \Exception('Retrieved version list is empty.');
221+
return '';
223222
}
224223
$version = $releaseCollection->first()->name;
225224
}
@@ -230,14 +229,14 @@ public function getVersionAvailable($prepend = '', $append = ''): string
230229
/**
231230
* Retrieve html body with list of all releases from archive URL.
232231
*
233-
*@throws \Exception
232+
*@throws Exception
234233
*
235234
* @return mixed|ResponseInterface
236235
*/
237236
protected function getPackageReleases()
238237
{
239238
if (empty($url = $this->config['repository_url'])) {
240-
throw new \Exception('No repository specified. Please enter a valid URL in your config.');
239+
throw new Exception('No repository specified. Please enter a valid URL in your config.');
241240
}
242241

243242
$format = str_replace('_VERSION_', '\d+\.\d+\.\d+',

0 commit comments

Comments
 (0)