| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace Innmind\Neo4jBundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     DependencyInjection\ContainerBuilder, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     Config\FileLocator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     HttpKernel\DependencyInjection\Extension, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     DependencyInjection\Loader, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     DependencyInjection\Reference | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | final class InnmindNeo4jExtension extends Extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 24 |  |     public function load(array $configs, ContainerBuilder $container) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 24 |  |         $configuration = new Configuration(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 24 |  |         $config = $this->processConfiguration($configuration, $configs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 24 |  |         $loader = new Loader\YamlFileLoader( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 24 |  |             new FileLocator(__DIR__ . '/../Resources/config') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 24 |  |         $loader->load('services.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 24 |  |             ->injectPersister($container, $config['persister']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 24 |  |             ->configureConnection($container, $config['connection']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 24 |  |             ->registerTypes($container, $config['types']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 24 |  |             ->injectMetadataConfiguration( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 24 |  |                 $config['metadata_configuration'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 24 |  |             ->injectClock($container, $config['clock']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 24 |  |             ->aliasEventBus($container, $config['event_bus']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 24 |  |             ->aliasDbalConnection($container, $config['dbal_connection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 24 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * Inject the defined service in the unit of work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param string $service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @return self | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 24 |  |     private function injectPersister( | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         ContainerBuilder $container, | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         string $service | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     ): self { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $container | 
            
                                                                        
                            
            
                                    
            
            
                | 55 | 24 |  |             ->getDefinition('innmind_neo4j.unit_of_work') | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 24 |  |             ->replaceArgument(5, new Reference($service)); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 24 |  |         return $this; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Inject value objects to make the connection work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param array $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 24 |  |     private function configureConnection( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         array $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 24 |  |         $transactions = $container->getDefinition('innmind_neo4j.dbal.connection.transactions'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 24 |  |         $transport = $container->getDefinition('innmind_neo4j.dbal.connection.transport'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 24 |  |         $server = $container->getDefinition('innmind_neo4j.dbal.connection.server'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 24 |  |         $authentication = $container->getDefinition('innmind_neo4j.dbal.connection.authentication'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $server | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 24 |  |             ->replaceArgument(0, $config['scheme']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 24 |  |             ->replaceArgument(1, $config['host']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 24 |  |             ->replaceArgument(2, $config['port']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $authentication | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 24 |  |             ->replaceArgument(0, $config['user']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 24 |  |             ->replaceArgument(1, $config['password']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Register the classes as added property types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param array $types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 24 |  |     private function registerTypes( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         array $types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 24 |  |         $definition = $container->getDefinition('innmind_neo4j.types'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 24 |  |         foreach ($types as $class) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 14 |  |             $definition->addArgument($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * Inject the configuration object into the metadata builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @param string $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 24 |  |     private function injectMetadataConfiguration( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         string $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 24 |  |             ->getDefinition('innmind_neo4j.metadata_builder') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 24 |  |             ->replaceArgument(2, new Reference($config)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * Inject the clock in the transactions service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @param string $clock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 24 |  |     private function injectClock( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         string $clock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 24 |  |             ->getDefinition('innmind_neo4j.dbal.connection.transactions') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 24 |  |             ->replaceArgument(1, new Reference($clock)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * Create the alias for the event bus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @param string $eventBus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 24 |  |     private function aliasEventBus( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         string $eventBus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 24 |  |         $container->setAlias('innmind_neo4j.event_bus', $eventBus); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * Create the alias for dbal connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @param ContainerBuilder $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * @param string $connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 24 |  |     private function aliasDbalConnection( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         ContainerBuilder $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         string $connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 24 |  |         $container->setAlias('innmind_neo4j.dbal.connection', $connection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 24 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 181 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 182 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.