1 | <?php |
||
43 | final class MigrationRunner implements MigrationRunnerInterface |
||
44 | { |
||
45 | use HasInternalPublisherTrait; |
||
46 | use HasContextTrait; |
||
47 | |||
48 | /** |
||
49 | * MigrationRunner constructor. |
||
50 | * |
||
51 | * @param PublisherInterface $publisher |
||
|
|||
52 | * @param CollectionContextInterface $context |
||
53 | */ |
||
54 | 29 | public function __construct( |
|
55 | PublisherInterface $publisher = null, |
||
56 | CollectionContextInterface $context = null |
||
57 | ) { |
||
58 | 29 | if (null === $context) { |
|
59 | 23 | $context = CollectionContext::createWithProgress(1, 1); |
|
60 | 23 | } |
|
61 | 29 | $this->setContext($context); |
|
62 | |||
63 | 29 | $this->setPublisher($publisher); |
|
64 | 29 | } |
|
65 | |||
66 | /** |
||
67 | * Runs a single version using the specified options |
||
68 | * |
||
69 | * @param DeltaInterface $version |
||
70 | * @param OptionsInterface $options |
||
71 | * |
||
72 | * @return false|MigrateAfterEvent |
||
73 | * |
||
74 | * @throws RunnerException |
||
75 | */ |
||
76 | 23 | public function run(DeltaInterface $version, OptionsInterface $options) |
|
77 | { |
||
78 | 23 | if (!$this->shouldMigrate($version, $options)) { |
|
79 | 14 | if ($options->isExceptionOnSkip()) { |
|
80 | 2 | throw new RunnerException(sprintf( |
|
81 | 2 | 'Cowardly refusing to run %s() on a delta that is already "%s" (ID: %s).', |
|
82 | 2 | $options->getDirection(), |
|
83 | 2 | $options->getDirection(), |
|
84 | 2 | $version->getId() |
|
85 | 2 | )); |
|
86 | } |
||
87 | |||
88 | 12 | return false; // skip |
|
89 | } |
||
90 | |||
91 | // Dispatch MIGRATE_BEFORE |
||
92 | 13 | $this->getPublisher()->publish(new MigrateBeforeEvent($version, $options, $this->getContext())); |
|
93 | |||
94 | 13 | $version->migrate($options); // state will be changed |
|
95 | |||
96 | // Dispatch MIGRATE_AFTER |
||
97 | 13 | $event = new MigrateAfterEvent($version, $options, $this->getContext()); |
|
98 | 13 | $this->getPublisher()->publish($event); |
|
99 | |||
100 | 13 | return $event; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Returns true if the operation is forced, or if the direction is the opposite to the state of the migration. |
||
105 | * |
||
106 | * @param DeltaInterface $version |
||
107 | * @param OptionsInterface $options |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | 23 | protected function shouldMigrate(DeltaInterface $version, OptionsInterface $options) |
|
112 | { |
||
113 | 23 | return $options->isForced() |
|
114 | 23 | || ($options->getDirection()->isUp() ^ $version->isMigrated()); // direction is opposite to state |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | 18 | final public function withContext(ContextInterface $context) { |
|
123 | } |
||
124 |
This check looks for
@param
annotations 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.