Conditions | 4 |
Paths | 8 |
Total Lines | 61 |
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 |
||
45 | private function createPlatform(bool $unsafe) |
||
46 | { |
||
47 | /** @var AbstractPlatform|MockObject $platform */ |
||
48 | $platform = $this->createMock(AbstractPlatform::class); |
||
49 | $platform->expects($this->exactly(1)) |
||
50 | ->method('getCreateSchemaSQL') |
||
51 | ->with('foo_ns') |
||
52 | ->will($this->returnValue('create_schema')); |
||
53 | if ($unsafe) { |
||
54 | $platform->expects($this->exactly(1)) |
||
55 | ->method('getDropSequenceSql') |
||
56 | ->with($this->isInstanceOf(Sequence::class)) |
||
57 | ->will($this->returnValue('drop_seq')); |
||
58 | } |
||
59 | $platform->expects($this->exactly(1)) |
||
60 | ->method('getAlterSequenceSql') |
||
61 | ->with($this->isInstanceOf(Sequence::class)) |
||
62 | ->will($this->returnValue('alter_seq')); |
||
63 | $platform->expects($this->exactly(1)) |
||
64 | ->method('getCreateSequenceSql') |
||
65 | ->with($this->isInstanceOf(Sequence::class)) |
||
66 | ->will($this->returnValue('create_seq')); |
||
67 | if ($unsafe) { |
||
68 | $platform->expects($this->exactly(1)) |
||
69 | ->method('getDropTableSql') |
||
70 | ->with($this->isInstanceOf(Table::class)) |
||
71 | ->will($this->returnValue('drop_table')); |
||
72 | } |
||
73 | $platform->expects($this->exactly(1)) |
||
74 | ->method('getCreateTableSql') |
||
75 | ->with($this->isInstanceOf(Table::class)) |
||
76 | ->will($this->returnValue(['create_table'])); |
||
77 | $platform->expects($this->exactly(1)) |
||
78 | ->method('getCreateForeignKeySQL') |
||
79 | ->with($this->isInstanceOf(ForeignKeyConstraint::class)) |
||
80 | ->will($this->returnValue('create_foreign_key')); |
||
81 | $platform->expects($this->exactly(1)) |
||
82 | ->method('getAlterTableSql') |
||
83 | ->with($this->isInstanceOf(TableDiff::class)) |
||
84 | ->will($this->returnValue(['alter_table'])); |
||
85 | if ($unsafe) { |
||
86 | $platform->expects($this->exactly(1)) |
||
87 | ->method('getDropForeignKeySql') |
||
88 | ->with( |
||
89 | $this->isInstanceOf(ForeignKeyConstraint::class), |
||
90 | $this->isInstanceOf(Table::class) |
||
91 | ) |
||
92 | ->will($this->returnValue('drop_orphan_fk')); |
||
93 | } |
||
94 | $platform->expects($this->exactly(1)) |
||
95 | ->method('supportsSchemas') |
||
96 | ->will($this->returnValue(true)); |
||
97 | $platform->expects($this->exactly(1)) |
||
98 | ->method('supportsSequences') |
||
99 | ->will($this->returnValue(true)); |
||
100 | $platform->expects($this->exactly(2)) |
||
101 | ->method('supportsForeignKeyConstraints') |
||
102 | ->will($this->returnValue(true)); |
||
103 | |||
104 | return $platform; |
||
105 | } |
||
106 | |||
127 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.