WPThemeReview/Sniffs/Plugins/CorrectTGMPAVersionSniff.php
protected function update_current_version() {
		if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) || true === $this->gh_call_made ) {
			return;
		}

		$api_url     = self::GITHUB_TGMPA_API_URL;
		$oauth_token = false;
		if ( '' !== $this->github_oauth_token && is_string( $this->github_oauth_token ) ) {
			$oauth_token = $this->github_oauth_token;
		} elseif ( false !== getenv( 'GITHUB_OAUTH_TOKEN' ) ) {
			$oauth_token = getenv( 'GITHUB_OAUTH_TOKEN' );
		}

		if ( false !== $oauth_token ) {
			$api_url .= sprintf( self::GITHUB_API_OAUTH_QUERY, $oauth_token );
		}

		$stream_options = array(
			'http' => array(
				'method'           => 'GET',
				'user_agent'       => 'WordPress-Coding-Standards/Theme-Review-Sniffs',
				'protocol_version' => 1.1,
			),
		);
		$stream_context = stream_context_create( $stream_options );
		$response       = file_get_contents( $api_url, false, $stream_context );
		$headers        = $this->parse_response_headers( $http_response_header );

		// Check for invalid oAuth token response.
		if ( 401 === $headers['response_code'] && false !== $oauth_token ) {
			$this->phpcsFile->addWarning(
				'The GITHUB_OAUTH_TOKEN you provided is invalid. Please update the token in your custom ruleset or environment properties.',
				0,
				'githubOauthTokenInvalid'
			);
			$this->oauth_error = false;
			return;
		}

		// Check for rate limit error response.
		if ( 403 === $headers['response_code'] && '0' === $headers['X-RateLimit-Remaining'] ) {
			// @todo Add link to GH wiki page documenting the properties.
			$this->phpcsFile->addWarning(
				'You are running PHPCS more than 60 times per hour. You may want to consider setting the `github_oauth_token` property in your custom ruleset for Theme Review. For more information see: ... (GH wiki page).',
				0,
				'githubRateLimitReached'
			);
			$this->rate_limit_error = false;
			return;
		}

		if ( 200 !== $headers['response_code'] ) {
			// Something unexpected going on, just ignore it.
			return;
		}

		// Ok, we have received a valid response.
		$response = json_decode( $response );
		if ( ! empty( $response->tag_name ) && ( ! isset( $response->prerelease ) || false === $response->prerelease ) ) {
			// Should there be a check for `v` at the start of a version number ?
			$this->current_version = $response->tag_name;
		}
	}
protected function update_current_version() {
		if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) || true === $this->gh_call_made ) {
			return;
		}

		$api_url     = self::GITHUB_TGMPA_API_URL;
		$oauth_token = false;
		if ( '' !== $this->github_oauth_token && is_string( $this->github_oauth_token ) ) {
			$oauth_token = $this->github_oauth_token;
		} elseif ( false !== getenv( 'GITHUB_OAUTH_TOKEN' ) ) {
			$oauth_token = getenv( 'GITHUB_OAUTH_TOKEN' );
		}

		if ( false !== $oauth_token ) {
			$api_url .= sprintf( self::GITHUB_API_OAUTH_QUERY, $oauth_token );
		}

		$stream_options = array(
			'http' => array(
				'method'           => 'GET',
				'user_agent'       => 'WordPress-Coding-Standards/Theme-Review-Sniffs',
				'protocol_version' => 1.1,
			),
		);
		$stream_context = stream_context_create( $stream_options );
		$response       = file_get_contents( $api_url, false, $stream_context );
		$headers        = $this->parse_response_headers( $http_response_header );

		// Check for invalid oAuth token response.
		if ( 401 === $headers['response_code'] && false !== $oauth_token ) {
			$this->phpcsFile->addWarning(
				'The GITHUB_OAUTH_TOKEN you provided is invalid. Please update the token in your custom ruleset or environment properties.',
				0,
				'githubOauthTokenInvalid'
			);
			$this->oauth_error = false;
			return;
		}

		// Check for rate limit error response.
		if ( 403 === $headers['response_code'] && '0' === $headers['X-RateLimit-Remaining'] ) {
			// @todo Add link to GH wiki page documenting the properties.
			$this->phpcsFile->addWarning(
				'You are running PHPCS more than 60 times per hour. You may want to consider setting the `github_oauth_token` property in your custom ruleset for Theme Review. For more information see: ... (GH wiki page).',
				0,
				'githubRateLimitReached'
			);
			$this->rate_limit_error = false;
			return;
		}

		if ( 200 !== $headers['response_code'] ) {
			// Something unexpected going on, just ignore it.
			return;
		}

		// Ok, we have received a valid response.
		$response = json_decode( $response );
		if ( ! empty( $response->tag_name ) && ( ! isset( $response->prerelease ) || false === $response->prerelease ) ) {
			// Should there be a check for `v` at the start of a version number ?
			$this->current_version = $response->tag_name;
		}
	}
Get the version number (tag_name) of the latest TGMPA release from the GitHub API.