PjaxHelper::instance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of the slince/cakephp-pjax package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\Pjax\Helper;
12
13
use Cake\Network\Request;
14
15
final class PjaxHelper
16
{
17
    /**
18
     * @var static
19
     */
20
    private static $instance;
21
22
    /**
23
     * Checks whether the request is pjax.
24
     *
25
     * @param Request $request
26
     *
27
     * @return bool
28
     */
29
    public function isPjaxRequest(Request $request)
30
    {
31
        return (bool) $request->getHeaderLine('X-PJAX');
32
    }
33
34
    /**
35
     * Get container.
36
     *
37
     * @param Request $request
38
     *
39
     * @return string
40
     */
41
    public function getContainer(Request $request)
42
    {
43
        return $request->getHeaderLine('X-PJAX-Container');
44
    }
45
46
    /**
47
     * Creates the instance.
48
     *
49
     * @return PjaxHelper
50
     */
51
    public static function instance()
52
    {
53
        if (static::$instance) {
0 ignored issues
show
Comprehensibility introduced by
Since Slince\Pjax\Helper\PjaxHelper is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
54
            return static::$instance;
0 ignored issues
show
Comprehensibility introduced by
Since Slince\Pjax\Helper\PjaxHelper is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
55
        }
56
57
        return static::$instance = new static();
0 ignored issues
show
Comprehensibility introduced by
Since Slince\Pjax\Helper\PjaxHelper is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
58
    }
59
}
60