Code Duplication    Length = 34-34 lines in 2 locations

src/AlgoliaSpecification/QueryFactory/AndXFactory.php 1 location

@@ 14-47 (lines=34) @@
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class AndXFactory implements Factory
15
{
16
    /**
17
     * @var Registry
18
     */
19
    private $registry;
20
21
    /**
22
     * @param Registry $registry
23
     */
24
    public function __construct(Registry $registry)
25
    {
26
        $this->registry = $registry;
27
    }
28
29
    /**
30
     * {inheritdoc}
31
     */
32
    public function create(Specification $spec)
33
    {
34
        if (!$spec instanceof AndX) {
35
            throw new \InvalidArgumentException();
36
        }
37
38
        $firstPartFactory  = $this->registry->getFactory($spec->getFirstPart());
39
        $secondPartFactory = $this->registry->getFactory($spec->getSecondPart());
40
41
        return sprintf(
42
            '(%s) AND (%s)',
43
            $firstPartFactory->create($spec->getFirstPart()),
44
            $secondPartFactory->create($spec->getSecondPart())
45
        );
46
    }
47
}
48

src/AlgoliaSpecification/QueryFactory/OrXFactory.php 1 location

@@ 14-47 (lines=34) @@
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class OrXFactory implements Factory
15
{
16
    /**
17
     * @var Registry
18
     */
19
    private $registry;
20
21
    /**
22
     * @param Registry $registry
23
     */
24
    public function __construct(Registry $registry)
25
    {
26
        $this->registry = $registry;
27
    }
28
29
    /**
30
     * {inheritdoc}
31
     */
32
    public function create(Specification $spec)
33
    {
34
        if (!$spec instanceof OrX) {
35
            throw new \InvalidArgumentException();
36
        }
37
38
        $firstPartFactory  = $this->registry->getFactory($spec->getFirstPart());
39
        $secondPartFactory = $this->registry->getFactory($spec->getSecondPart());
40
41
        return sprintf(
42
            '(%s) OR (%s)',
43
            $firstPartFactory->create($spec->getFirstPart()),
44
            $secondPartFactory->create($spec->getSecondPart())
45
        );
46
    }
47
}
48