| Conditions | 2 |
| Paths | 2 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 105 | public function up() |
||
| 106 | { |
||
| 107 | $authManager = $this->getAuthManager(); |
||
| 108 | $this->db = $authManager->db; |
||
| 109 | |||
| 110 | $tableOptions = null; |
||
|
|
|||
| 111 | if ($this->db->driverName === 'mysql') { |
||
| 112 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
||
| 113 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
||
| 114 | |||
| 115 | $this->createTable($authManager->ruleTable, [ |
||
| 116 | 'name' => $this->varchar(64)->notNull()->comment('Rule Name'), |
||
| 117 | 'data' => $this->blob(), |
||
| 118 | 'created_at' => $this->dateTime()->notNull(), |
||
| 119 | 'updated_at' => $this->dateTime()->notNull(), |
||
| 120 | ], $tableOptions . " COMMENT 'Auth Rule'"); |
||
| 121 | $this->addPrimaryKey('rule_name_pk', $authManager->ruleTable, 'name'); |
||
| 122 | |||
| 123 | $this->createTable($authManager->itemTable, [ |
||
| 124 | 'name' => $this->varchar(64)->notNull(), |
||
| 125 | 'type' => $this->smallInteger()->notNull(), |
||
| 126 | 'description' => $this->text()->comment('Description'), |
||
| 127 | 'rule_name' => $this->varchar(64)->comment('Rule Name'), |
||
| 128 | 'data' => $this->blob(), |
||
| 129 | 'color' => $this->integer()->defaultValue(-1)->notNull()->comment('Color'), |
||
| 130 | 'created_at' => $this->dateTime()->notNull(), |
||
| 131 | 'updated_at' => $this->dateTime()->notNull(), |
||
| 132 | ], $tableOptions . " COMMENT 'Auth Item'"); |
||
| 133 | $this->addPrimaryKey('item_name_pk', $authManager->itemTable, 'name'); |
||
| 134 | $this->addForeignKey('rule_name_fk', $authManager->itemTable, 'rule_name', $authManager->ruleTable, 'name', 'CASCADE', 'CASCADE'); |
||
| 135 | $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type'); |
||
| 136 | |||
| 137 | $this->createTable($authManager->itemChildTable, [ |
||
| 138 | 'parent' => $this->varchar(64)->notNull(), |
||
| 139 | 'child' => $this->varchar(64)->notNull(), |
||
| 140 | ], $tableOptions . " COMMENT 'Auth Item Child'"); |
||
| 141 | $this->addPrimaryKey('parent_child_pk', $authManager->itemChildTable, ['parent', 'child']); |
||
| 142 | $this->addForeignKey('parent_name_fk', $authManager->itemChildTable, 'parent', $authManager->itemTable, 'name', 'CASCADE', 'CASCADE'); |
||
| 143 | $this->addForeignKey('child_name_fk', $authManager->itemChildTable, 'child', $authManager->itemTable, 'name', 'CASCADE', 'CASCADE'); |
||
| 144 | |||
| 145 | $this->createTable($authManager->assignmentTable, [ |
||
| 146 | 'item_name' => $this->varchar(64)->notNull(), |
||
| 147 | 'user_guid' => $this->varbinary(16)->notNull(), |
||
| 148 | 'created_at' => $this->dateTime()->notNull(), |
||
| 149 | 'failed_at' => $this->dateTime(), |
||
| 150 | ], $tableOptions . " COMMENT 'Auth Assignment'"); |
||
| 151 | $this->addPrimaryKey('user_item_name_pk', $authManager->assignmentTable, ['item_name', 'user_guid']); |
||
| 152 | $this->addForeignKey('user_assignment_fk', $authManager->assignmentTable, 'user_guid', '{{%user}}', 'guid', 'CASCADE', 'CASCADE'); |
||
| 153 | } |
||
| 154 | $this->addRules(); |
||
| 155 | $this->addRoles(); |
||
| 156 | } |
||
| 157 | |||
| 231 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.