AbstractPostingDecorator   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

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

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getThread() 0 3 1
A isLocked() 0 3 1
A getLevel() 0 3 1
A get() 0 3 1
A map() 0 3 1
A hasAnswers() 0 3 1
A isNt() 0 3 1
A toArray() 0 3 1
A isPinned() 0 3 1
A isRoot() 0 3 1
A __call() 0 7 2
A getAllChildren() 0 3 1
A getChildren() 0 3 1
A addDecorator() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Saito\Posting\Decorator;
14
15
use Saito\Posting\Basic\BasicPostingInterface;
16
use Saito\Posting\PostingInterface;
17
18
/**
19
 * Abstract class which allows to decorate Postings
20
 *
21
 * class MyDecorator extends AbstractPostingDecorator ...
22
 *
23
 * $postings = $postings->addDecorator(
24
 *   function ($node) {
25
 *      return new MyDecorator($node);
26
 *    }
27
 * );
28
 */
29
abstract class AbstractPostingDecorator implements BasicPostingInterface, PostingInterface
30
{
31
32
    protected $_Posting;
33
34
    /**
35
     * Make traits and other decorators available
36
     *
37
     * @param string $method method to call
38
     * @param array $args method arguments
39
     * @return mixed return value of called method
40
     */
41
    public function __call($method, $args)
42
    {
43
        if (is_callable([$this->_Posting, $method])) {
44
            return call_user_func_array([$this->_Posting, $method], $args);
45
        }
46
        throw new \RuntimeException(
47
            'Undefined method ' . get_class($this) . '::' . $method
48
        );
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function __construct(\Saito\Posting\Posting $Posting)
55
    {
56
        $this->_Posting = $Posting;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function get($var)
63
    {
64
        return $this->_Posting->get($var);
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70
    public function getChildren()
71
    {
72
        return $this->_Posting->getChildren();
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    public function getLevel(): int
79
    {
80
        return $this->_Posting->getLevel();
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86
    public function toArray()
87
    {
88
        return $this->_Posting->toArray();
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94
    public function getThread()
95
    {
96
        return $this->_Posting->getThread();
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102
    public function hasAnswers()
103
    {
104
        return $this->_Posting->hasAnswers();
105
    }
106
107
    /**
108
     * {@inheritDoc}
109
     */
110
    public function isNt(): bool
111
    {
112
        return $this->_Posting->isNt();
113
    }
114
115
    /**
116
     * Check if posting is locked.
117
     *
118
     * @return bool
119
     */
120
    public function isLocked(): bool
121
    {
122
        return $this->_Posting->isLocked();
123
    }
124
125
    /**
126
     * {@inheritDoc}
127
     */
128
    public function isPinned(): bool
129
    {
130
        return $this->_Posting->isPinned();
131
    }
132
133
    /**
134
     * {@inheritDoc}
135
     */
136
    public function isRoot(): bool
137
    {
138
        return $this->_Posting->isRoot();
139
    }
140
141
    /**
142
     * {@inheritDoc}
143
     */
144
    public function addDecorator(callable $fct)
145
    {
146
        return $this->_Posting->addDecorator($fct);
147
    }
148
149
    /**
150
     * {@inheritDoc}
151
     */
152
    public function map(callable $callback, bool $mapSelf = true, $node = null): void
153
    {
154
        $this->_Posting->map($callback, $mapSelf, $node);
155
    }
156
157
    /**
158
     * {@inheritDoc}
159
     */
160
    public function getAllChildren()
161
    {
162
        return $this->_Posting->getAllChildren();
163
    }
164
}
165