Completed
Push — master ( 146147...1776d4 )
by Neomerx
01:58
created

FileMigrationRunner   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 21.18 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 18
loc 85
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMigrationsPath() 0 4 1
A setMigrationsPath() 0 6 1
A migrate() 18 18 1
A getMigrationClasses() 0 4 1
A setMigrationClasses() 0 6 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 namespace Limoncello\Application\Data;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Commands\IoInterface;
20
use Limoncello\Contracts\FileSystem\FileSystemInterface;
21
use Psr\Container\ContainerInterface;
22
23
/**
24
 * @package Limoncello\Application
25
 */
26
class FileMigrationRunner extends BaseMigrationRunner
27
{
28
    /**
29
     * @var string
30
     */
31
    private $migrationsPath;
32
33
    /**
34
     * @var string[]
35
     */
36
    private $migrationClasses;
37
38
    /**
39
     * @param IoInterface $inOut
40
     * @param string      $migrationsPath
41
     */
42 2
    public function __construct(IoInterface $inOut, string $migrationsPath)
43
    {
44 2
        parent::__construct($inOut);
45
46 2
        $this->setMigrationsPath($migrationsPath);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 1 View Code Duplication
    public function migrate(ContainerInterface $container): void
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        // read & remember classes to migrate...
55 1
        assert($container->has(FileSystemInterface::class) === true);
56
        /** @var FileSystemInterface $fileSystem */
57 1
        $fileSystem = $container->get(FileSystemInterface::class);
58
59 1
        $path = $this->getMigrationsPath();
60 1
        assert($fileSystem->exists($path) === true);
61
62 1
        $this->getIO()->writeInfo("Migrations `$path` started." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
0 ignored issues
show
Unused Code introduced by
The call to IoInterface::writeInfo() has too many arguments starting with \Limoncello\Contracts\Co...face::VERBOSITY_VERBOSE.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
63
64 1
        $migrationClasses = $fileSystem->requireFile($path);
65 1
        $this->setMigrationClasses($migrationClasses);
66
67
        // ... and run actual migration
68 1
        parent::migrate($container);
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74 1
    protected function getMigrationClasses(): array
75
    {
76 1
        return $this->migrationClasses;
77
    }
78
79
    /**
80
     * @return string
81
     */
82 1
    protected function getMigrationsPath(): string
83
    {
84 1
        return $this->migrationsPath;
85
    }
86
87
    /**
88
     * @param string $migrationsPath
89
     *
90
     * @return self
91
     */
92 2
    protected function setMigrationsPath(string $migrationsPath): self
93
    {
94 2
        $this->migrationsPath = $migrationsPath;
95
96 2
        return $this;
97
    }
98
99
    /**
100
     * @param string[] $migrationClasses
101
     *
102
     * @return self
103
     */
104 1
    private function setMigrationClasses(array $migrationClasses): self
105
    {
106 1
        $this->migrationClasses = $migrationClasses;
107
108 1
        return $this;
109
    }
110
}
111