Stencil_Recorder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A start_recording() 0 7 1
A finish_recording() 0 6 1
A get_recording() 0 7 2
1
<?php
2
/**
3
 * Recorder to use in a Handler to record output into a variable
4
 *
5
 * @package Stencil
6
 */
7
8
/**
9
 * Class Recorder
10
 */
11
class Stencil_Recorder implements Stencil_Recorder_Interface {
12
	/**
13
	 * Recorded output saved
14
	 *
15
	 * @var string
16
	 */
17
	protected $recorded = '';
18
19
	/**
20
	 * Status
21
	 *
22
	 * @var bool
23
	 */
24
	protected $recording = false;
25
26
	/**
27
	 * Start recording
28
	 */
29
	public function start_recording() {
30
		$this->recorded = '';
31
32
		ob_start();
33
34
		$this->recording = true;
35
	}
36
37
	/**
38
	 * Finish recording and return recorded data
39
	 *
40
	 * @return mixed
41
	 */
42
	public function finish_recording() {
43
		$this->recorded  = ob_get_clean();
44
		$this->recording = false;
45
46
		return $this->get_recording();
47
	}
48
49
	/**
50
	 * Get the recorded data
51
	 *
52
	 * @return mixed
53
	 * @throws LogicException When we are still recording.
54
	 */
55
	public function get_recording() {
56
		if ( $this->recording ) {
57
			throw new LogicException( 'Tried to get recorded output while still recording.' );
58
		}
59
60
		return $this->recorded;
61
	}
62
}
63