FacetConverter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 19.12 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 13
loc 68
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canHandle() 0 11 3
A handle() 13 13 3
A buildFacet() 0 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway;
4
5
use eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder;
6
use Kaliop\EzFindSearchEngineBundle\Core\Base\Exceptions\NotImplementedException;
7
8
class FacetConverter extends Converter
9
{
10
    /**
11
     * Check if the FacetBuilder can be handled by any of the available handlers.
12
     *
13
     * @param FacetBuilder $facetBuilder
14
     * @return bool
15
     */
16
    public function canHandle(FacetBuilder $facetBuilder)
17
    {
18
        /** @var FacetHandler $handler */
19
        foreach ($this->handlers as $handler) {
20
            if ($handler->accept($facetBuilder)) {
21
                return true;
22
            }
23
        }
24
25
        return false;
26
    }
27
28
    /**
29
     * Map facet builder value to a proper SOLR representation.
30
     *
31
     * @param FacetBuilder $facetBuilder
32
     * @return array
33
     *
34
     * @throws NotImplementedException
35
     */
36 View Code Duplication
    public function handle(FacetBuilder $facetBuilder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        /** @var FacetHandler $handler */
39
        foreach ($this->handlers as $handler) {
40
            if ($handler->accept($facetBuilder)) {
41
                return $handler->handle($facetBuilder);
42
            }
43
        }
44
45
        throw new NotImplementedException(
46
            'No facet handler available for: ' . get_class($facetBuilder)
47
        );
48
    }
49
50
    /**
51
     * Map eZFind facet results to correct facet handler.
52
     *
53
     * @param FacetBuilder $facetBuilder
54
     * @param array $fields
55
     * @param array $queries
56
     * @param array $dates
57
     * @param array $ranges
58
     * @return \eZ\Publish\API\Repository\Values\Content\Search\Facet
59
     *
60
     * @throws NotImplementedException
61
     */
62
    public function buildFacet(FacetBuilder $facetBuilder, $fields = [], $queries = [], $dates = [], $ranges = [])
63
    {
64
        foreach ($this->handlers as $handler) {
65
            /** @var FacetHandler $handler */
66
            if ($handler->accept($facetBuilder)) {
67
                return $handler->createFacetResult($facetBuilder, $fields, $queries, $dates, $ranges);
68
            }
69
        }
70
71
        throw new NotImplementedException(
72
            'No facet handler available for: ' . get_class($facetBuilder)
73
        );
74
    }
75
}
76