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