diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 156edf921..8b8cef613 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -543,7 +543,7 @@ class Config * @var string * @deprecated Please use {@see self::$shepherd_endpoint} instead. Property will be removed in Psalm 6. */ - public $shepherd_host = 'https://shepherd.dev/hooks/psalm/'; + public $shepherd_host = 'shepherd.dev'; /** * @var string diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index c4d9007f5..1df9e4228 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -306,32 +306,7 @@ final class Psalm ? $options['find-references-to'] : null; - $is_shepherd_enabled = (bool) ($options['shepherd'] ?? getenv('PSALM_SHEPHERD')); - if ($is_shepherd_enabled) { - $plugins[] = Path::canonicalize(__DIR__ . '/../../Plugin/Shepherd.php'); - - $custom_shepherd_host = ($options['shepherd'] ?? getenv('PSALM_SHEPHERD')) ?: getenv('PSALM_SHEPHERD_HOST'); - - $is_valid_custom_shepherd_endpoint = is_string($custom_shepherd_host) && strlen($custom_shepherd_host) > 2; - if ($is_valid_custom_shepherd_endpoint) { - if (parse_url($custom_shepherd_host, PHP_URL_SCHEME) === null) { - $custom_shepherd_host = 'https://' . $custom_shepherd_host; - } - - $config->shepherd_host = $custom_shepherd_host; - $config->shepherd_endpoint = $custom_shepherd_host; - - if (is_string(getenv('PSALM_SHEPHERD_HOST'))) { - fwrite( - STDERR, - 'PSALM_SHEPHERD_HOST env variable is deprecated and will be removed in Psalm 6.' - .' Please use "--shepherd" cli option or PSALM_SHEPHERD env variable' - .' to specify a custom Shepherd host/endpoint.' - . PHP_EOL, - ); - } - } - } + self::configureShepherd($options, $plugins); if (isset($options['clear-cache'])) { self::clearCache($config); @@ -1170,6 +1145,51 @@ final class Psalm } } + private static function configureShepherd(Config $config, array $options, array &$plugins): void + { + if (is_string(getenv('PSALM_SHEPHERD_HOST'))) { // remove this block in Psalm 6 + fwrite( + STDERR, + 'PSALM_SHEPHERD_HOST env variable is deprecated and will be removed in Psalm 6.' + .' Please use "--shepherd" cli option or PSALM_SHEPHERD env variable' + .' to specify a custom Shepherd host/endpoint.' + . PHP_EOL, + ); + } + + $is_shepherd_enabled = (bool) ($options['shepherd'] ?? getenv('PSALM_SHEPHERD')); + if (! $is_shepherd_enabled) { + return; + } + + $plugins[] = Path::canonicalize(__DIR__ . '/../../Plugin/Shepherd.php'); + + $custom_shepherd_endpoint = $options['shepherd'] ?? getenv('PSALM_SHEPHERD'); + if (is_string($custom_shepherd_endpoint) && strlen($custom_shepherd_endpoint) > 2) { + if (parse_url($custom_shepherd_endpoint, PHP_URL_SCHEME) === null) { + $custom_shepherd_endpoint = 'https://' . $custom_shepherd_endpoint; + } + + $config->shepherd_endpoint = $custom_shepherd_endpoint; + $config->shepherd_host = str_replace('/hooks/psalm', '', $custom_shepherd_endpoint); + + return; + } + + // Legacy part, will be removed in Psalm 6 + $custom_shepherd_host = getenv('PSALM_SHEPHERD_HOST'); + + $is_valid_custom_shepherd_endpoint = is_string($custom_shepherd_host); + if ($is_valid_custom_shepherd_endpoint) { + if (parse_url($custom_shepherd_host, PHP_URL_SCHEME) === null) { + $custom_shepherd_host = 'https://' . $custom_shepherd_host; + } + + $config->shepherd_endpoint = $custom_shepherd_host . '/hooks/psalm'; + $config->shepherd_host = $custom_shepherd_host; + } + } + private static function generateStubs( array $options, Providers $providers, diff --git a/src/Psalm/Plugin/Shepherd.php b/src/Psalm/Plugin/Shepherd.php index 0d6f542a2..6631f7b3f 100644 --- a/src/Psalm/Plugin/Shepherd.php +++ b/src/Psalm/Plugin/Shepherd.php @@ -81,7 +81,7 @@ final class Shepherd implements AfterAnalysisInterface $payload = json_encode($data, JSON_THROW_ON_ERROR); // Prepare new cURL resource - $ch = curl_init($codebase->config->shepherd_endpoint); + $ch = curl_init($base_address . '/hooks/psalm'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true);