Completed
Pull Request — master (#952)
by Kévin
03:35 queued 27s
created

VarnishPurger::purge()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\HttpCache;
13
14
use GuzzleHttp\ClientInterface;
15
16
final class VarnishPurger implements PurgerInterface
17
{
18
    private $guzzle;
19
20
    public function __construct(ClientInterface $guzzle)
21
    {
22
        $this->guzzle = $guzzle;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function purge(array $iris)
29
    {
30
        if (!$iris) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $iris of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
31
            return;
32
        }
33
34
        $hashes = array_map('md5', $iris);
35
        $regex = isset($hashes[1]) ? sprintf('(%s)', implode('|', $hashes)) : $hashes[0];
36
37
        $this->guzzle->sendAsync($this->guzzle->request('BAN', '', ['headers' => ['X-Ban-Regex' => $regex]]));
0 ignored issues
show
Documentation introduced by
$this->guzzle->request('...Ban-Regex' => $regex))) is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a object<Psr\Http\Message\RequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
}
40