| Conditions | 1 |
| Paths | 1 |
| Total Lines | 94 |
| 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 |
||
| 16 | public function testRun() |
||
| 17 | { |
||
| 18 | /** @var ContainerInterface|MockObject $container */ |
||
| 19 | $container = $this |
||
| 20 | ->getMockBuilder(ContainerInterface::class) |
||
| 21 | ->disableOriginalConstructor() |
||
| 22 | ->getMock() |
||
| 23 | ; |
||
| 24 | |||
| 25 | // mock event dispatcher |
||
| 26 | $eventDispatcher = $this |
||
| 27 | ->getMockBuilder(EventDispatcherInterface::class) |
||
| 28 | ->disableOriginalConstructor() |
||
| 29 | ->getMock() |
||
| 30 | ; |
||
| 31 | |||
| 32 | // mock assets configuration |
||
| 33 | $configuration = [ |
||
| 34 | 'debug' => true, |
||
| 35 | 'filters' => [ |
||
| 36 | 'compass' => [], |
||
| 37 | 'merge' => [], |
||
| 38 | 'minify' => [], |
||
| 39 | 'copy' => [], |
||
| 40 | ], |
||
| 41 | 'tasks' => [ |
||
| 42 | 'main.css' => [ |
||
| 43 | 'filters' => [ |
||
| 44 | 'compass', |
||
| 45 | 'merge', |
||
| 46 | 'minify', |
||
| 47 | 'copy', |
||
| 48 | ], |
||
| 49 | 'sources' => [ |
||
| 50 | 'tests/Resources/assets/scss/main.scss', |
||
| 51 | 'tests/Resources/assets/scss/custom.scss', |
||
| 52 | ], |
||
| 53 | 'destinations' => [ |
||
| 54 | 'web/css/main.css', |
||
| 55 | ], |
||
| 56 | ], |
||
| 57 | ], |
||
| 58 | ]; |
||
| 59 | |||
| 60 | // mock notification subscriber |
||
| 61 | $notificationSubscriber = $this |
||
| 62 | ->getMockBuilder(NotificationSubscriber::class) |
||
| 63 | ->getMock() |
||
| 64 | ; |
||
| 65 | $notificationSubscriber |
||
| 66 | ->expects($this->atLeastOnce()) |
||
| 67 | ->method('getNotifications') |
||
| 68 | ->willReturn([ |
||
| 69 | 'Success !!!', |
||
| 70 | ]) |
||
| 71 | ; |
||
| 72 | |||
| 73 | $container |
||
| 74 | ->method('getParameter') |
||
| 75 | ->willReturnMap([ |
||
| 76 | ['jk.assets', $configuration], |
||
| 77 | ['kernel.root_dir', realpath(__DIR__.'/../..')], |
||
| 78 | ]) |
||
| 79 | ; |
||
| 80 | $c = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE; |
||
| 81 | $container |
||
| 82 | ->method('get') |
||
| 83 | ->willReturnMap([ |
||
| 84 | ['event_dispatcher', $c, $eventDispatcher], |
||
| 85 | ['jk.assets.notification_subscriber', $c, $notificationSubscriber] |
||
| 86 | ]) |
||
| 87 | ; |
||
| 88 | |||
| 89 | $command = new BuildCommand(); |
||
| 90 | $command->setContainer($container); |
||
|
|
|||
| 91 | |||
| 92 | $input = new ArrayInput([]); |
||
| 93 | $output = new BufferedOutput(); |
||
| 94 | $command->run($input, $output); |
||
| 95 | |||
| 96 | $content = $output->fetch(); |
||
| 97 | |||
| 98 | $this->assertContains('Building tasks', $content); |
||
| 99 | $this->assertContains('Tasks build', $content); |
||
| 100 | $this->assertContains('Building filters', $content); |
||
| 101 | $this->assertContains('Filters build', $content); |
||
| 102 | $this->assertContains('Running tasks', $content); |
||
| 103 | $this->assertContains('Running main.css', $content); |
||
| 104 | $this->assertContains('x Success !!!', $content); |
||
| 105 | $this->assertContains('[OK] Assets build end', $content); |
||
| 106 | |||
| 107 | $fileContent = 'body{color:blue}a{color:red}'; |
||
| 108 | $this->assertEquals(file_get_contents(__DIR__.'/../../web/css/main.css'), $fileContent); |
||
| 109 | } |
||
| 110 | } |
||
| 111 |
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.