| Conditions | 5 |
| Paths | 16 |
| Total Lines | 92 |
| Code Lines | 82 |
| 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 |
||
| 64 | public function createPlatform($unsafe = false) |
||
| 65 | { |
||
| 66 | $platform = $this->createMock(MockPlatform::class); |
||
| 67 | $platform->expects($this->exactly(1)) |
||
| 68 | ->method('getCreateSchemaSQL') |
||
| 69 | ->with('foo_ns') |
||
| 70 | ->will($this->returnValue('create_schema')); |
||
| 71 | if ($unsafe) { |
||
| 72 | $platform->expects($this->exactly(1)) |
||
| 73 | ->method('getDropSequenceSql') |
||
| 74 | ->with($this->isInstanceOf(Sequence::class)) |
||
| 75 | ->will($this->returnValue('drop_seq')); |
||
| 76 | } |
||
| 77 | $platform->expects($this->exactly(1)) |
||
| 78 | ->method('getAlterSequenceSql') |
||
| 79 | ->with($this->isInstanceOf(Sequence::class)) |
||
| 80 | ->will($this->returnValue('alter_seq')); |
||
| 81 | $platform->expects($this->exactly(1)) |
||
| 82 | ->method('getCreateSequenceSql') |
||
| 83 | ->with($this->isInstanceOf(Sequence::class)) |
||
| 84 | ->will($this->returnValue('create_seq')); |
||
| 85 | if ($unsafe) { |
||
| 86 | $platform->expects($this->exactly(2)) |
||
| 87 | ->method('getDropViewSQL') |
||
| 88 | ->with($this->logicalOr( |
||
| 89 | $this->equalTo('bar_view'), |
||
| 90 | $this->equalTo('baz_view') |
||
| 91 | )) |
||
| 92 | ->will($this->returnCallback(static function ($arg) { |
||
| 93 | return [ |
||
| 94 | 'bar_view' => 'drop_view', |
||
| 95 | 'baz_view' => 'change_view_drop', |
||
| 96 | ][$arg] ?? null; |
||
| 97 | })); |
||
| 98 | } else { |
||
| 99 | $platform->expects($this->exactly(1)) |
||
| 100 | ->method('getDropViewSQL') |
||
| 101 | ->with($this->equalTo('baz_view')) |
||
| 102 | ->will($this->returnValue('change_view_drop')); |
||
| 103 | } |
||
| 104 | $platform->expects($this->exactly(2)) |
||
| 105 | ->method('getCreateViewSQL') |
||
| 106 | ->with($this->logicalOr( |
||
| 107 | $this->equalTo('baz_view'), |
||
| 108 | $this->equalTo('foo_view') |
||
| 109 | ), '') |
||
| 110 | ->will($this->returnCallback(static function ($arg) { |
||
| 111 | return [ |
||
| 112 | 'baz_view' => 'change_view_add', |
||
| 113 | 'foo_view' => 'create_view', |
||
| 114 | ][$arg] ?? null; |
||
| 115 | })); |
||
| 116 | if ($unsafe) { |
||
| 117 | $platform->expects($this->exactly(1)) |
||
| 118 | ->method('getDropTableSql') |
||
| 119 | ->with($this->isInstanceOf(Table::class)) |
||
| 120 | ->will($this->returnValue('drop_table')); |
||
| 121 | } |
||
| 122 | $platform->expects($this->exactly(1)) |
||
| 123 | ->method('getCreateTableSql') |
||
| 124 | ->with($this->isInstanceOf(Table::class)) |
||
| 125 | ->will($this->returnValue(['create_table'])); |
||
| 126 | $platform->expects($this->exactly(1)) |
||
| 127 | ->method('getCreateForeignKeySQL') |
||
| 128 | ->with($this->isInstanceOf(ForeignKeyConstraint::class)) |
||
| 129 | ->will($this->returnValue('create_foreign_key')); |
||
| 130 | $platform->expects($this->exactly(1)) |
||
| 131 | ->method('getAlterTableSql') |
||
| 132 | ->with($this->isInstanceOf(TableDiff::class)) |
||
| 133 | ->will($this->returnValue(['alter_table'])); |
||
| 134 | if ($unsafe) { |
||
| 135 | $platform->expects($this->exactly(1)) |
||
| 136 | ->method('getDropForeignKeySql') |
||
| 137 | ->with( |
||
| 138 | $this->isInstanceOf(ForeignKeyConstraint::class), |
||
| 139 | $this->isInstanceOf(Table::class) |
||
| 140 | ) |
||
| 141 | ->will($this->returnValue('drop_orphan_fk')); |
||
| 142 | } |
||
| 143 | $platform->expects($this->exactly(1)) |
||
| 144 | ->method('supportsSchemas') |
||
| 145 | ->will($this->returnValue(true)); |
||
| 146 | $platform->expects($this->exactly(1)) |
||
| 147 | ->method('supportsSequences') |
||
| 148 | ->will($this->returnValue(true)); |
||
| 149 | $platform->expects($this->exactly(1)) |
||
| 150 | ->method('supportsViews') |
||
| 151 | ->will($this->returnValue(true)); |
||
| 152 | $platform->expects($this->exactly(2)) |
||
| 153 | ->method('supportsForeignKeyConstraints') |
||
| 154 | ->will($this->returnValue(true)); |
||
| 155 | return $platform; |
||
| 156 | } |
||
| 180 |