VerboseReporter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 46
ccs 0
cts 30
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A started() 0 5 1
A endedSuccessfully() 0 3 1
A endedWithError() 0 4 1
A stepStarted() 0 4 1
A stepCompleted() 0 11 2
1
<?php
2
3
namespace Queryr\Replicator\Cli\Import;
4
5
use Queryr\Replicator\Importer\PageImportReporter;
6
use Queryr\Replicator\Model\EntityPage;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class VerboseReporter implements PageImportReporter {
14
15
	private $output;
16
	private $veryVerbose;
17
18
	private $number = 0;
19
	private $stepStartTime;
20
21
	public function __construct( OutputInterface $output, $veryVerbose = false ) {
22
		$this->output = $output;
23
		$this->veryVerbose = $veryVerbose;
24
	}
25
26
	public function started( EntityPage $entityPage ) {
27
		$this->output->writeln(
28
			"\n<info>Importing entity " . ++$this->number . ': ' . $entityPage->getTitle() . '...</info>'
29
		);
30
	}
31
32
	public function endedSuccessfully() {
33
		$this->output->writeln( "<info>\t Entity imported.</info>" );
34
	}
35
36
	public function endedWithError( \Exception $ex ) {
37
		$this->output->writeln( '<error>FAILED!</error>' );
38
		$this->output->writeln( "\t <error>Error details: " . $ex->getMessage() . '</error>' );
39
	}
40
41
	public function stepStarted( string $message ) {
42
		$this->stepStartTime = microtime( true );
43
		$this->output->write( "<comment>\t* $message... </comment>" );
44
	}
45
46
	public function stepCompleted() {
47
		if ( $this->veryVerbose ) {
48
			$ms = round( ( microtime( true ) - $this->stepStartTime ) * 1000, 2 );
49
			$details = " ($ms ms)";
50
		}
51
		else {
52
			$details = '';
53
		}
54
55
		$this->output->writeln( "<comment>done$details.</comment>" );
56
	}
57
58
}