Code Duplication    Length = 49-52 lines in 2 locations

src/mappers/JobBindingToExchangeDeleteMapper.php 1 location

@@ 13-61 (lines=49) @@
10
use mcorten87\rabbitmq_api\objects\Url;
11
use mcorten87\rabbitmq_api\services\MqManagementConfig;
12
13
class JobBindingToExchangeDeleteMapper extends BaseMapper
14
{
15
    protected function mapMethod() : Method
16
    {
17
        return new Method(Method::DELETE);
18
    }
19
20
    /**
21
     * @param JobBindingToExchangeDelete $job
22
     * @return Url
23
     */
24
    protected function mapUrl(JobBase $job) : Url
25
    {
26
        if (!$job instanceof JobBindingToExchangeDelete) {
27
            throw new WrongArgumentException($job, JobBindingToExchangeDelete::class);
28
        }
29
30
        return new Url('bindings/'
31
            .urlencode((string)$job->getVirtualHost()).'/'
32
            .'e/'
33
            .urlencode((string)$job->getExchangeName()).'/'
34
            .$job->getDestinationType().'/'
35
            .urlencode((string)$job->getToExchange())
36
            .'/'.(!empty((string) $job->getRoutingKey()) ? (string) $job->getRoutingKey() : '~')
37
        );
38
    }
39
40
    /**
41
     * @param JobBindingToExchangeDelete $job
42
     * @return array
43
     */
44
    protected function mapConfig(JobBase $job) : array {
45
        if (!$job instanceof JobBindingToExchangeDelete) {
46
            throw new WrongArgumentException($job, JobBindingToExchangeDelete::class);
47
        }
48
49
        $body = [
50
            'destination'       => (string)$job->getToExchange(),
51
            'destination_type'  => $job->getDestinationType(),
52
            'properties_key'       => (string)$job->getRoutingKey(),
53
            'source'            => (string)$job->getExchangeName(),
54
            'vhost'             => $job->getVirtualHost(),
55
        ];
56
57
        return array_merge(parent::mapConfig($job), [
58
            'json'      =>  $body,
59
        ]);
60
    }
61
}
62

src/mappers/JobBindingToQueueDeleteMapper.php 1 location

@@ 13-64 (lines=52) @@
10
use mcorten87\rabbitmq_api\objects\Url;
11
use mcorten87\rabbitmq_api\services\MqManagementConfig;
12
13
class JobBindingToQueueDeleteMapper extends BaseMapper
14
{
15
    protected function mapMethod() : Method
16
    {
17
        return new Method(Method::DELETE);
18
    }
19
20
    /**
21
     * @param JobBindingToQueueDelete $job
22
     * @return Url
23
     */
24
    protected function mapUrl(JobBase $job) : Url
25
    {
26
        if (!$job instanceof JobBindingToQueueDelete) {
27
            throw new WrongArgumentException($job, JobBindingToQueueDelete::class);
28
        }
29
30
31
        return new Url('bindings/'
32
            .urlencode((string)$job->getVirtualHost()).'/'
33
            .'e/'
34
            .urlencode((string)$job->getExchangeName()).'/'
35
            .$job->getDestinationType().'/'
36
            .urlencode((string)$job->getQueueName())
37
            .'/'.(!empty((string) $job->getRoutingKey()) ? (string) $job->getRoutingKey() : '~')
38
        );
39
    }
40
41
    /**
42
     * @param JobBindingToQueueDelete $job
43
     * @return array
44
     */
45
    protected function mapConfig(JobBase $job) : array {
46
        if (!$job instanceof JobBindingToQueueDelete) {
47
            throw new WrongArgumentException($job, JobBindingToQueueDelete::class);
48
        }
49
50
51
        $body = [
52
            'arguments'         => [],
53
            'destination'       => (string)$job->getQueueName(),
54
            'destination_type'  => $job->getDestinationType(),
55
            'routing_key'       => (string)$job->getRoutingKey(),
56
            'source'            => (string)$job->getExchangeName(),
57
            'vhost'             => $job->getVirtualHost(),
58
        ];
59
60
        return array_merge(parent::mapConfig($job), [
61
            'json'      =>  $body,
62
        ]);
63
    }
64
}
65