File MultiHttpClient.php
has 479 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* HTTP service client
*
* This program is free software; you can redistribute it and/or modify
Method getCurlHandle
has 108 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getCurlHandle( array &$req, array $opts ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_PROXY, $req['proxy'] ?? $this->proxy );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, intval( $opts['connTimeout'] * 1e3 ) );
Function runMultiHttp
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
private function runMultiHttp( array $reqs, array $opts = [] ) {
$httpOptions = [
'timeout' => $opts['reqTimeout'] ?? $this->reqTimeout,
'connectTimeout' => $opts['connTimeout'] ?? $this->connTimeout,
'logger' => $this->logger,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getCurlHandle
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
protected function getCurlHandle( array &$req, array $opts ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_PROXY, $req['proxy'] ?? $this->proxy );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT_MS, intval( $opts['connTimeout'] * 1e3 ) );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method runMultiCurl
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function runMultiCurl( array $reqs, array $opts ) {
$chm = $this->getCurlMulti( $opts );
$selectTimeout = $this->getSelectTimeout( $opts );
Function normalizeRequests
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeRequests( array &$reqs ) {
foreach ( $reqs as &$req ) {
$req['response'] = [
'code' => 0,
'reason' => '',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function runMultiCurl
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function runMultiCurl( array $reqs, array $opts ) {
$chm = $this->getCurlMulti( $opts );
$selectTimeout = $this->getSelectTimeout( $opts );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method runMultiHttp
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function runMultiHttp( array $reqs, array $opts = [] ) {
$httpOptions = [
'timeout' => $opts['reqTimeout'] ?? $this->reqTimeout,
'connectTimeout' => $opts['connTimeout'] ?? $this->connTimeout,
'logger' => $this->logger,
Method normalizeRequests
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function normalizeRequests( array &$reqs ) {
foreach ( $reqs as &$req ) {
$req['response'] = [
'code' => 0,
'reason' => '',
Function isLocalURL
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function isLocalURL( $url ) {
if ( !$this->localVirtualHosts ) {
// Shortcut
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method runMulti
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function runMulti( array $reqs, array $opts = [] ) {
$this->normalizeRequests( $reqs );
$opts += [ 'connTimeout' => $this->connTimeout, 'reqTimeout' => $this->reqTimeout ];
if ( $this->maxConnTimeout && $opts['connTimeout'] > $this->maxConnTimeout ) {
Function runMulti
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function runMulti( array $reqs, array $opts = [] ) {
$this->normalizeRequests( $reqs );
$opts += [ 'connTimeout' => $this->connTimeout, 'reqTimeout' => $this->reqTimeout ];
if ( $this->maxConnTimeout && $opts['connTimeout'] > $this->maxConnTimeout ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getCurlMulti
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function getCurlMulti( array $opts ) {
if ( !$this->cmh ) {
$cmh = curl_multi_init();
// Limit the size of the idle connection cache such that consecutive parallel
// request batches to the same host can avoid having to keep making connections
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return strlen( $data );
Avoid too many return
statements within this method. Open
return $ch;
Avoid too many return
statements within this method. Open
return fwrite( $req['stream'], $data );
Function __construct
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function __construct( array $options ) {
if ( isset( $options['caBundlePath'] ) ) {
$this->caBundlePath = $options['caBundlePath'];
if ( !file_exists( $this->caBundlePath ) ) {
throw new InvalidArgumentException( "Cannot find CA bundle: " . $this->caBundlePath );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"