Issues (75)

src/SymfonyCache/RefreshListener.php (2 issues)

1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache 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\HttpCache\SymfonyCache;
13
14
use Symfony\Component\HttpFoundation\Request;
15
16
/**
17
 * Refresh handler for the symfony built-in HttpCache.
18
 *
19
 * To use this handler, make sure that your HttpCache makes the fetch method
20
 * public.
21
 *
22
 * @author David Buchmann <[email protected]>
23
 *
24
 * {@inheritdoc}
25
 */
26
class RefreshListener extends AccessControlledListener
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34 1
            Events::PRE_HANDLE => 'handleRefresh',
35
        ];
36
    }
37
38
    /**
39
     * Look at cacheable requests and handle refresh requests.
40
     *
41
     * When the request comes from a non-authorized client, ignore refresh to
42
     * let normal lookup happen.
43
     */
44 6
    public function handleRefresh(CacheEvent $event)
45
    {
46 6
        $request = $event->getRequest();
47
        // BC - we can drop this check when we only support Symfony 3.1 and newer
48 6
        $cacheable = method_exists(Request::class, 'isMethodCacheable')
49 6
            ? $request->isMethodCacheable()
50 6
            : $request->isMethodSafe(false);
0 ignored issues
show
The call to Symfony\Component\HttpFo...Request::isMethodSafe() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            : $request->/** @scrutinizer ignore-call */ isMethodSafe(false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
51
52 6
        if (!$cacheable
53 5
            || !$request->isNoCache()
54 6
            || !$this->isRequestAllowed($request)
55
        ) {
56 5
            return;
57
        }
58
59 1
        $event->setResponse(
60 1
            $event->getKernel()->fetch($request)
0 ignored issues
show
The method fetch() does not exist on FOS\HttpCache\SymfonyCache\CacheInvalidation. Since it exists in all sub-types, consider adding an abstract or default implementation to FOS\HttpCache\SymfonyCache\CacheInvalidation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            $event->getKernel()->/** @scrutinizer ignore-call */ fetch($request)
Loading history...
61
        );
62 1
    }
63
}
64