GenericLink::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
namespace rtens\domin\delivery\web\renderers\link\types;
3
4
use rtens\domin\delivery\web\renderers\link\Link;
5
6
class GenericLink implements Link {
7
8
    private $actionId;
9
    private $parameters;
10
    private $handles;
11
    private $confirmation;
12
13
    public function __construct($actionId, callable $handles, callable $parameters = null) {
14
        $this->actionId = $actionId;
15
        $this->handles = $handles;
16
        $this->parameters = $parameters ?: function () {
17
            return [];
18
        };
19
    }
20
21
    public function setHandles(callable $handles) {
22
        $this->handles = $handles;
23
        return $this;
24
    }
25
26
    /**
27
     * @param object $object
28
     * @return boolean
29
     */
30
    public function handles($object) {
31
        return call_user_func($this->handles, $object);
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function actionId() {
38
        return $this->actionId;
39
    }
40
41
    /**
42
     * @param object $object
43
     * @return array|mixed[] Values indexed by parameter names
44
     */
45
    public function parameters($object) {
46
        return call_user_func($this->parameters, $object);
47
    }
48
49
    /**
50
     * Message that needs to be confirmed before the action can be executed
51
     * @param string|null $confirmation
52
     * @return $this
53
     */
54
    public function setConfirmation($confirmation) {
55
        $this->confirmation = $confirmation;
56
        return $this;
57
    }
58
59
    /**
60
     * A message that needs to be confirmed before the action can be executed (or null if not required)
61
     * @return string|null
62
     */
63
    public function confirm() {
64
        return $this->confirmation;
65
    }
66
}