SetConsoleOutputEventSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 38
loc 38
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getSubscribedEvents() 4 4 1
A setOutputWriter() 9 9 2
A isMigrationCommand() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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