Help   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 246
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 33
lcom 4
cbo 1
dl 0
loc 246
ccs 0
cts 107
cp 0
rs 9.3999
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getLayout() 0 4 2
D getFormatedUsage() 0 32 9
A hasPluginSignature() 0 4 1
A hasManyOutputFormats() 0 4 1
A getOutputFormats() 0 15 2
B getInputFormats() 0 16 6
A getPathParams() 0 9 3
A getQueryParams() 0 9 3
A getReturns() 0 8 3
A getVersion() 0 12 3
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\View\ViewModel;
14
15
class Help extends Common
16
{
17
    /**
18
     * Holds the supported format definitions.
19
     * @var array
20
     */
21
    protected $format_defs = array(
22
        'post' => array(
23
            'url'  => 'http://en.wikipedia.org/wiki/POST_%28HTTP%29',
24
            'mime' => 'application/x-www-form-urlencoded',
25
            'ext'  => null,
26
            'input' => 'encoded key-value pairs.',
27
        ),
28
        'html' => array(
29
            'url'  => 'http://en.wikipedia.org/wiki/HTML',
30
            'name' => 'HyperText Markup Language',
31
            'mime' => 'text/html', // application/xhtml+xml
32
            'ext'  => '.html'
33
        ),
34
        'json' => array(
35
            'url'  => 'http://en.wikipedia.org/wiki/Json',
36
            'name' => 'JavaScript Object Notation',
37
            'mime' => 'application/json',
38
            'ext'  => '.json',
39
        ),
40
        'jsonp' => array(
41
            'url'  => 'http://en.wikipedia.org/wiki/JSONP',
42
            'name' => 'JSON with padding',
43
            'mime' => 'application/javascript', // one day: application/json-p
44
            'ext'  => '.jsonp'
45
        ),
46
        'php' => array(
47
            'url'  => 'http://php.net/manual/en/function.serialize.php',
48
            'name' => 'Byte-stream representation',
49
            'mime' => 'text/plain',
50
            'ext'  => '.php'
51
        ),
52
        'xml' => array(
53
            'url'  => 'http://en.wikipedia.org/wiki/XML',
54
            'name' => 'Extensible Markup Language',
55
            'mime' => 'text/xml', // application/xhtml+xml
56
            'ext'  => '.xml',
57
        ),
58
        'csv' => array(
59
            'url'  => 'http://en.wikipedia.org/wiki/Comma-separated_values',
60
            'name' => 'Comma-separated values',
61
            'mime' => 'text/xml', // application/xhtml+xml
62
            'ext'  => '.csv'
63
        )
64
    );
65
66
    /**
67
     * Holds the usage string.
68
     * @var string
69
     */
70
    protected $usage = null;
71
72
    /**
73
     * Gets the view layout.
74
     *
75
     * @return string
76
     */
77
    public function getLayout()
78
    {
79
        return isset($this->items) ? 'man_toc' : 'man_page';
80
    }
81
82
    /**
83
     * Returns the Usage field formatted
84
     *
85
     * @return string
86
     */
87
    public function getFormatedUsage()
88
    {
89
        if (null === $this->usage) {
90
            $this->usage = '<dl><dt class="flush">'
91
                            // . $this->path
92
                            . $this->options['rel_path'];
93
94
            if (isset($this->params)) {
95
                foreach ($this->params as $var) {
0 ignored issues
show
Bug introduced by
The property params does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
96
                    $this->usage .= !$var['required']
97
                        ? '<span>:' . $var['name'] . '</span>'
98
                        : '/:' .$var['name'];
99
                }
100
            }
101
            $this->usage .= '</dt><dd>';
102
            if (isset($this->globals)) {
103
                foreach ($this->globals as $param) {
0 ignored issues
show
Bug introduced by
The property globals does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
104
                    $types = explode('|', $param['type']);
105
                    if (! in_array('null', $types) ) {
106
                        $this->usage .= '<span>' . $param['name'];
107
                        if ($param['type'] != 'null') {
108
                            $this->usage .= '=<i>' . $param['type'] . '</i>';
109
                        }
110
                        $this->usage .= '</span>';
111
                    }
112
                }
113
            }
114
            $this->usage .= '</dd></dl>';
115
        }
116
117
        return $this->usage;
118
    }
119
120
    /**
121
     * Checks wether the plugin signature is enable.
122
     *
123
     * @return boolean
124
     */
125
    public function hasPluginSignature()
126
    {
127
        return in_array('Apix\Plugin\OutputSign', $this->config['plugins']);
128
    }
129
130
    /**
131
     * Checks wether many output format are available.
132
     *
133
     * @return boolean
134
     */
135
    public function hasManyOutputFormats()
136
    {
137
        return $this->config['routing']['formats'] > 1;
138
    }
139
140
    /**
141
     * Returns the formatted Output formats.
142
     *
143
     * @return array
144
     */
145
    public function getOutputFormats()
146
    {
147
        $formatted = array();
148
        sort($this->config['routing']['formats']);
149
        foreach ($this->config['routing']['formats'] as $k) {
150
            $item = &$this->format_defs[$k];
151
            $formatted[] = sprintf(
152
                '<td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td>',
153
                $item['url'], strtoupper($k),
154
                $item['name'], $item['ext'], $item['mime']
155
            );
156
        }
157
158
        return $formatted;
159
    }
160
161
    // public function getOutputExtensionExamples()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
162
    // {
163
    //     $formats = &$this->format_defs;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
164
    //     $formatted = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
165
    //     sort($this->config['routing']['formats']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
    //     foreach ($this->config['routing']['formats'] as $k) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
167
    //         $ext = $formats[$k]['ext'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
168
    //         $formatted[] = sprintf(
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
169
    //             '<a href="/help/:path%s">/help<b>%s</b></a>', $ext, $ext
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
170
    //         );
171
    //     }
172
173
    //     return $formatted;
174
    // }
175
176
    /**
177
     * Returns formatted Input formats
178
     *
179
     * @return array
180
     */
181
    public function getInputFormats()
182
    {
183
        $formats = &$this->format_defs;
184
        $formatted = array();
185
        foreach ($this->config['input_formats'] as $k) {
186
            $formatted[] = sprintf(
187
                '"<var>%s</var>" for <a href="%s">%s</a> %s',
188
                isset($formats[$k]['mime']) ? $formats[$k]['mime'] : 'n/a',
189
                isset($formats[$k]['url']) ? $formats[$k]['url'] : '#',
190
                $k != 'post' ? strtoupper($k) : '',
191
                isset($formats[$k]['input']) ? $formats[$k]['input'] : 'formatted data.'
192
            );
193
        }
194
195
        return $formatted;
196
    }
197
198
    /**
199
     * Deals with the resource parameters definitions.
200
     *
201
     * @return array
202
     */
203
    public function getPathParams()
204
    {
205
        if (isset($this->params) && !empty($this->params)) {
206
            return array(
207
                'prefix' => ':',
208
                'items'  => array_values($this->params)
209
            );
210
        }
211
    }
212
213
    /**
214
     * Deals with the request params/filters definitions.
215
     *
216
     * @return array
217
     */
218
    public function getQueryParams()
219
    {
220
        if (isset($this->globals) && !empty($this->globals)) {
221
            return array(
222
                'prefix' => '&',
223
                'items' => array_values($this->globals)
224
            );
225
        }
226
    }
227
228
    /**
229
     * Returns the response entries.
230
     *
231
     * @return array
232
     */
233
    public function getReturns()
234
    {
235
        if (isset($this->return) && !empty($this->return)) {
236
            return array(
237
                'items' => array_values($this->return)
0 ignored issues
show
Bug introduced by
The property return does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
238
            );
239
        }
240
    }
241
242
    /**
243
     * Deals with the request params/filters definitions.
244
     *
245
     * @return array
246
     */
247
    public function getVersion()
248
    {
249
        if (isset($this->version)) {
250
            if (is_array($this->version)) {
251
                $this->version = 'version <b>'
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
252
                        . implode('</b>, version <b>', $this->version)
253
                        . '</b>';
254
            }
255
256
            return $this->version;
257
        }
258
    }
259
260
}
261