Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DeprecationLoggedHttp
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 _setupCurl
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace CirrusSearch\Elastica;
4
5use Elastica\Connection;
6use Elastica\Transport\Http;
7use MediaWiki\Logger\LoggerFactory;
8use Psr\Log\LoggerInterface;
9
10class DeprecationLoggedHttp extends Http {
11
12    /** @var LoggerInterface */
13    private $logger;
14
15    public function __construct( ?Connection $connection = null ) {
16        parent::__construct( $connection );
17        $this->logger = LoggerFactory::getInstance( 'CirrusSearchDeprecation' );
18    }
19
20    /**
21     * @param resource $curlConnection
22     * @return void
23     */
24    protected function _setupCurl( $curlConnection ): void {
25        parent::_setupCurl( $curlConnection );
26        // @phan-suppress-next-line PhanTypeMismatchArgumentInternal
27        curl_setopt( $curlConnection, CURLOPT_HEADERFUNCTION, function ( $curl, $header ) {
28            // Elasticsearch sends Warning, but seeing lowercase coming in from curl. Didn't
29            // find docs confirming this is standard, do lowercase to have an expectation.
30            if ( str_starts_with( strtolower( $header ), 'warning:' ) ) {
31                $this->logger->warning( $header, [
32                    // A bit awkward, but we want to log a stack trace without
33                    // being too specific about how that happens.
34                    'exception' => new \RuntimeException( $header ),
35                ] );
36            }
37            return strlen( $header );
38        } );
39    }
40}