Completed
Push — master ( 849954...8f1795 )
by David
9s
created

src/CacheManager.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle;
13
14
use FOS\HttpCache\CacheInvalidator;
15
use FOS\HttpCache\ProxyClient\ProxyClient;
16
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
17
18
/**
19
 * The CacheManager is a CacheInvalidator but adds symfony Route support and
20
 * response tagging to the framework agnostic FOS\HttpCache\CacheInvalidator.
21
 *
22
 * @author David de Boer <[email protected]>
23
 */
24
class CacheManager extends CacheInvalidator
25
{
26
    /**
27
     * @var UrlGeneratorInterface
28
     */
29
    private $urlGenerator;
30
31
    /**
32
     * What type of urls to generate.
33
     *
34
     * @var bool|string
35
     */
36
    private $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH;
37
38
    /**
39
     * Constructor.
40
     *
41
     * @param ProxyClient           $cache        HTTP cache proxy client
42
     * @param UrlGeneratorInterface $urlGenerator Symfony route generator
43
     */
44 13
    public function __construct(ProxyClient $cache, UrlGeneratorInterface $urlGenerator)
45
    {
46 13
        parent::__construct($cache);
47 13
        $this->urlGenerator = $urlGenerator;
48 13
    }
49
50
    /**
51
     * Set what type of URLs to generate.
52
     *
53
     * @param bool|string $generateUrlType One of the constants in UrlGeneratorInterface
54
     */
55 11
    public function setGenerateUrlType($generateUrlType)
56
    {
57 11
        $this->generateUrlType = $generateUrlType;
58 11
    }
59
60
    /**
61
     * Invalidate a route.
62
     *
63
     * @param string $name       Route name
64
     * @param array  $parameters Route parameters (optional)
65
     * @param array  $headers    Extra HTTP headers to send to the caching proxy (optional)
66
     *
67
     * @return $this
68
     */
69 1
    public function invalidateRoute($name, array $parameters = [], array $headers = [])
70
    {
71 1
        $this->invalidatePath($this->urlGenerator->generate($name, $parameters, $this->generateUrlType), $headers);
0 ignored issues
show
$this->generateUrlType is of type boolean|string, but the function expects a integer.

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...
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * Refresh a route.
78
     *
79
     * @param string $route      Route name
80
     * @param array  $parameters Route parameters (optional)
81
     * @param array  $headers    Extra HTTP headers to send to the caching proxy (optional)
82
     *
83
     * @return $this
84
     */
85 1
    public function refreshRoute($route, array $parameters = [], array $headers = [])
86
    {
87 1
        $this->refreshPath($this->urlGenerator->generate($route, $parameters, $this->generateUrlType), $headers);
0 ignored issues
show
$this->generateUrlType is of type boolean|string, but the function expects a integer.

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...
88
89 1
        return $this;
90
    }
91
}
92