Completed
Push — master ( 5d29b3...11effe )
by Nazar
04:11
created

Output   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 41
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get_buffer() 0 3 1
A doWrite() 0 14 2
A __destruct() 0 3 1
1
<?php
2
/**
3
 * @package   Composer
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs\modules\Composer;
10
use
11
	cs\Event,
12
	Symfony\Component\Console\Formatter\OutputFormatterInterface,
13
	Symfony\Component\Console\Output\Output as Symfony_output;
14
15
/**
16
 * Provides next events:
17
 *  Composer/update_progress
18
 *  [
19
 *   'message' => $message,     //Current message targeted for output
20
 *   'buffer'  => $this->buffer //Total output
21
 *  ]
22
 */
23
class Output extends Symfony_output {
24
	/**
25
	 * @var string
26
	 */
27
	protected $buffer = '';
28
	/**
29
	 * @var resource
30
	 */
31
	protected $stream;
32
	function __construct ($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null) {
33
		$this->stream = fopen(STORAGE.'/Composer/last_execution.log', 'w');
34
		parent::__construct($verbosity, $decorated, $formatter);
35
	}
36
	/**
37
	 * @return string
38
	 */
39
	function get_buffer () {
40
		return $this->buffer;
41
	}
42
	/**
43
	 * @param string $message
44
	 * @param bool   $newline
45
	 */
46
	protected function doWrite ($message, $newline) {
47
		if ($newline) {
48
			$message .= "\n";
49
		}
50
		fwrite($this->stream, $message);
51
		$this->buffer .= $message;
52
		Event::instance()->fire(
53
			'Composer/update_progress',
54
			[
55
				'message' => $message,
56
				'buffer'  => $this->buffer
57
			]
58
		);
59
	}
60
	function __destruct () {
61
		fclose($this->stream);
62
	}
63
}
64