| Conditions | 3 | 
| Paths | 3 | 
| Total 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  | 
            ||
| 21 | public function testProcess()  | 
            ||
| 22 |     { | 
            ||
| 23 | // Create ContainerBuilder and set up basic sonata_media config with formats  | 
            ||
| 24 | $container = new ContainerBuilder();  | 
            ||
| 25 | $extension = new SonataMediaExtension();  | 
            ||
| 26 | $container->registerExtension($extension);  | 
            ||
| 27 | $container->loadFromExtension(  | 
            ||
| 28 | $extension->getAlias(),  | 
            ||
| 29 | [  | 
            ||
| 30 | 'db_driver' => 'doctrine_orm',  | 
            ||
| 31 | 'default_context' => 'default',  | 
            ||
| 32 | 'providers' => [  | 
            ||
| 33 | 'image' => [  | 
            ||
| 34 | 'filesystem' => 'foo_filesystem',  | 
            ||
| 35 | ],  | 
            ||
| 36 | ],  | 
            ||
| 37 | 'contexts' => [  | 
            ||
| 38 | 'default' => [  | 
            ||
| 39 | 'providers' => [  | 
            ||
| 40 | 'foo_provider',  | 
            ||
| 41 | ],  | 
            ||
| 42 | 'formats' => '%foo_formats%',  | 
            ||
| 43 | ],  | 
            ||
| 44 | ],  | 
            ||
| 45 | ]  | 
            ||
| 46 | );  | 
            ||
| 47 | |||
| 48 | // Define 'foo_formats' parameter, parameter reference in 'sonata_media' config should resolve to this value.  | 
            ||
| 49 |         $container->setParameter('foo_formats', [ | 
            ||
| 50 | 'foo_format' => [  | 
            ||
| 51 | 'width' => 350,  | 
            ||
| 52 | 'height' => 200,  | 
            ||
| 53 | 'quality' => 70,  | 
            ||
| 54 | ],  | 
            ||
| 55 | ]);  | 
            ||
| 56 | |||
| 57 | // Register parameters and services needed by compiler pass  | 
            ||
| 58 |         $container->setParameter('sonata.media.admin_format', [ | 
            ||
| 59 | 'width' => 200,  | 
            ||
| 60 | 'height' => false,  | 
            ||
| 61 | 'quality' => 90,  | 
            ||
| 62 | ]);  | 
            ||
| 63 | $container  | 
            ||
| 64 |             ->register('foo_filesystem') | 
            ||
| 65 | ->setPublic(false);  | 
            ||
| 66 | $container  | 
            ||
| 67 |             ->register('foo_provider') | 
            ||
| 68 | ->setPublic(false);  | 
            ||
| 69 | $container  | 
            ||
| 70 |             ->register('sonata.media.pool') | 
            ||
| 71 | ->setPublic(false);  | 
            ||
| 72 | |||
| 73 | (new AddProviderCompilerPass())->process($container);  | 
            ||
| 74 | |||
| 75 | // 'foo_provider' should have 1 'addFormat' method call with correctly resolved config values.  | 
            ||
| 76 |         $calls = $container->getDefinition('foo_provider')->getMethodCalls(); | 
            ||
| 77 | $callFound = false;  | 
            ||
| 78 | $expectedCall = [  | 
            ||
| 79 | 'default_foo_format',  | 
            ||
| 80 | [  | 
            ||
| 81 | 'width' => 350,  | 
            ||
| 82 | 'height' => 200,  | 
            ||
| 83 | 'quality' => 70,  | 
            ||
| 84 | 'format' => 'jpg',  | 
            ||
| 85 | 'constraint' => true,  | 
            ||
| 86 | ],  | 
            ||
| 87 | ];  | 
            ||
| 88 |         foreach ($calls as $call) { | 
            ||
| 89 |             if ('addFormat' === $call[0]) { | 
            ||
| 90 | $callFound = true;  | 
            ||
| 91 | $this->assertSame(  | 
            ||
| 92 | $expectedCall,  | 
            ||
| 93 | $call[1],  | 
            ||
| 94 | 'Format config of "foo_provider" doesn\'t match the expected config.'  | 
            ||
| 95 | );  | 
            ||
| 96 | }  | 
            ||
| 97 | }  | 
            ||
| 98 | $this->assertTrue(  | 
            ||
| 99 | $callFound,  | 
            ||
| 100 | 'Expected "addFormat" method call on "foo_provider" service was not registered.'  | 
            ||
| 101 | );  | 
            ||
| 102 | }  | 
            ||
| 103 | }  | 
            ||
| 104 |