Code Duplication    Length = 47-48 lines in 2 locations

src/ElasticsearchExtraBundle/Handler/CreateIndexHandler.php 1 location

@@ 13-60 (lines=48) @@
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class CreateIndexHandler
14
{
15
    /**
16
     * @var ClientRepository
17
     */
18
    private $clientRepository;
19
20
    /**
21
     * @var IndexConfigurationRepository
22
     */
23
    private $configurationRepository;
24
25
    /**
26
     * @param ClientRepository             $clientRepository
27
     * @param IndexConfigurationRepository $configurationRepository
28
     */
29
    public function __construct(
30
        ClientRepository $clientRepository,
31
        IndexConfigurationRepository $configurationRepository
32
    ) {
33
        $this->clientRepository        = $clientRepository;
34
        $this->configurationRepository = $configurationRepository;
35
    }
36
37
    /**
38
     * Handle index creation command
39
     *
40
     * @param string $clientId
41
     * @param string $indexId
42
     */
43
    public function handle($clientId, $indexId)
44
    {
45
        $client = $this->clientRepository->get($clientId);
46
        $config = $this->configurationRepository->get($clientId, $indexId);
47
48
        if (null === $client || null === $config) {
49
            throw new \InvalidArgumentException();
50
        }
51
52
        $client
53
            ->indices()
54
            ->create([
55
                'index' => $indexId,
56
                'body'  => $config,
57
            ])
58
        ;
59
    }
60
}

src/ElasticsearchExtraBundle/Handler/DeleteIndexHandler.php 1 location

@@ 13-59 (lines=47) @@
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class DeleteIndexHandler
14
{
15
    /**
16
     * @var ClientRepository
17
     */
18
    private $clientRepository;
19
20
    /**
21
     * @var IndexConfigurationRepository
22
     */
23
    private $configurationRepository;
24
25
    /**
26
     * @param ClientRepository             $clientRepository
27
     * @param IndexConfigurationRepository $configurationRepository
28
     */
29
    public function __construct(
30
        ClientRepository $clientRepository,
31
        IndexConfigurationRepository $configurationRepository
32
    ) {
33
        $this->clientRepository        = $clientRepository;
34
        $this->configurationRepository = $configurationRepository;
35
    }
36
37
    /**
38
     * Handle index deletion command
39
     *
40
     * @param string $clientId
41
     * @param string $indexId
42
     */
43
    public function handle($clientId, $indexId)
44
    {
45
        $client = $this->clientRepository->get($clientId);
46
        $config = $this->configurationRepository->get($clientId, $indexId);
47
48
        if (null === $client || null === $config) {
49
            throw new \InvalidArgumentException();
50
        }
51
52
        $client
53
            ->indices()
54
            ->delete([
55
                'index' => $indexId,
56
            ])
57
        ;
58
    }
59
}