Completed
Push — zend-sentry-inject-static-nonc... ( bd26f1 )
by Markus
10:45
created

ZendSentry::getCSPNonce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Bright Answer ZendSentry
5
 *
6
 * This source file is part of the Bright Answer ZendSentry package
7
 *
8
 * @package    ZendSentry\ZendSentry
9
 * @license    MIT License {@link /docs/LICENSE}
10
 * @copyright  Copyright (c) 2018, Bright Answer OÜ
11
 */
12
13
namespace ZendSentry;
14
15
use Raven_Client as RavenClient;
16
use Raven_ErrorHandler as RavenErrorHandler;
17
18
/**
19
 * @package    ZendSentry\ZendSentry
20
 */
21
class ZendSentry
22
{
23
    /**
24
     * @var RavenClient $ravenClient
25
     */
26
    private $ravenClient;
27
28
    /**
29
     * @var RavenErrorHandler $ravenErrorHandler
30
     */
31
    private $ravenErrorHandler;
32
33
    /**
34
     * @var string $nonce
35
     */
36
    private static $nonce;
37
38
    /**
39
     * @param RavenClient $ravenClient
40
     * @param RavenErrorHandler $ravenErrorHandler
41
     */
42
    public function __construct(RavenClient $ravenClient, RavenErrorHandler $ravenErrorHandler = null)
43
    {
44
        $this->ravenClient = $ravenClient;
45
        $this->setOrLoadRavenErrorHandler($ravenErrorHandler);
46
    }
47
48
    /**
49
     * @param bool   $callExistingHandler
50
     * @param int    $errorReporting
51
     *
52
     * @return ZendSentry
53
     */
54
    public function registerErrorHandler($callExistingHandler = true, $errorReporting = E_ALL): ZendSentry
55
    {
56
        $this->ravenErrorHandler->registerErrorHandler($callExistingHandler, $errorReporting);
0 ignored issues
show
Documentation introduced by
$errorReporting is of type integer, but the function expects a array|null.

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...
57
        return $this;
58
    }
59
60
    /**
61
     * @param bool $callExistingHandler
62
     * @return ZendSentry
63
     */
64
    public function registerExceptionHandler($callExistingHandler = true): ZendSentry
65
    {
66
        $this->ravenErrorHandler->registerExceptionHandler($callExistingHandler);
67
        return $this;
68
    }
69
70
    /**
71
     * @param int $reservedMemorySize
72
     * @return ZendSentry
73
     */
74
    public function registerShutdownFunction($reservedMemorySize = 10): ZendSentry
75
    {
76
        $this->ravenErrorHandler->registerShutdownFunction($reservedMemorySize);
77
        return $this;
78
    }
79
80
    /**
81
     * @param null|RavenErrorHandler $ravenErrorHandler
82
     */
83
    private function setOrLoadRavenErrorHandler($ravenErrorHandler): void
84
    {
85
        if ($ravenErrorHandler !== null) {
86
            $this->ravenErrorHandler = $ravenErrorHandler;
87
        } else {
88
            $this->ravenErrorHandler = new RavenErrorHandler($this->ravenClient);
89
        }
90
    }
91
92
    /**
93
     * @param string $nonce
94
     */
95
    public static function setCSPNonce(string $nonce): void
96
    {
97
        self::$nonce = $nonce;
98
    }
99
100
    /**
101
     * @return null|string
102
     */
103
    public function getCSPNonce(): ?string
104
    {
105
        return self::$nonce;
106
    }
107
}