mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -10,12 +10,7 @@
|
||||
|
||||
abstract class AbstractSourceControlProvider implements SourceControlProvider
|
||||
{
|
||||
protected SourceControl $sourceControl;
|
||||
|
||||
public function __construct(SourceControl $sourceControl)
|
||||
{
|
||||
$this->sourceControl = $sourceControl;
|
||||
}
|
||||
public function __construct(protected SourceControl $sourceControl) {}
|
||||
|
||||
public function createRules(array $input): array
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public function connect(): bool
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRepo(?string $repo = null): mixed
|
||||
public function getRepo(string $repo): mixed
|
||||
{
|
||||
$res = Http::withHeaders($this->getAuthenticationHeaders())
|
||||
->get($this->apiUrl."/repositories/$repo");
|
||||
@ -163,6 +163,9 @@ public function deployKey(string $title, string $repo, string $key): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getCommitter(string $raw): array
|
||||
{
|
||||
$committer = explode(' <', $raw);
|
||||
@ -173,6 +176,9 @@ protected function getCommitter(string $raw): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getAuthenticationHeaders(): array
|
||||
{
|
||||
$username = $this->data()['username'];
|
||||
|
@ -29,13 +29,9 @@ public function connect(): bool
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRepo(?string $repo = null): mixed
|
||||
public function getRepo(string $repo): mixed
|
||||
{
|
||||
if ($repo) {
|
||||
$url = $this->apiUrl.'/repos/'.$repo;
|
||||
} else {
|
||||
$url = $this->apiUrl.'/user/repos';
|
||||
}
|
||||
$url = $repo !== '' && $repo !== '0' ? $this->apiUrl.'/repos/'.$repo : $this->apiUrl.'/user/repos';
|
||||
$res = Http::withHeaders([
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
'Authorization' => 'Bearer '.$this->data()['token'],
|
||||
|
@ -41,9 +41,9 @@ public function connect(): bool
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRepo(?string $repo = null): mixed
|
||||
public function getRepo(string $repo): mixed
|
||||
{
|
||||
$repository = $repo ? urlencode($repo) : null;
|
||||
$repository = $repo !== '' && $repo !== '0' ? urlencode($repo) : null;
|
||||
$res = Http::withToken($this->data()['token'])
|
||||
->get($this->getApiUrl().'/projects/'.$repository.'/repository/commits');
|
||||
|
||||
@ -54,7 +54,7 @@ public function getRepo(?string $repo = null): mixed
|
||||
|
||||
public function fullRepoUrl(string $repo, string $key): string
|
||||
{
|
||||
$host = parse_url($this->getApiUrl())['host'];
|
||||
$host = parse_url($this->getApiUrl())['host'] ?? 'gitlab.com';
|
||||
|
||||
return sprintf('git@%s-%s:%s.git', $host, $key, $repo);
|
||||
}
|
||||
@ -170,9 +170,7 @@ public function deployKey(string $title, string $repo, string $key): void
|
||||
|
||||
public function getApiUrl(): string
|
||||
{
|
||||
$host = $this->sourceControl->url === null
|
||||
? $this->defaultApiHost
|
||||
: $this->sourceControl->url;
|
||||
$host = $this->sourceControl->url ?? $this->defaultApiHost;
|
||||
|
||||
return $host.$this->apiVersion;
|
||||
}
|
||||
|
@ -7,22 +7,47 @@
|
||||
|
||||
interface SourceControlProvider
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function createRules(array $input): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function createData(array $input): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function editRules(array $input): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function editData(array $input): array;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function data(): array;
|
||||
|
||||
public function connect(): bool;
|
||||
|
||||
public function getRepo(?string $repo = null): mixed;
|
||||
public function getRepo(string $repo): mixed;
|
||||
|
||||
public function fullRepoUrl(string $repo, string $key): string;
|
||||
|
||||
/**
|
||||
* @param array<mixed> $events
|
||||
* @return array<string, mixed>
|
||||
*
|
||||
* @throws \App\Exceptions\FailedToDeployGitHook
|
||||
*/
|
||||
public function deployHook(string $repo, array $events, string $secret): array;
|
||||
|
||||
/**
|
||||
@ -30,6 +55,9 @@ public function deployHook(string $repo, array $events, string $secret): array;
|
||||
*/
|
||||
public function destroyHook(string $repo, string $hookId): void;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getLastCommit(string $repo, string $branch): ?array;
|
||||
|
||||
/**
|
||||
@ -37,5 +65,8 @@ public function getLastCommit(string $repo, string $branch): ?array;
|
||||
*/
|
||||
public function deployKey(string $title, string $repo, string $key): void;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
*/
|
||||
public function getWebhookBranch(array $payload): string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user