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\ProxyClientInterface; |
||
16 | use Symfony\Component\HttpFoundation\Response; |
||
17 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
||
18 | |||
19 | /** |
||
20 | * The CacheManager is a CacheInvalidator but adds symfony Route support and |
||
21 | * response tagging to the framework agnostic FOS\HttpCache\CacheInvalidator. |
||
22 | * |
||
23 | * @author David de Boer <[email protected]> |
||
24 | */ |
||
25 | class CacheManager extends CacheInvalidator |
||
26 | { |
||
27 | /** |
||
28 | * @var UrlGeneratorInterface |
||
29 | */ |
||
30 | private $urlGenerator; |
||
31 | |||
32 | /** |
||
33 | * What type of urls to generate. |
||
34 | * |
||
35 | * @var bool|string |
||
36 | */ |
||
37 | private $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param ProxyClientInterface $cache HTTP cache proxy client |
||
43 | * @param UrlGeneratorInterface $urlGenerator Symfony route generator |
||
44 | */ |
||
45 | 11 | public function __construct(ProxyClientInterface $cache, UrlGeneratorInterface $urlGenerator) |
|
46 | { |
||
47 | 11 | parent::__construct($cache); |
|
48 | 11 | $this->urlGenerator = $urlGenerator; |
|
49 | 11 | } |
|
50 | |||
51 | /** |
||
52 | * Set what type of URLs to generate. |
||
53 | * |
||
54 | * @param bool|string $generateUrlType One of the constants in UrlGeneratorInterface |
||
55 | */ |
||
56 | 8 | public function setGenerateUrlType($generateUrlType) |
|
57 | { |
||
58 | 8 | $this->generateUrlType = $generateUrlType; |
|
59 | 8 | } |
|
60 | |||
61 | /** |
||
62 | * Assign cache tags to a response. |
||
63 | * |
||
64 | * @param Response $response |
||
65 | * @param array $tags |
||
66 | * @param bool $replace Whether to replace the current tags on the |
||
67 | * response |
||
68 | * |
||
69 | * @return $this |
||
70 | * |
||
71 | * @deprecated Add tags with TagHandler::addTags and then use TagHandler::tagResponse |
||
72 | */ |
||
73 | 1 | public function tagResponse(Response $response, array $tags, $replace = false) |
|
74 | { |
||
75 | 1 | @trigger_error('The '.__METHOD__.' method is deprecated since version 1.2 and will be removed in 2.0. Use the TagHandler instead.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
|
|||
76 | |||
77 | 1 | View Code Duplication | if (!$replace && $response->headers->has($this->getTagsHeader())) { |
0 ignored issues
–
show
The method
FOS\HttpCache\CacheInvalidator::getTagsHeader() has been deprecated with message: Use TagHandler::getTagsHeaderName instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
78 | 1 | $header = $response->headers->get($this->getTagsHeader()); |
|
0 ignored issues
–
show
The method
FOS\HttpCache\CacheInvalidator::getTagsHeader() has been deprecated with message: Use TagHandler::getTagsHeaderName instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
79 | 1 | if ('' !== $header) { |
|
80 | 1 | $tags = array_merge( |
|
81 | 1 | explode(',', $response->headers->get($this->getTagsHeader())), |
|
0 ignored issues
–
show
The method
FOS\HttpCache\CacheInvalidator::getTagsHeader() has been deprecated with message: Use TagHandler::getTagsHeaderName instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
82 | $tags |
||
83 | ); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | 1 | $uniqueTags = array_unique($tags); |
|
88 | 1 | $response->headers->set($this->getTagsHeader(), implode(',', $uniqueTags)); |
|
0 ignored issues
–
show
The method
FOS\HttpCache\CacheInvalidator::getTagsHeader() has been deprecated with message: Use TagHandler::getTagsHeaderName instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. ![]() |
|||
89 | |||
90 | 1 | return $this; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * Invalidate a route. |
||
95 | * |
||
96 | * @param string $name Route name |
||
97 | * @param array $parameters Route parameters (optional) |
||
98 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | 1 | public function invalidateRoute($name, array $parameters = array(), array $headers = array()) |
|
103 | { |
||
104 | 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);
![]() |
|||
105 | |||
106 | 1 | return $this; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Refresh a route. |
||
111 | * |
||
112 | * @param string $route Route name |
||
113 | * @param array $parameters Route parameters (optional) |
||
114 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
115 | * |
||
116 | * @return $this |
||
117 | */ |
||
118 | 1 | public function refreshRoute($route, array $parameters = array(), array $headers = array()) |
|
119 | { |
||
120 | 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);
![]() |
|||
121 | |||
122 | 1 | return $this; |
|
123 | } |
||
124 | } |
||
125 |
If you suppress an error, we recommend checking for the error condition explicitly: