mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Use early return
This commit is contained in:
parent
a56e08d4ff
commit
a5a2daa993
@ -46,17 +46,19 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
public static function afterAnalysis(
|
||||
AfterAnalysisEvent $event
|
||||
): void {
|
||||
$config = $event->getCodebase()->config;
|
||||
|
||||
if (!function_exists('curl_init')) {
|
||||
fwrite(STDERR, 'No curl found, cannot send data to ' . $config->shepherd_host . PHP_EOL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$codebase = $event->getCodebase();
|
||||
$issues = $event->getIssues();
|
||||
$build_info = $event->getBuildInfo();
|
||||
$source_control_info = $event->getSourceControlInfo();
|
||||
|
||||
if (!function_exists('curl_init')) {
|
||||
fwrite(STDERR, 'No curl found, cannot send data to ' . $codebase->config->shepherd_host . PHP_EOL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$source_control_data = $source_control_info ? $source_control_info->toArray() : [];
|
||||
|
||||
if (!$source_control_data && isset($build_info['git']) && is_array($build_info['git'])) {
|
||||
@ -65,7 +67,10 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
|
||||
unset($build_info['git']);
|
||||
|
||||
if ($build_info) {
|
||||
if ($build_info === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$normalized_data = $issues === [] ? [] : array_filter(
|
||||
array_merge(...array_values($issues)),
|
||||
static fn(IssueData $i): bool => $i->severity === 'error',
|
||||
@ -82,7 +87,7 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
$payload = json_encode($data, JSON_THROW_ON_ERROR);
|
||||
|
||||
/** @psalm-suppress DeprecatedProperty */
|
||||
$base_address = $codebase->config->shepherd_host;
|
||||
$base_address = $config->shepherd_host;
|
||||
|
||||
if (parse_url($base_address, PHP_URL_SCHEME) === null) {
|
||||
$base_address = 'https://' . $base_address;
|
||||
@ -117,7 +122,7 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
|
||||
$response_status_code = $curl_info['http_code'];
|
||||
if ($response_status_code >= 200 && $response_status_code < 300) {
|
||||
$shepherd_host = parse_url($codebase->config->shepherd_endpoint, PHP_URL_HOST);
|
||||
$shepherd_host = parse_url($config->shepherd_endpoint, PHP_URL_HOST);
|
||||
|
||||
fwrite(STDERR, "🐑 results sent to $shepherd_host 🐑" . PHP_EOL);
|
||||
return;
|
||||
@ -133,7 +138,6 @@ final class Shepherd implements AfterAnalysisInterface
|
||||
$response_content = is_string($curl_result) ? strip_tags($curl_result) : 'n/a';
|
||||
fwrite(STDERR, "Shepherd response: $response_content\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $ch
|
||||
|
Loading…
x
Reference in New Issue
Block a user