| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Nexy\PayboxDirect\Bundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Nexy\PayboxDirect\Paybox; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Config\FileLocator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\HttpKernel\DependencyInjection\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Sullivan Senechal <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | final class NexyPayboxDirectExtension extends Extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function load(array $configs, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $configuration = new Configuration(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $config = $this->processConfiguration($configuration, $configs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->processOptions($config, $container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $loader->load('sdk.xml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->processClient($config, $container); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @param array            $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private function processOptions(array $config, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         // Start with client option | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $options = $config['client']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         // Paybox version and devise special hack: Get the number. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $options['paybox_version'] = Paybox::VERSIONS[$config['paybox']['version']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         unset($config['paybox']['version']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         if (array_key_exists('devise', $config['paybox'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $options['paybox_devise'] = Paybox::DEVISES[$config['paybox']['devise']]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             unset($config['paybox']['devise']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         // Convert paybox option format | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         foreach ($config['paybox'] as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $options['paybox_'.$key] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $container->setParameter('nexy_paybox_direct.options', $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param array            $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |     private function processClient(array $config, ContainerBuilder $container) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         // Define http_client_* as private services and set the nexy_paybox_direct.http_client_default one | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                        
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: