Skip to content

Commit

Permalink
Merge pull request #11 from salahhusa9/fun-docs
Browse files Browse the repository at this point in the history
Fun docs
  • Loading branch information
salahhusa9 committed Oct 24, 2023
2 parents 4737e7e + 0fcb67e commit bcf4f1a
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 19 deletions.
14 changes: 0 additions & 14 deletions phpstan.neon.dist

This file was deleted.

8 changes: 4 additions & 4 deletions src/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

interface Repository
{
public function getLatestVersion();
public function getLatestVersion(): string;

public function getLatestVersionData();
public function getLatestVersionData(): \Illuminate\Support\Collection;

public function getVersions();
public function getVersions(): array;

public function getVersionsData();
public function getVersionsData(): \Illuminate\Support\Collection;
}
7 changes: 7 additions & 0 deletions src/Facades/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

/**
* @see \Salahhusa9\Updater\Updater
*
* @method static string update() Update the application to the latest version
* @method static array newVersionAvailable() Check if a new version is available
* @method static string getLatestVersion() Get the latest version
* @method static string getCurrentVersion() Get the current version
* @method static string getLatestVersionData() Get the latest version data
* @method static string versions() Get all versions
*/
class Updater extends Facade
{
Expand Down
55 changes: 55 additions & 0 deletions src/Helpers/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

class Git
{
/**
* getCurrentCommit
*
* @return string
*
* @throws \Exception
*/
public static function getCurrentCommit()
{
$process = Process::run(self::gitPath().' log --pretty="%h" -n1 HEAD');
Expand All @@ -18,6 +25,13 @@ public static function getCurrentCommit()
return trim($process->output());
}

/**
* getCurrentBranch
*
* @return string
*
* @throws \Exception
*/
public static function getCurrentBranch()
{
$process = Process::run(self::gitPath().' rev-parse --abbrev-ref HEAD');
Expand All @@ -29,6 +43,13 @@ public static function getCurrentBranch()
return trim($process->output());
}

/**
* getCurrentTag
*
* @return string
*
* @throws \Exception
*/
public static function getCurrentTag()
{
$process = Process::run(self::gitPath().' describe --tags --abbrev=0');
Expand All @@ -40,6 +61,13 @@ public static function getCurrentTag()
return trim($process->output());
}

/**
* auth
*
* @return string
*
* @throws \Exception
*/
public static function auth()
{
$process = Process::run(self::gitPath().' remote set-url origin https://'.config('updater.github_username').':'.config('updater.github_token').'@github.com/'.config('updater.github_username').'/'.config('updater.github_repository').'.git');
Expand All @@ -51,6 +79,13 @@ public static function auth()
return trim($process->output());
}

/**
* pull
*
* @return string
*
* @throws \Exception
*/
public static function pull()
{
$process = Process::run(self::gitPath().' pull');
Expand All @@ -62,6 +97,14 @@ public static function pull()
return trim($process->output());
}

/**
* checkout
*
* @param mixed $branch
* @return string
*
* @throws \Exception
*/
public static function checkout($branch)
{
$process = Process::run(self::gitPath().' checkout '.$branch);
Expand All @@ -73,6 +116,13 @@ public static function checkout($branch)
return trim($process->output());
}

/**
* fetch
*
* @return string
*
* @throws \Exception
*/
public static function fetch()
{
$process = Process::run(self::gitPath().' fetch');
Expand All @@ -84,6 +134,11 @@ public static function fetch()
return trim($process->output());
}

/**
* gitPath
*
* @return string
*/
public static function gitPath()
{
$gitPath = config('updater.git_path');
Expand Down
7 changes: 6 additions & 1 deletion src/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

class Helper
{
public function isVersion($version)
/**
* isVersion
*
* @param mixed $version
*/
public function isVersion($version): int|false
{
$pattern = '/^v(\d+\.\d+\.\d+)(-[a-zA-Z0-9]+(\.\d+)?)?$/';

Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallCacheClearPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallCacheClearPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('cache:clear');
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallConfigClearPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallConfigClearPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('config:clear');
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallMigratePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallMigratePipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('migrate', [
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallOptimizePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallOptimizePipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('optimize');
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallRouteClearPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallRouteClearPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('route:clear');
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/ArtisanCallViewClearPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class ArtisanCallViewClearPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('view:clear');
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/GitPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

class GitPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
$version = $content['new_version'];
Expand Down
7 changes: 7 additions & 0 deletions src/Pipelines/SeedersPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class SeedersPipe implements Pipeline
{
/**
* handle
*
* @param array $content
* @param mixed $next
* @return void
*/
public function handle($content, Closure $next)
{
Artisan::call('db:seed', [
Expand Down
21 changes: 21 additions & 0 deletions src/RepositorySource/GithubRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

class GithubRepository implements Repository
{
/**
* getLatestVersion
*/
public function getLatestVersion(): string
{
$this->checkConfig();

return isset($this->getLatestVersionData()['message']) ? throw new \Exception($this->getLatestVersionData()['message']) : $this->getLatestVersionData()['tag_name'];
}

/**
* getLatestVersionData
*
* @return Illuminate\Support\Collection
*/
public function getLatestVersionData(): \Illuminate\Support\Collection
{
$this->checkConfig();
Expand All @@ -29,6 +37,9 @@ public function getLatestVersionData(): \Illuminate\Support\Collection
return $response->collect();
}

/**
* getVersions
*/
public function getVersions(): array
{
$this->checkConfig();
Expand All @@ -44,6 +55,11 @@ public function getVersions(): array
})->toArray();
}

/**
* getVersionsData
*
* @return Illuminate\Support\Collection
*/
public function getVersionsData(): \Illuminate\Support\Collection
{
$this->checkConfig();
Expand All @@ -59,6 +75,11 @@ public function getVersionsData(): \Illuminate\Support\Collection
return $response->collect();
}

/**
* checkConfig
*
* @return void
*/
private function checkConfig()
{
if (config('updater.github_token') == null) {
Expand Down
Loading

0 comments on commit bcf4f1a

Please sign in to comment.