GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TwigExtension   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 2 Features 0
Metric Value
dl 0
loc 48
rs 10
c 3
b 2
f 0
wmc 12
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A matchesRoute() 0 4 1
A getFunctions() 0 7 1
D parsePeriod() 0 26 9
1
<?php
2
3
/*  ATICA - Web application for supporting Quality Management Systems
4
  Copyright (C) 2009-2015: Luis-Ramón López López
5
6
  This program is free software: you can redistribute it and/or modify
7
  it under the terms of the GNU Affero General Public License as published by
8
  the Free Software Foundation, either version 3 of the License, or
9
  (at your option) any later version.
10
11
  This program is distributed in the hope that it will be useful,
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
  GNU Affero General Public License for more details.
15
16
  You should have received a copy of the GNU Affero General Public License
17
  along with this program.  If not, see [http://www.gnu.org/licenses/]. */
18
19
namespace Atica\Extension;
20
use \Slim\Slim;
21
22
class TwigExtension extends \Twig_Extension
23
{
24
    public function getName()
25
    {
26
        return 'atica';
27
    }
28
29
    public function getFunctions()
30
    {
31
        return array(
32
            new \Twig_SimpleFunction('parsePeriod', array($this, 'parsePeriod')),
33
            new \Twig_SimpleFunction('matchesRoute', array($this, 'matchesRoute'))
34
        );
35
    }
36
    
37
    public function parsePeriod($from, $to, $strings) {
38
39
        if (($from === NULL) || ($to === NULL)) {
40
            return "";
41
        }
42
43
        // Mes(es) completo
44
        if ((($from % 4) == 0) && (($to % 4) == 3)) {
45
            $return = $strings['months'][floor($from / 4)];
46
            if ((floor($from / 4)) != floor($to / 4)) {
47
                $return .= "-" . $strings['months'][floor($to / 4)];
48
            }
49
        }
50
        elseif ((($from % 2) == 0) && ($to == $from + 1)) {
51
            $return = $strings['halfmonths'][($from % 4)/2] . $strings['months'][floor($from / 4)];
52
        }
53
        else {
54
            $return = $strings['weeks'][$from % 4] . $strings['months'][floor($from / 4)];
55
            if ($from != $to) {
56
                $return .= ' a ';
57
                $return .= $strings['weeks'][$to % 4] . $strings['months'][floor($to / 4)];
58
            }
59
        }
60
61
        return $return;
62
    }
63
    
64
    public function matchesRoute($route, $appName = 'default')
65
    {
66
        return (Slim::getInstance($appName)->router()->getCurrentRoute()->getName() == $route);
67
    }
68
69
}
70