Completed
Push — preprodparkur ( c7da1d...18f684 )
by
unknown
01:12 queued 33s
created

ChamiloExtension::getChamiloPageTitle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Twig\Extension;
5
6
use Twig\TwigFunction;
7
8
/**
9
 * Class ChamiloExtension.
10
 *
11
 * @package Chamilo\CoreBundle\Twig\Extension
12
 */
13
class ChamiloExtension extends \Twig_Extension
14
{
15
    /**
16
     * @return array
17
     */
18
    public function getFilters()
19
    {
20
        return [
21
            new \Twig_SimpleFilter('var_dump', 'var_dump'),
22
            new \Twig_SimpleFilter('icon', 'Template::get_icon_path'),
23
            new \Twig_SimpleFilter('api_get_local_time', 'api_get_local_time'),
24
        ];
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getFunctions()
31
    {
32
        return [
33
            new TwigFunction('chamilo_page_title_get', [$this, 'getChamiloPageTitle']),
34
        ];
35
    }
36
37
    public function getChamiloPageTitle(): string
38
    {
39
        $urlPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
40
        $urlPath = rtrim($urlPath, '/');
41
        $parts = explode('/', $urlPath);
42
        $title = end($parts);
43
44
        $titleList = [];
45
        $titleList[] = 'OFAJ';     // api_get_setting('Institution');
46
        $titleList[] = 'PARKUR';     // api_get_setting('siteName');
47
        $titleList[] = ucfirst(str_replace('-', ' ', $title));    // Page title
48
49
        $titleString = '';
50
        for ($i = 0; $i < count($titleList); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
51
            $titleString .= $titleList[$i];
52
            if (isset($titleList[$i + 1])) {
53
                $item = trim($titleList[$i + 1]);
54
                if (!empty($item)) {
55
                    $titleString .= ' - ';
56
                }
57
            }
58
        }
59
60
        return $titleString;
61
    }
62
63
    /**
64
     * Returns the name of the extension.
65
     *
66
     * @return string The extension name
67
     */
68
    public function getName()
69
    {
70
        return 'chamilo_extension';
71
    }
72
}
73