| Conditions | 5 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 33 |
| 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 |
||
| 31 | public function load(Container $container) |
||
| 32 | { |
||
| 33 | $container->register('phpcr_odm', function (Container $container) { |
||
| 34 | $dbPath = $container->getParameter('db_path'); |
||
| 35 | $registerNodeTypes = false; |
||
| 36 | |||
| 37 | $connection = DriverManager::getConnection([ |
||
| 38 | 'driver' => 'pdo_sqlite', |
||
| 39 | 'path' => $dbPath, |
||
| 40 | ]); |
||
| 41 | |||
| 42 | // automatically setup the schema if the db doesn't exist yet. |
||
| 43 | if (!file_exists($dbPath)) { |
||
| 44 | if (!file_exists($dir = dirname($dbPath))) { |
||
| 45 | mkdir($dir); |
||
| 46 | } |
||
| 47 | |||
| 48 | $schema = new RepositorySchema(); |
||
| 49 | foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { |
||
| 50 | $connection->exec($sql); |
||
| 51 | } |
||
| 52 | |||
| 53 | $registerNodeTypes = true; |
||
| 54 | } |
||
| 55 | |||
| 56 | $factory = new RepositoryFactoryDoctrineDBAL(); |
||
| 57 | $repository = $factory->getRepository([ |
||
| 58 | 'jackalope.doctrine_dbal_connection' => $connection, |
||
| 59 | ]); |
||
| 60 | $session = $repository->login(new SimpleCredentials(null, null), 'default'); |
||
| 61 | |||
| 62 | if ($registerNodeTypes) { |
||
| 63 | $typeRegistrator = new NodeTypeRegistrator(); |
||
| 64 | $typeRegistrator->registerNodeTypes($session); |
||
| 65 | } |
||
| 66 | |||
| 67 | $xmlDriver = new XmlDriver([__DIR__ . '/mappings']); |
||
| 68 | $annotationDriver = new AnnotationDriver(new AnnotationReader(), [ |
||
| 69 | __DIR__ . '/../../../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', |
||
| 70 | ]); |
||
| 71 | $chain = new MappingDriverChain(); |
||
| 72 | $chain->addDriver($xmlDriver, 'Psi\Component\ObjectAgent\Tests\Functional\Model'); |
||
| 73 | $chain->addDriver($xmlDriver, 'Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional\Model'); |
||
| 74 | $chain->addDriver($annotationDriver, 'Doctrine'); |
||
| 75 | |||
| 76 | $config = new Configuration(); |
||
| 77 | $config->setMetadataDriverImpl($chain); |
||
| 78 | |||
| 79 | return DocumentManager::create($session, $config); |
||
| 80 | }); |
||
| 81 | |||
| 82 | $container->register('psi_object_agent.phpcr_odm', function (Container $container) { |
||
| 83 | return new PhpcrOdmAgent($container->get('phpcr_odm')); |
||
| 84 | }); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |