CategoryRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B findFrontCategories() 0 24 2
1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\Repository;
13
14
use Orbitale\Bundle\CmsBundle\Entity\Category;
15
16
class CategoryRepository extends AbstractCmsRepository
17
{
18
    /**
19
     * @param array $slugs
20
     *
21
     * @return Category[]
22
     */
23
    public function findFrontCategories(array $slugs)
24
    {
25
        $qb = $this->createQueryBuilder('category')
26
            ->where('category.enabled = :enabled')
27
            ->setParameter('enabled', true)
28
            ->andWhere('category.slug IN ( :slugs )')
29
            ->setParameter('slugs', $slugs)
30
        ;
31
32
        /** @var Category[] $results */
33
        $results = $qb
34
            ->getQuery()
35
            ->useResultCache($this->cacheEnabled, $this->cacheTtl)
36
            ->getResult()
37
        ;
38
39
        $resultsSortedBySlug = [];
40
41
        foreach ($results as $category) {
42
            $resultsSortedBySlug[$category->getSlug()] = $category;
43
        }
44
45
        return $resultsSortedBySlug;
46
    }
47
}
48