diff options
author | Willy Micieli <micieli@laposte.net> | 2019-11-08 08:16:08 +0100 |
---|---|---|
committer | Willy Micieli <micieli@laposte.net> | 2019-11-08 08:16:08 +0100 |
commit | ba8caff45f48ee8d72122e1e3e6c10103182e46a (patch) | |
tree | bebcb4254687c3dd20cddcf18e5a1db74df76197 | |
parent | 1b33a1f59896f92fdf170d9376b6e4b234e02385 (diff) | |
download | imperium-ba8caff45f48ee8d72122e1e3e6c10103182e46a.zip imperium-ba8caff45f48ee8d72122e1e3e6c10103182e46a.tar.gz |
clean code10.6
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | imperium/App.php | 8 | ||||
-rw-r--r-- | imperium/Management.php | 5 | ||||
-rw-r--r-- | imperium/Testing/Unit.php | 10 | ||||
-rw-r--r-- | imperium/Versioning/Git.php | 51 | ||||
-rw-r--r-- | tests/Versioning/GitTest.php | 10 |
6 files changed, 35 insertions, 53 deletions
@@ -9,7 +9,7 @@ It's a library written to be useful for everybody, in order to manage dbs and to `composer require imperium/imperium`
* [**Source code**](https://git.fumseck.eu/cgit/imperium)
- * [**Download**](https://git.fumseck.eu/cgit/imperium/snapshot/imperium-10.5.5.zip)
+ * [**Download**](https://git.fumseck.eu/cgit/imperium/snapshot/imperium-10.6zip)
* [**Report a bug**](mailto:bugzilla@laposte.net)
- * [**Show diff**](https://git.fumseck.eu/cgit/imperium/diff/?id=10.5.5&id2=10.5.4&dt=2)
+ * [**Show diff**](https://git.fumseck.eu/cgit/imperium/diff/?id=10.6&id2=10.5.5&dt=2)
diff --git a/imperium/App.php b/imperium/App.php index 7ae1675..8721a1e 100644 --- a/imperium/App.php +++ b/imperium/App.php @@ -743,16 +743,16 @@ namespace Imperium { * Management of git
*
* @param string $repository
- * @param string $owner
+ * @param string $branch
+ * @param string $directory
*
* @return Git
*
* @throws Kedavra
- *
*/
- public function git(string $repository, string $owner): Git
+ public function git(string $repository, string $branch,string $directory =''): Git
{
- return new Git($repository,$owner);
+ return new Git($repository,$branch,$directory);
}
}
}
diff --git a/imperium/Management.php b/imperium/Management.php index db4f13c..1f7f84c 100644 --- a/imperium/Management.php +++ b/imperium/Management.php @@ -498,12 +498,13 @@ * Management of git * * @param string $repository - * @param string $owner + * @param string $branch + * @param string $directory * * @return Git * */ - public function git(string $repository,string $owner): Git; + public function git(string $repository,string $branch,string $directory=''): Git; } } diff --git a/imperium/Testing/Unit.php b/imperium/Testing/Unit.php index 440dba7..465e83e 100644 --- a/imperium/Testing/Unit.php +++ b/imperium/Testing/Unit.php @@ -176,18 +176,16 @@ * Get an instance of git class * * @param string $repository - * @param string $owner - * + * @param string $branch * @return Git * * @throws DependencyException - * @throws NotFoundException * @throws Kedavra - * + * @throws NotFoundException */ - public function git(string $repository,string $owner): Git + public function git(string $repository,string $branch): Git { - return app()->git($repository,$owner); + return app()->git($repository,$branch); } } }
\ No newline at end of file diff --git a/imperium/Versioning/Git.php b/imperium/Versioning/Git.php index 78e36b2..7cd1c97 100644 --- a/imperium/Versioning/Git.php +++ b/imperium/Versioning/Git.php @@ -28,28 +28,27 @@ private $repository; /** - * - * The repository owner - * + * @var array + */ + private $data; + /** * @var string - * */ - private $owner; + private $branch; /** - * @var array + * @var string */ - private $data; + private $directory; /** * Git constructor. * * @param string $repository - * @param string $owner - * + * @param string $branch + * @param string $directory * @throws Kedavra - * */ - public function __construct(string $repository,string $owner) + public function __construct(string $repository,string $branch,string $directory='') { is_false(is_dir($repository),true,"Repository is not a directory"); @@ -59,20 +58,9 @@ $this->repository = collect(explode(DIRECTORY_SEPARATOR,realpath($repository)))->last(); - $this->owner = $owner; + $this->branch = $branch; - } - - /** - * - * Get the repository owner - * - * @return string - * - */ - public function owner(): string - { - return $this->owner; + $this->directory = $directory; } /**cd @@ -97,7 +85,7 @@ */ public function status(): string { - return nl2br(html_entity_decode($this->execute('git status | aha')->join("\n"))); + return is_dir('.git') ? nl2br(html_entity_decode($this->execute('git status | aha')->join("\n"))) : ''; } /** @@ -133,13 +121,7 @@ */ public function branches(): array { - $x = collect(); - - foreach ($this->execute('git branch') as $branch) - { - $x->push(str_replace(' ','',str_replace('* ','',$branch))); - } - return $x->all(); + return array_diff(scandir('refs/heads'), ['..','.']); } /** @@ -157,7 +139,8 @@ */ public function releases(): array { - return $this->execute('git tag -l --sort=v:refname')->reverse()->all(); + $f = function ($x){ return str_replace('refs/tags/','',$x);}; + return $this->execute("git for-each-ref --sort=-taggerdate --format '%(refname)' refs/tags")->for($f)->all(); } /** @@ -214,7 +197,7 @@ */ public function current_branch(): string { - return $this->execute('git branch --show-current')->get(0); + return $this->branch; } /** * diff --git a/tests/Versioning/GitTest.php b/tests/Versioning/GitTest.php index c694e07..f9a315c 100644 --- a/tests/Versioning/GitTest.php +++ b/tests/Versioning/GitTest.php @@ -6,6 +6,7 @@ namespace Testing\Versioning; use DI\DependencyException; use DI\NotFoundException; +use Imperium\Exception\Kedavra; use Imperium\Testing\Unit; use Imperium\Versioning\Git; @@ -19,30 +20,29 @@ class GitTest extends Unit /** * @throws DependencyException * @throws NotFoundException + * @throws Kedavra */ public function setUp(): void { - $this->git = $this->git('/home/willy/bidon','willy'); + $this->git = $this->git('/home/willy/bidon','develop'); } public function test_base() { $this->assertEquals('bidon',$this->git->name()); - $this->assertEquals('willy',$this->git->owner()); } public function test_status() { - $this->assertNotEmpty($this->git->status()); + $this->assertEmpty($this->git->status()); } public function test_diff() { - $this->assertNotEmpty($this->git->diff()); $this->assertNotEmpty($this->git->diff('10.5.2','10.5.3')); } public function test_branch() { - $this->assertEquals('master',$this->git->current_branch()); + $this->assertEquals('develop',$this->git->current_branch()); } public function test_commit_size() { |