CallableTrait::getCallable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MisterIcy\ExcelWriter\Properties\Traits;
5
6
use MisterIcy\ExcelWriter\Properties\AbstractProperty;
7
8
/**
9
 * Callable Trait defines a shared trait for all classes that should have callable functions.
10
 *
11
 * For the time being, this is only used by {@see AbstractProperty} to define properties
12
 * that execute a function, before rendering their result
13
 *
14
 * @author Alexandros Koutroulis <[email protected]>
15
 * @license MIT
16
 *
17
 * @package MisterIcy\ExcelWriter\Properties\Traits
18
 */
19
trait CallableTrait
20
{
21
    /** @var callable|null */
22
    protected $callable = null;
23
24
    protected function handleCallable($object)
25
    {
26
        if (is_null($this->callable)) {
27
            throw new \Error("Undefined Callable");
28
        }
29
        return call_user_func($this->callable, $object);
30
    }
31
32
    /**
33
     * @return callable|null
34
     */
35
    public function getCallable()
36
    {
37
        return $this->callable;
38
    }
39
40
    /**
41
     * @param callable $callable
42
     * @return self
43
     */
44
    public function setCallable(callable $callable) : self
45
    {
46
        $this->callable = $callable;
47
        return $this;
48
    }
49
}
50