Passed
Pull Request — master (#5)
by Dante
02:15
created

HtmlHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A title() 0 14 4
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2018 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
14
namespace BEdita\WebTools\View\Helper;
15
16
use Cake\Utility\Inflector;
17
use Cake\View\Helper\HtmlHelper as CakeHtmlHelper;
18
19
/**
20
 * Html helper.
21
 * It extends {@see \Cake\View\Helper\HtmlHelper} Cake Html Helper
22
 */
23
class HtmlHelper extends CakeHtmlHelper
24
{
25
    /**
26
     * Title for template pages
27
     * If `_title` view var is set, return it
28
     * Otherwise return controller name (and action name if set)
29
     *
30
     * @return string
31
     */
32
    public function title() : string
33
    {
34
        if (isset($this->getView()->viewVars['_title'])) {
35
            return $this->getView()->viewVars['_title'];
36
        }
37
        $title = Inflector::humanize($this->getView()->request->getParam('controller', ''));
38
        $suffix = Inflector::humanize($this->getView()->request->getParam('action', ''));
39
        if (empty($title)) {
40
            $title = $suffix;
41
        } elseif (!empty($suffix)) {
42
            $title .= sprintf(' - %s', $suffix);
43
        }
44
45
        return $title;
46
    }
47
}
48