Completed
Branch FET/better-paypal-error-unauth... (0c8498)
by
unknown
34:21 queued 26:06
created

EventEditorHeartbeat   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A heartbeatResponse() 0 13 2
1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\ajax;
4
5
use EE_Environment_Config;
6
use EventEspresso\core\domain\Domain;
7
8
/**
9
 * Class EventEditorHeartbeat
10
 * Handles WordPress Heartbeat AJAX requests for the Espresso Event Editor
11
 *
12
 * @package EventEspresso\core\domain\services\admin\ajax
13
 * @author  Brent Christensen
14
 * @since   $VID:$
15
 */
16
class EventEditorHeartbeat
17
{
18
19
    /**
20
     * @var Domain $domain
21
     */
22
    protected $domain;
23
24
    /**
25
     * @var EE_Environment_Config $environment
26
     */
27
    protected $environment;
28
29
30
    /**
31
     * EventEditorHeartbeat constructor.
32
     *
33
     * @param Domain                $domain
34
     * @param EE_Environment_Config $environment
35
     */
36
    public function __construct(Domain $domain, EE_Environment_Config $environment)
37
    {
38
        $this->domain = $domain;
39
        $this->environment = $environment;
40
        if ($this->domain->isCaffeinated()) {
41
            add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
        }
43
    }
44
45
46
    /**
47
     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
     * accordingly.
49
     *
50
     * @param array $response The existing heartbeat response array.
51
     * @param array $data     The incoming data package.
52
     * @return array  possibly appended response.
53
     */
54
    public function heartbeatResponse($response, $data)
55
    {
56
        /**
57
         * check whether count of tickets is approaching the potential
58
         * limits for the server.
59
         */
60
        if (! empty($data['input_count'])) {
61
            $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
                $data['input_count']
63
            );
64
        }
65
        return $response;
66
    }
67
}
68