GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MigrationFiles   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 16
lcom 1
cbo 4
dl 0
loc 91
rs 10
c 3
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
C get() 0 33 12
A statusIntention() 0 6 1
A getFiles() 0 14 2
1
<?php
2
3
namespace Dami\Migration;
4
5
use Symfony\Component\Finder\Finder;
6
7
class MigrationFiles
8
{
9
    private $path;
10
    private $schemaTable;
11
    private $statusIntention = false;
12
13
    /**
14
     * @param string      $path        Migrations path.
15
     * @param SchemaTable $schemaTable SchemaTable instance.
16
     */
17
    public function __construct($path, SchemaTable $schemaTable)
18
    {
19
        $this->path = $path;
20
        $this->schemaTable = $schemaTable;
21
    }
22
23
    /**
24
     * Gets migration files.
25
     *
26
     * @param string $version Version of migration.
27
     *
28
     * @return MigrationFile[]
29
     */
30
    public function get($version = null)
31
    {
32
        $currentVersion = $this->schemaTable->getCurrentVersion();
33
        if (null !== $version && (int) $version === (int) $currentVersion) {
34
            return null;
35
        }
36
        $migrateUp = null === $version || $version >= $currentVersion;
37
        $migrationFiles = array();
38
        foreach ($this->getFiles($migrateUp) as $file) {
39
            $filenameParser = new FileNameParser($file->getFileName());
40
41
            $isMigrated = in_array($filenameParser->getVersion(), $this->schemaTable->getVersions());
42
43
            $migrationFile = new MigrationFile($filenameParser->getMigrationName(), $file->getRealpath(),
44
                $filenameParser->getVersion(), $filenameParser->getMigrationClassName(), $isMigrated);
45
46
            if (false === $this->statusIntention) {
47
                if ($migrateUp && $isMigrated
48
                    || !$migrateUp && !$isMigrated) {
49
                    continue;
50
                }
51
                if ($version == $migrationFile->getVersion()) {
52
                    if ($migrateUp) {
53
                        $migrationFiles[] = $migrationFile;
54
                    }
55
                    break;
56
                }
57
            }
58
            $migrationFiles[] = $migrationFile;
59
        }
60
61
        return $migrationFiles;
62
    }
63
64
    /**
65
     * This method is called when status of migrations is checking.
66
     *
67
     * @return MigrationFiles
68
     */
69
    public function statusIntention()
70
    {
71
        $this->statusIntention = true;
72
73
        return $this;
74
    }
75
76
    /**
77
     * Gets files from directory.
78
     *
79
     * @param bool $migrateUp Is migration up.
80
     *
81
     * @return bool
82
     */
83
    private function getFiles($migrateUp)
84
    {
85
        $finder = new Finder();
86
87
        return $finder
88
            ->files()
89
            ->in($this->path)
90
            ->sort(function (\SplFileInfo $a, \SplFileInfo $b) use ($migrateUp) {
91
                return $migrateUp
92
                    ? $a->getRealpath() > $b->getRealpath()
93
                    : $a->getRealpath() < $b->getRealpath();
94
            }
95
        );
96
    }
97
}
98