ProducerMethods   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isPassive() 0 3 1
A isDurable() 0 3 1
A options() 0 3 1
A mergeOptions() 0 4 1
A isAutoDelete() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of amqp
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
 
10
declare(strict_types=1);
11
12
namespace Slick\Amqp\Producer;
13
14
use Slick\Amqp\Producer;
15
16
/**
17
 * ProducerMethods
18
 *
19
 * @package Slick\Amqp\Producer
20
 */
21
trait ProducerMethods
22
{
23
    /**
24
     * @var array<string, mixed>
25
     */
26
    protected array $options = [];
27
28
    /**
29
     * @var array<string, mixed>
30
     */
31
    protected static array $defaultOptions = [
32
        Producer::OPT_PASSIVE => false,
33
        Producer::OPT_DURABLE => false,
34
        Producer::OPT_AUTO_DELETE => true,
35
        Producer::OPT_INTERNAL => false,
36
        Producer::OPT_NOWAIT => false,
37
        Producer::OPT_ARGUMENTS => [],
38
        Producer::OPT_TICKET => null
39
    ];
40
41
    /**
42
     * Merges provided options
43
     *
44
     * @param array<string, mixed>|null $options
45
     * @return self
46
     */
47
    protected function mergeOptions(?array $options = []): self
48
    {
49
        $this->options = array_merge(self::$defaultOptions, $this->options, $options ?? []);
50
        return $this;
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function isPassive(): bool
57
    {
58
        return (bool) $this->options[Producer::OPT_PASSIVE];
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function isDurable(): bool
65
    {
66
        return (bool) $this->options[Producer::OPT_DURABLE];
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function isAutoDelete(): bool
73
    {
74
        return (bool) $this->options[Producer::OPT_AUTO_DELETE];
75
    }
76
77
    /**
78
     * Exchange/Producer options
79
     *
80
     * @return array<string, mixed>
81
     */
82
    public function options(): array
83
    {
84
        return $this->options;
85
    }
86
}
87