SetConsoleOutputEventSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Zenify
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Zenify\DoctrineMigrations\EventSubscriber;
11
12
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand;
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\ConsoleEvents;
15
use Symfony\Component\Console\Event\ConsoleCommandEvent;
16
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17
use Zenify\DoctrineMigrations\OutputWriter;
18
19
20 View Code Duplication
final class SetConsoleOutputEventSubscriber implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
23
	/**
24
	 * @var OutputWriter
25
	 */
26
	private $outputWriter;
27 6
28
29 6
	public function __construct(OutputWriter $outputWriter)
30 6
	{
31
		$this->outputWriter = $outputWriter;
32
	}
33
34
35
	public static function getSubscribedEvents() : array
36 2
	{
37
		return [ConsoleEvents::COMMAND => 'setOutputWriter'];
38 2
	}
39
40
41
	public function setOutputWriter(ConsoleCommandEvent $event)
42 6
	{
43
		$command = $event->getCommand();
44 6
		if ( ! $this->isMigrationCommand($command)) {
45 6
			return;
46
		}
47
48
		$this->outputWriter->setConsoleOutput($event->getOutput());
49 6
	}
50 6
51
52
	private function isMigrationCommand(Command $command) : bool
53
	{
54
		return $command instanceof AbstractCommand;
55
	}
56 6
57
}
58