| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Spiral Framework. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license   MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @author    Anton Titov (Wolfy-J) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Spiral\Migrations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Spiral\Database\Entities\Database; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Spiral\Migrations\Exceptions\MigrationException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Spiral\Migrations\Migration\State; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Simple migration class with shortcut for database and blueprint instances. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | abstract class Migration implements MigrationInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @var State|null | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     private $status = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * @var MigrationCapsule | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     private $capsule = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function withCapsule(CapsuleInterface $capsule): MigrationInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $migration = clone $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $migration->capsule = $capsule; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return $migration; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function withState(State $state): MigrationInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $migration = clone $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $migration->status = $state; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return $migration; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function getState() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $this->status; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @param string $database | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * @return Database | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function database(string $database = null): Database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         if (!empty($this->capsule)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             throw new MigrationException("Unable to get database, no capsule are set"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return $this->capsule->getDatabase($database); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      * Get table schema builder (blueprint). | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      * @param string      $table | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      * @param string|null $database | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |      * @return TableBlueprint | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function table(string $table, string $database = null): TableBlueprint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         if (!empty($this->capsule)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             throw new MigrationException("Unable to get table blueprint, no capsule are set"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         return new TableBlueprint($this->capsule, $database, $table); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  | } | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.