Conditions | 5 |
Paths | 16 |
Total Lines | 70 |
Code Lines | 56 |
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 |
||
91 | protected static function orm(): bool |
||
92 | { |
||
93 | $config = Setup::createAnnotationMetadataConfiguration([BASEPATH.DS.'src'], true); |
||
94 | |||
95 | $config->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); |
||
96 | $config->setProxyDir(BASEPATH.DS.'tmp'.DS.'proxies'); |
||
97 | $config->addEntityNamespace('RssApp', 'RssApp\Model'); |
||
98 | $config->setQuoteStrategy(new BacktickQuoteStrategy()); |
||
99 | $config->setNamingStrategy(new UnderscoreNamingStrategy()); |
||
100 | |||
101 | if (Registry::get('redis')) { |
||
102 | $ormCache = new RedisCache(); |
||
103 | $ormCache->setRedis(Registry::get('redis')); |
||
|
|||
104 | } else { |
||
105 | $ormCache = new ArrayCache(); |
||
106 | } |
||
107 | $config->setSecondLevelCacheEnabled(); |
||
108 | $config->getSecondLevelCacheConfiguration() |
||
109 | ->setCacheFactory(new DefaultCacheFactory(new RegionsConfiguration(), $ormCache)); |
||
110 | $config->setMetadataCacheImpl($ormCache); |
||
111 | $config->setQueryCacheImpl($ormCache); |
||
112 | $config->setResultCacheImpl($ormCache); |
||
113 | $reader = new AnnotationReader(); |
||
114 | $driver = new AnnotationDriver($reader, [BASEPATH.DS.'src']); |
||
115 | $config->setMetadataDriverImpl($driver); |
||
116 | |||
117 | $slaves = []; |
||
118 | if (getenv('DB_SLAVES') !== false) { |
||
119 | $slaveHosts = explode(',', getenv('DB_SLAVES')); |
||
120 | foreach ($slaveHosts as $host) { |
||
121 | $slaves[] = [ |
||
122 | 'user' => getenv('DB_USER'), |
||
123 | 'password' => getenv('DB_PASS'), |
||
124 | 'host' => $host, |
||
125 | 'dbname' => getenv('DB_NAME'), |
||
126 | ]; |
||
127 | } |
||
128 | } else { |
||
129 | $slaves[] = [ |
||
130 | 'user' => getenv('DB_USER'), |
||
131 | 'password' => getenv('DB_PASS'), |
||
132 | 'host' => getenv('DB_HOST'), |
||
133 | 'dbname' => getenv('DB_NAME'), |
||
134 | ]; |
||
135 | } |
||
136 | $connection = DriverManager::getConnection([ |
||
137 | 'wrapperClass' => 'Doctrine\DBAL\Connections\MasterSlaveConnection', |
||
138 | 'driver' => 'pdo_mysql', |
||
139 | 'master' => [ |
||
140 | 'user' => getenv('DB_USER'), |
||
141 | 'password' => getenv('DB_PASS'), |
||
142 | 'host' => getenv('DB_HOST'), |
||
143 | 'dbname' => getenv('DB_NAME'), |
||
144 | ], |
||
145 | 'slaves' => $slaves, |
||
146 | ]); |
||
147 | $entityManager = EntityManager::create($connection, $config); |
||
148 | Registry::set('em', $entityManager); |
||
149 | |||
150 | try { |
||
151 | $dbPlatform = $entityManager->getConnection()->getDatabasePlatform(); |
||
152 | $dbPlatform->registerDoctrineTypeMapping('enum', 'string'); |
||
153 | $dbPlatform->registerDoctrineTypeMapping('bit', 'boolean'); |
||
154 | } catch (DBALException $e) { |
||
155 | echo $e->getMessage(); |
||
156 | return false; |
||
157 | } |
||
158 | AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', BASEPATH.DS.'external/jms/serializer/src'); |
||
159 | Registry::set('serializer', SerializerBuilder::create()->addMetadataDir(BASEPATH.DS.'src')->build()); |
||
160 | return true; |
||
161 | } |
||
214 |