|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <https://github.com/baleen/migrations>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Migration\Repository; |
|
21
|
|
|
|
|
22
|
|
|
use Baleen\Migrations\Migration\Repository\Mapper\DefinitionInterface; |
|
23
|
|
|
use Baleen\Migrations\Migration\Repository\Mapper\RepositoryMapperInterface; |
|
24
|
|
|
use Baleen\Migrations\Version\Collection\Collection; |
|
25
|
|
|
use Baleen\Migrations\Version\Comparator\ComparatorInterface; |
|
26
|
|
|
use Baleen\Migrations\Version\Comparator\MigrationComparator; |
|
27
|
|
|
use Baleen\Migrations\Version\Repository\VersionRepositoryInterface as VersionRepositoryInterface; |
|
28
|
|
|
use Baleen\Migrations\Version\Version; |
|
29
|
|
|
use Baleen\Migrations\Version\VersionId; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class MigrationRepository. |
|
33
|
|
|
* |
|
34
|
|
|
* @author Gabriel Somoza <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
final class MigrationRepository implements MigrationRepositoryInterface |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var ComparatorInterface */ |
|
39
|
|
|
private $comparator = null; |
|
40
|
|
|
|
|
41
|
|
|
/** @var VersionRepositoryInterface */ |
|
42
|
|
|
private $storage; |
|
43
|
|
|
|
|
44
|
|
|
/** @var RepositoryMapperInterface */ |
|
45
|
|
|
private $mapper; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* MigrationRepository constructor |
|
49
|
|
|
* |
|
50
|
|
|
* @param VersionRepositoryInterface $storage |
|
51
|
|
|
* @param RepositoryMapperInterface $mapper |
|
52
|
|
|
* @param ComparatorInterface $comparator |
|
|
|
|
|
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function __construct( |
|
55
|
|
|
VersionRepositoryInterface $storage, |
|
56
|
|
|
RepositoryMapperInterface $mapper, |
|
57
|
|
|
ComparatorInterface $comparator = null |
|
58
|
|
|
) { |
|
59
|
2 |
|
if (null === $comparator) { |
|
60
|
|
|
// this is the default because we're hashing IDs by default |
|
61
|
2 |
|
$comparator = new MigrationComparator(); |
|
62
|
2 |
|
} |
|
63
|
2 |
|
$this->comparator = $comparator; |
|
64
|
|
|
|
|
65
|
2 |
|
$this->storage = $storage; |
|
66
|
2 |
|
$this->mapper = $mapper; |
|
67
|
2 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritdoc |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function fetchAll() |
|
73
|
|
|
{ |
|
74
|
2 |
|
$definitions = $this->mapper->fetchAll(); |
|
75
|
2 |
|
$stored = array_map(function (VersionId $id) { |
|
76
|
2 |
|
return $id->toString(); |
|
77
|
2 |
|
}, $this->storage->fetchAll()); |
|
78
|
|
|
|
|
79
|
2 |
|
$collection = new Collection(); |
|
80
|
2 |
|
foreach ($definitions as $definition) { |
|
81
|
|
|
/** @var DefinitionInterface $definition */ |
|
82
|
2 |
|
$migration = $definition->getMigration(); |
|
83
|
2 |
|
$id = $definition->getId(); |
|
84
|
2 |
|
$migrated = in_array($id->toString(), $stored); |
|
85
|
2 |
|
$version = new Version($migration, $migrated, $id); |
|
86
|
2 |
|
$collection->add($version); |
|
87
|
2 |
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
return $collection->sort($this->comparator); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.