-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from markwalet/9-add-laravel-7-support
Add laravel 7 support
- Loading branch information
Showing
6 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
preset: laravel | ||
enabled: | ||
- alpha_ordered_imports | ||
disabled: | ||
- length_ordered_imports | ||
- simplified_null_return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace MarkWalet\GitState\Support; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class RemoteUrlTransformer | ||
{ | ||
/** | ||
* Transform the url to a visitable url. | ||
* | ||
* @param string $url | ||
* @return string | ||
*/ | ||
public static function transform(string $url) | ||
{ | ||
// Remove ssh user. | ||
$url = last(explode('@', $url, 2)); | ||
|
||
// Remove http or https prefix if present. | ||
if (Str::startsWith($url, ['http://', 'https://'])) { | ||
$url = last(explode('//', $url, 2)); | ||
} | ||
|
||
// Remove `.git` appendix if present. | ||
if (Str::endsWith($url, '.git')) { | ||
$url = substr($url, 0, -4); | ||
} | ||
|
||
// Replace semi colons. | ||
return str_replace(':', '/', $url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace MarkWalet\GitState\Tests; | ||
|
||
use MarkWalet\GitState\Support\RemoteUrlTransformer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RemoteUrlTransformerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_the_url_if_it_is_already_valid() | ||
{ | ||
$url = 'github.com/markwalet/laravel-git-state'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_removes_the_http_prefix_if_present() | ||
{ | ||
$url = 'http://github.com/markwalet/laravel-git-state'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_removes_the_https_prefix_if_present() | ||
{ | ||
$url = 'https://github.com/markwalet/laravel-git-state'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_removes_the_git_appendix_if_present() | ||
{ | ||
$url = 'https://github.com/markwalet/laravel-git-state.git'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_removes_the_ssh_user_if_present() | ||
{ | ||
$url = '[email protected]/markwalet/laravel-git-state'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_replaces_semi_colons_with_forward_slashes() | ||
{ | ||
$url = 'github.com:markwalet/laravel-git-state'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('github.com/markwalet/laravel-git-state', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_format_gitlab_ssh_remotes() | ||
{ | ||
$url = '[email protected]:gitlab-org/gitlab-foss.git'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('gitlab.com/gitlab-org/gitlab-foss', $result); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_format_gitlab_http_remotes() | ||
{ | ||
$url = 'https://gitlab.com/gitlab-org/gitlab-foss.git'; | ||
|
||
$result = RemoteUrlTransformer::transform($url); | ||
|
||
$this->assertEquals('gitlab.com/gitlab-org/gitlab-foss', $result); | ||
} | ||
} |