Completed
Push — master ( 2704f9...f273e8 )
by Tomáš
02:19
created

RegisterMigrationsEventSubscriber   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 46
loc 46
ccs 14
cts 15
cp 0.9333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getSubscribedEvents() 4 4 1
A registerMigrations() 11 11 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
/**
4
 * This file is part of Zenify
5
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace Zenify\DoctrineMigrations\EventSubscriber;
9
10
use Doctrine\DBAL\Migrations\Configuration\Configuration;
11
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\ConsoleEvents;
14
use Symfony\Component\Console\Event\ConsoleCommandEvent;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Coding Style introduced by
As per PSR2, there should be exactly one blank line after the last USE statement, 2 were found though.
Loading history...
16
17
18 View Code Duplication
final class RegisterMigrationsEventSubscriber 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...
19
{
20
21
	/**
22
	 * @var Configuration
23
	 */
24
	private $configuration;
25
26
27 6
	public function __construct(Configuration $configuration)
28
	{
29 6
		$this->configuration = $configuration;
30 6
	}
31
32
33
	/**
34
	 * {@inheritdoc}
35
	 */
36 6
	public static function getSubscribedEvents()
37
	{
38 6
		return [ConsoleEvents::COMMAND => 'registerMigrations'];
39
	}
40
41
42 6
	public function registerMigrations(ConsoleCommandEvent $event)
43
	{
44 6
		$command = $event->getCommand();
45 6
		if ( ! $this->isMigrationCommand($command)) {
46
			return;
47
		}
48
49 6
		$this->configuration->registerMigrationsFromDirectory(
50 6
			$this->configuration->getMigrationsDirectory()
51 6
		);
52 6
	}
53
54
55
	/**
56
	 * @return bool
57
	 */
58 6
	private function isMigrationCommand(Command $command)
59
	{
60 6
		return $command instanceof AbstractCommand;
61
	}
62
63
}
1 ignored issue
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
64