Code Duplication    Length = 34-34 lines in 2 locations

src/AlgoliaSpecification/QueryFactory/AndXFactory.php 1 location

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

src/AlgoliaSpecification/QueryFactory/OrXFactory.php 1 location

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