| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 11 |
| Lines | 62 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 20 | View Code Duplication | public function up(Schema $schema) |
|
|
|
|||
| 21 | { |
||
| 22 | // create temp table from new structure |
||
| 23 | $this->addSql('CREATE TABLE "_new" ( |
||
| 24 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||
| 25 | type VARCHAR(16) DEFAULT NULL, |
||
| 26 | country VARCHAR(2) DEFAULT NULL, |
||
| 27 | storage INTEGER DEFAULT NULL, |
||
| 28 | studio INTEGER DEFAULT NULL, |
||
| 29 | name VARCHAR(256) NOT NULL, |
||
| 30 | date_premiere DATE DEFAULT NULL, |
||
| 31 | date_end DATE DEFAULT NULL, |
||
| 32 | duration INTEGER DEFAULT NULL, |
||
| 33 | summary TEXT DEFAULT NULL, |
||
| 34 | path VARCHAR(256) DEFAULT NULL, |
||
| 35 | episodes TEXT DEFAULT NULL, |
||
| 36 | episodes_number VARCHAR(5) DEFAULT NULL, |
||
| 37 | translate VARCHAR(256) DEFAULT NULL, |
||
| 38 | file_info TEXT DEFAULT NULL, |
||
| 39 | cover VARCHAR(256) DEFAULT NULL, |
||
| 40 | rating INTEGER DEFAULT NULL, |
||
| 41 | date_add DATETIME NOT NULL, |
||
| 42 | date_update DATETIME NOT NULL |
||
| 43 | )'); |
||
| 44 | $this->addSql(' |
||
| 45 | INSERT INTO |
||
| 46 | "_new" |
||
| 47 | SELECT |
||
| 48 | id, |
||
| 49 | type, |
||
| 50 | country, |
||
| 51 | storage, |
||
| 52 | studio, |
||
| 53 | name, |
||
| 54 | date_start, |
||
| 55 | date_end, |
||
| 56 | duration, |
||
| 57 | summary, |
||
| 58 | path, |
||
| 59 | episodes, |
||
| 60 | episodes_number, |
||
| 61 | translate, |
||
| 62 | file_info, |
||
| 63 | cover, |
||
| 64 | rating, |
||
| 65 | date_add, |
||
| 66 | date_update |
||
| 67 | FROM |
||
| 68 | "item" |
||
| 69 | '); |
||
| 70 | // rename new to origin and drop origin |
||
| 71 | $this->addSql('ALTER TABLE item RENAME TO _origin'); |
||
| 72 | $this->addSql('ALTER TABLE _new RENAME TO item'); |
||
| 73 | $this->addSql('DROP TABLE _origin'); |
||
| 74 | |||
| 75 | // create index |
||
| 76 | $this->addSql('CREATE INDEX item_country_idx ON item (country);'); |
||
| 77 | $this->addSql('CREATE INDEX item_storage_idx ON item (storage);'); |
||
| 78 | $this->addSql('CREATE INDEX item_type_idx ON item (type)'); |
||
| 79 | $this->addSql('CREATE INDEX item_rating_idx ON item (rating)'); |
||
| 80 | $this->addSql('CREATE INDEX item_studio_idx ON item (studio)'); |
||
| 81 | } |
||
| 82 | |||
| 148 |
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.