Improved code

This commit is contained in:
Alejandro Celaya 2018-08-01 20:28:05 +02:00
parent 899771cc2e
commit f4b569c245
2 changed files with 10 additions and 10 deletions

View file

@ -23,8 +23,7 @@ class EntityManagerFactory implements FactoryInterface
* @param null|array $options * @param null|array $options
* @return object * @return object
* @throws ServiceNotFoundException if unable to resolve the service. * @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when * @throws ServiceNotCreatedException if an exception is raised when creating a service.
* creating a service.
* @throws ContainerException if any other error occurs * @throws ContainerException if any other error occurs
*/ */
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
@ -32,14 +31,14 @@ class EntityManagerFactory implements FactoryInterface
$globalConfig = $container->get('config'); $globalConfig = $container->get('config');
$isDevMode = isset($globalConfig['debug']) ? ((bool) $globalConfig['debug']) : false; $isDevMode = isset($globalConfig['debug']) ? ((bool) $globalConfig['debug']) : false;
$cache = $container->has(Cache::class) ? $container->get(Cache::class) : new ArrayCache(); $cache = $container->has(Cache::class) ? $container->get(Cache::class) : new ArrayCache();
$emConfig = isset($globalConfig['entity_manager']) ? $globalConfig['entity_manager'] : []; $emConfig = $globalConfig['entity_manager'] ?? [];
$connecitonConfig = isset($emConfig['connection']) ? $emConfig['connection'] : []; $connectionConfig = $emConfig['connection'] ?? [];
$ormConfig = isset($emConfig['orm']) ? $emConfig['orm'] : []; $ormConfig = $emConfig['orm'] ?? [];
return EntityManager::create($connecitonConfig, Setup::createAnnotationMetadataConfiguration( return EntityManager::create($connectionConfig, Setup::createAnnotationMetadataConfiguration(
isset($ormConfig['entities_paths']) ? $ormConfig['entities_paths'] : [], $ormConfig['entities_paths'] ?? [],
$isDevMode, $isDevMode,
isset($ormConfig['proxies_dir']) ? $ormConfig['proxies_dir'] : null, $ormConfig['proxies_dir'] ?? null,
$cache, $cache,
false false
)); ));

View file

@ -57,10 +57,11 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
->orderBy('totalVisits', $order); ->orderBy('totalVisits', $order);
return \array_column($qb->getQuery()->getResult(), 0); return \array_column($qb->getQuery()->getResult(), 0);
} elseif (\in_array($fieldName, ['originalUrl', 'shortCode', 'dateCreated'], true)) {
$qb->orderBy('s.' . $fieldName, $order);
} }
if (\in_array($fieldName, ['originalUrl', 'shortCode', 'dateCreated'], true)) {
$qb->orderBy('s.' . $fieldName, $order);
}
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }