Code Duplication    Length = 49-49 lines in 2 locations

src/mappers/JobBindingToQueueCreateMapper.php 1 location

@@ 13-61 (lines=49) @@
10
use mcorten87\rabbitmq_api\objects\Url;
11
use mcorten87\rabbitmq_api\services\MqManagementConfig;
12
13
class JobBindingToQueueCreateMapper extends BaseMapper
14
{
15
    protected function mapMethod() : Method
16
    {
17
        return new Method(Method::POST);
18
    }
19
20
    /**
21
     * @param JobBindingToQueueCreate $job
22
     * @return Url
23
     */
24
    protected function mapUrl(JobBase $job) : Url
25
    {
26
        if (!$job instanceof JobBindingToQueueCreate) {
27
            throw new WrongArgumentException($job, self::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->getQueueName())
36
        );
37
    }
38
39
    /**
40
     * @param JobBindingToQueueCreate $job
41
     * @return array
42
     */
43
    protected function mapConfig(JobBase $job) : array {
44
        if (!$job instanceof JobBindingToQueueCreate) {
45
            throw new \RuntimeException('Wrong argument');
46
        }
47
48
        $body = [
49
            'arguments'         => [],
50
            'destination'       => (string)$job->getQueueName(),
51
            'destination_type'  => $job->getDestinationType(),
52
            'routing_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/JobBindingToExchangeCreateMapper.php 1 location

@@ 11-59 (lines=49) @@
8
use mcorten87\rabbitmq_api\objects\Method;
9
use mcorten87\rabbitmq_api\objects\Url;
10
11
class JobBindingToExchangeCreateMapper extends BaseMapper
12
{
13
    protected function mapMethod() : Method
14
    {
15
        return new Method(Method::POST);
16
    }
17
18
    /**
19
     * @param JobBase $job
20
     * @return Url
21
     * @throws WrongArgumentException
22
     */
23
    protected function mapUrl(JobBase $job) : Url
24
    {
25
        if (!$job instanceof JobBindingToExchangeCreate) {
26
            throw new WrongArgumentException($job, JobBindingToExchangeCreate::class);
27
        }
28
29
        return new Url('bindings/'
30
            .urlencode((string)$job->getVirtualHost()).'/'
31
            .'e/'
32
            .urlencode((string)$job->getExchangeName()).'/'
33
            .$job->getDestinationType().'/'
34
            .urlencode((string)$job->getToExchange()));
35
    }
36
37
    /**
38
     * @param JobBase $job
39
     * @return array
40
     * @throws WrongArgumentException
41
     */
42
    protected function mapConfig(JobBase $job) : array
43
    {
44
        if (!$job instanceof JobBindingToExchangeCreate) {
45
            throw new WrongArgumentException($job, JobBindingToExchangeCreate::class);
46
        }
47
48
        $body = [
49
            'arguments'         => [],
50
            'destination'       => (string)$job->getToExchange(),
51
            'destination_type'  => $job->getDestinationType(),
52
            'routing_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