| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 47 |
| 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 declare(strict_types=1); |
||
| 43 | public function testApply() |
||
| 44 | { |
||
| 45 | $repo = $this->getMockBuilder(ObjectRepository::class) |
||
| 46 | ->disableOriginalConstructor() |
||
| 47 | ->setMethods(['getData', 'findAll', 'findBy', 'findOneBy', 'getClassName', 'find']) |
||
| 48 | ->getMock(); |
||
| 49 | |||
| 50 | $manager = $this->getMockBuilder(EntityManager::class) |
||
| 51 | ->disableOriginalConstructor() |
||
| 52 | ->getMock(); |
||
| 53 | |||
| 54 | $manager |
||
| 55 | ->expects($this->once()) |
||
| 56 | ->method('getRepository') |
||
| 57 | ->with('DummyClass') |
||
| 58 | ->willReturn($repo); |
||
| 59 | |||
| 60 | $registry = $this->getMockBuilder(ManagerRegistry::class) |
||
| 61 | ->disableOriginalConstructor() |
||
| 62 | ->getMock(); |
||
| 63 | |||
| 64 | $registry |
||
| 65 | ->expects($this->once()) |
||
| 66 | ->method('getManagerForClass') |
||
| 67 | ->with('DummyClass') |
||
| 68 | ->willReturn($manager); |
||
| 69 | |||
| 70 | $configuration = new ParamConverter([]); |
||
| 71 | $configuration->setName('dummy'); |
||
| 72 | $configuration->setClass(BaseConfig::class); |
||
| 73 | $configuration->setOptions([ |
||
| 74 | 'entity_manager' => null, |
||
| 75 | 'entity_class' => 'DummyClass', |
||
| 76 | 'repository_method' => 'getData', |
||
| 77 | ]); |
||
| 78 | |||
| 79 | $converter = new ConfigConverter($registry); |
||
| 80 | |||
| 81 | |||
| 82 | $request = new HttpRequest([ |
||
| 83 | 'limit' => 100, |
||
| 84 | 'page'=> 3, |
||
| 85 | 'filter' => [ |
||
| 86 | 'c.dummy' => 'the road to hell', |
||
| 87 | ], |
||
| 88 | 'sortby' => 'c.id', |
||
| 89 | 'sortdir' => 'asc', |
||
| 90 | ]); |
||
| 91 | |||
| 92 | $result = $converter->apply($request, $configuration); |
||
| 93 | |||
| 94 | $this->assertIsObject($request->attributes->get('dummy')); |
||
| 95 | /** @var BaseConfig $v */ |
||
| 96 | $v = $request->attributes->get('dummy'); |
||
| 97 | $this->assertInstanceOf(BaseConfig::class, $v); |
||
| 98 | $this->assertEquals(100, $v->getRequest()->getLimit()); |
||
| 99 | $this->assertEquals(3, $v->getRequest()->getPageNum()); |
||
| 100 | $this->assertEquals(['c.dummy' => 'the road to hell'], $v->getRequest()->getQuery()); |
||
| 101 | $this->assertEquals('c.id', $v->getRequest()->getSortBy()); |
||
| 102 | $this->assertEquals('asc', $v->getRequest()->getSortDir()); |
||
| 103 | $this->assertEquals('asc', $v->getRequest()->getSortDir()); |
||
| 104 | $this->assertIsCallable($v->getRepositoryCallback()); |
||
| 105 | |||
| 106 | $this->assertTrue($result); |
||
| 107 | } |
||
| 109 |