| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 27 | public function testBuildFilter() |
||
| 28 | { |
||
| 29 | $astSubtree = new ASTGroup( |
||
| 30 | 'T_LOGIC_AND', |
||
| 31 | [ |
||
| 32 | new ASTGroup( |
||
| 33 | 'T_LOGIC_OR', |
||
| 34 | [ |
||
| 35 | new ASTAssertion( |
||
| 36 | 'test_dse_1', |
||
| 37 | 'T_OP_EQ', |
||
| 38 | 'value1' |
||
| 39 | ), |
||
| 40 | new ASTAssertion( |
||
| 41 | 'test_dse_2', |
||
| 42 | 'T_OP_LT', |
||
| 43 | 'value2' |
||
| 44 | ), |
||
| 45 | ] |
||
| 46 | ), |
||
| 47 | new ASTAssertion( |
||
| 48 | 'test_dse_3', |
||
| 49 | 'T_OP_NEQ', |
||
| 50 | 'value3' |
||
| 51 | ), |
||
| 52 | ] |
||
| 53 | ); |
||
| 54 | |||
| 55 | $filterDefinition1 = new Filter(); |
||
| 56 | $filterDefinition1->setConditionType('OR'); |
||
| 57 | $filter1 = new FilterCondition('test_dse_1', FilterCondition::METHOD_NUMERIC_EQ, 'value1', 'value1'); |
||
| 58 | $filter2 = new FilterCondition('test_dse_2', FilterCondition::METHOD_NUMERIC_LT, 'value2', 'value2'); |
||
| 59 | $filterDefinition1[] = $filter1; |
||
| 60 | $filterDefinition1[] = $filter2; |
||
| 61 | $filter3 = new FilterCondition('test_dse_3', FilterCondition::METHOD_NUMERIC_NEQ, 'value3', 'value3'); |
||
| 62 | $filterDefinition2 = new Filter(); |
||
| 63 | $filterDefinition2->setConditionType('AND'); |
||
| 64 | $filterDefinition2[] = $filterDefinition1; |
||
| 65 | $filterDefinition2[] = $filter3; |
||
| 66 | |||
| 67 | $expectedFilter = $filterDefinition2; |
||
| 68 | |||
| 69 | $dataSourceElements = [ |
||
| 70 | new Field('test_dse_1', '', '', new NumberDataType()), |
||
| 71 | new Field('test_dse_2', '', '', new NumberDataType()), |
||
| 72 | new Field('test_dse_3', '', '', new NumberDataType()), |
||
| 73 | ]; |
||
| 74 | |||
| 75 | $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); |
||
| 76 | $dataSourceProphecy->getFields()->willReturn($dataSourceElements); |
||
| 77 | |||
| 78 | $extensionContainerProphecy = $this->prophesize(UqlExtensionContainer::class); |
||
| 79 | |||
| 80 | $interpreterFactory = new InterpreterFactory($extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactory); |
||
| 81 | $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); |
||
| 82 | |||
| 83 | $actualFilter = $interpreter->buildFilter($astSubtree); |
||
| 84 | $this->assertEquals($expectedFilter, $actualFilter); |
||
| 85 | } |
||
| 86 | |||
| 117 |