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.
Completed
Push — master ( c188f7...035d67 )
by Romain
05:21
created

__TwigTemplate_9ed5ad35b12f734b4f1460a4c46f927a638cca26e2b3cac7b371d06ed8e6913e   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 206
Duplicated Lines 13.11 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 41
lcom 2
cbo 3
dl 27
loc 206
rs 8.2769
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A doGetParent() 0 4 1
A doDisplay() 0 7 1
A block_title() 0 6 3
A block_body_class() 0 4 1
A block_page_id() 0 4 3
A block_below_menu() 0 14 3
C block_page_content() 27 74 24
A getTemplateName() 0 4 1
A isTraitable() 0 4 1
A getDebugInfo() 0 4 1
A getSourceContext() 0 48 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like __TwigTemplate_9ed5ad35b12f734b4f1460a4c46f927a638cca26e2b3cac7b371d06ed8e6913e often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use __TwigTemplate_9ed5ad35b12f734b4f1460a4c46f927a638cca26e2b3cac7b371d06ed8e6913e, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* namespace.twig */
4
class __TwigTemplate_9ed5ad35b12f734b4f1460a4c46f927a638cca26e2b3cac7b371d06ed8e6913e extends Twig_Template
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    public function __construct(Twig_Environment $env)
7
    {
8
        parent::__construct($env);
9
10
        // line 1
11
        $this->parent = $this->loadTemplate("layout/layout.twig", "namespace.twig", 1);
12
        $this->blocks = array(
13
            'title' => array($this, 'block_title'),
14
            'body_class' => array($this, 'block_body_class'),
15
            'page_id' => array($this, 'block_page_id'),
16
            'below_menu' => array($this, 'block_below_menu'),
17
            'page_content' => array($this, 'block_page_content'),
18
        );
19
    }
20
21
    protected function doGetParent(array $context)
22
    {
23
        return "layout/layout.twig";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'layout/layout.twig'; (string) is incompatible with the return type of the parent method Twig_Template::doGetParent of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
24
    }
25
26
    protected function doDisplay(array $context, array $blocks = array())
27
    {
28
        // line 2
29
        $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"] = $this->loadTemplate("macros.twig", "namespace.twig", 2);
30
        // line 1
31
        $this->parent->display($context, array_merge($this->blocks, $blocks));
0 ignored issues
show
Unused Code introduced by
The call to Twig_TemplateWrapper::display() has too many arguments starting with array_merge($this->blocks, $blocks).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
32
    }
33
34
    // line 3
35
    public function block_title($context, array $blocks = array())
36
    {
37
        echo (isset($context["namespace"]) || array_key_exists("namespace", $context) ? $context["namespace"] : (function () { throw new Twig_Error_Runtime('Variable "namespace" does not exist.', 3, $this->getSourceContext()); })());
38
        echo " | ";
39
        $this->displayParentBlock("title", $context, $blocks);
40
    }
41
42
    // line 4
43
    public function block_body_class($context, array $blocks = array())
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $blocks is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        echo "namespace";
46
    }
47
48
    // line 5
49
    public function block_page_id($context, array $blocks = array())
0 ignored issues
show
Unused Code introduced by
The parameter $blocks is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        echo twig_escape_filter($this->env, ("namespace:" . twig_replace_filter((isset($context["namespace"]) || array_key_exists("namespace", $context) ? $context["namespace"] : (function () { throw new Twig_Error_Runtime('Variable "namespace" does not exist.', 5, $this->getSourceContext()); })()), array("\\" => "_"))), "html", null, true);
52
    }
53
54
    // line 7
55
    public function block_below_menu($context, array $blocks = array())
0 ignored issues
show
Unused Code introduced by
The parameter $blocks is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        // line 8
58
        echo "    <div class=\"namespace-breadcrumbs\">
59
        <ol class=\"breadcrumb\">
60
            <li><span class=\"label label-default\">Namespace</span></li>
61
            ";
62
        // line 11
63
        echo $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"]->macro_breadcrumbs((isset($context["namespace"]) || array_key_exists("namespace", $context) ? $context["namespace"] : (function () { throw new Twig_Error_Runtime('Variable "namespace" does not exist.', 11, $this->getSourceContext()); })()));
64
        echo "
65
        </ol>
66
    </div>
67
";
68
    }
69
70
    // line 16
71
    public function block_page_content($context, array $blocks = array())
0 ignored issues
show
Unused Code introduced by
The parameter $blocks is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73
        // line 17
74
        echo "
75
    <div class=\"page-header\">
76
        <h1>";
77
        // line 19
78
        echo (isset($context["namespace"]) || array_key_exists("namespace", $context) ? $context["namespace"] : (function () { throw new Twig_Error_Runtime('Variable "namespace" does not exist.', 19, $this->getSourceContext()); })());
79
        echo "</h1>
80
    </div>
81
82
    ";
83
        // line 22
84
        if ((isset($context["subnamespaces"]) || array_key_exists("subnamespaces", $context) ? $context["subnamespaces"] : (function () { throw new Twig_Error_Runtime('Variable "subnamespaces" does not exist.', 22, $this->getSourceContext()); })())) {
85
            // line 23
86
            echo "        <h2>Namespaces</h2>
87
        <div class=\"namespace-list\">
88
            ";
89
            // line 25
90
            $context['_parent'] = $context;
91
            $context['_seq'] = twig_ensure_traversable((isset($context["subnamespaces"]) || array_key_exists("subnamespaces", $context) ? $context["subnamespaces"] : (function () { throw new Twig_Error_Runtime('Variable "subnamespaces" does not exist.', 25, $this->getSourceContext()); })()));
92
            foreach ($context['_seq'] as $context["_key"] => $context["ns"]) {
93
                echo $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"]->macro_namespace_link($context["ns"]);
94
            }
95
            $_parent = $context['_parent'];
96
            unset($context['_seq'], $context['_iterated'], $context['_key'], $context['ns'], $context['_parent'], $context['loop']);
97
            $context = array_intersect_key($context, $_parent) + $_parent;
98
            // line 26
99
            echo "        </div>
100
    ";
101
        }
102
        // line 28
103
        echo "
104
    ";
105
        // line 29
106 View Code Duplication
        if ((isset($context["classes"]) || array_key_exists("classes", $context) ? $context["classes"] : (function () { throw new Twig_Error_Runtime('Variable "classes" does not exist.', 29, $this->getSourceContext()); })())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
            // line 30
108
            echo "        <h2>Classes</h2>
109
        ";
110
            // line 31
111
            echo $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"]->macro_render_classes((isset($context["classes"]) || array_key_exists("classes", $context) ? $context["classes"] : (function () { throw new Twig_Error_Runtime('Variable "classes" does not exist.', 31, $this->getSourceContext()); })()));
112
            echo "
113
    ";
114
        }
115
        // line 33
116
        echo "
117
    ";
118
        // line 34
119 View Code Duplication
        if ((isset($context["interfaces"]) || array_key_exists("interfaces", $context) ? $context["interfaces"] : (function () { throw new Twig_Error_Runtime('Variable "interfaces" does not exist.', 34, $this->getSourceContext()); })())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
            // line 35
121
            echo "        <h2>Interfaces</h2>
122
        ";
123
            // line 36
124
            echo $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"]->macro_render_classes((isset($context["interfaces"]) || array_key_exists("interfaces", $context) ? $context["interfaces"] : (function () { throw new Twig_Error_Runtime('Variable "interfaces" does not exist.', 36, $this->getSourceContext()); })()));
125
            echo "
126
    ";
127
        }
128
        // line 38
129
        echo "
130
    ";
131
        // line 39
132 View Code Duplication
        if ((isset($context["exceptions"]) || array_key_exists("exceptions", $context) ? $context["exceptions"] : (function () { throw new Twig_Error_Runtime('Variable "exceptions" does not exist.', 39, $this->getSourceContext()); })())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
            // line 40
134
            echo "        <h2>Exceptions</h2>
135
        ";
136
            // line 41
137
            echo $context["__internal_084c0a9b4751f3912921b1f087047d19c4c1f20b347dd6cee5246a93c0cb9eed"]->macro_render_classes((isset($context["exceptions"]) || array_key_exists("exceptions", $context) ? $context["exceptions"] : (function () { throw new Twig_Error_Runtime('Variable "exceptions" does not exist.', 41, $this->getSourceContext()); })()));
138
            echo "
139
    ";
140
        }
141
        // line 43
142
        echo "
143
";
144
    }
145
146
    public function getTemplateName()
147
    {
148
        return "namespace.twig";
149
    }
150
151
    public function isTraitable()
152
    {
153
        return false;
154
    }
155
156
    public function getDebugInfo()
157
    {
158
        return array (  142 => 43,  137 => 41,  134 => 40,  132 => 39,  129 => 38,  124 => 36,  121 => 35,  119 => 34,  116 => 33,  111 => 31,  108 => 30,  106 => 29,  103 => 28,  99 => 26,  90 => 25,  86 => 23,  84 => 22,  78 => 19,  74 => 17,  71 => 16,  63 => 11,  58 => 8,  55 => 7,  49 => 5,  43 => 4,  35 => 3,  31 => 1,  29 => 2,  11 => 1,);
159
    }
160
161
    public function getSourceContext()
162
    {
163
        return new Twig_Source("{% extends \"layout/layout.twig\" %}
164
{% from \"macros.twig\" import breadcrumbs, render_classes, class_link, namespace_link %}
165
{% block title %}{{ namespace|raw }} | {{ parent() }}{% endblock %}
166
{% block body_class 'namespace' %}
167
{% block page_id 'namespace:' ~ (namespace|replace({'\\\\': '_'})) %}
168
169
{% block below_menu %}
170
    <div class=\"namespace-breadcrumbs\">
171
        <ol class=\"breadcrumb\">
172
            <li><span class=\"label label-default\">Namespace</span></li>
173
            {{ breadcrumbs(namespace) }}
174
        </ol>
175
    </div>
176
{% endblock %}
177
178
{% block page_content %}
179
180
    <div class=\"page-header\">
181
        <h1>{{ namespace|raw }}</h1>
182
    </div>
183
184
    {% if subnamespaces %}
185
        <h2>Namespaces</h2>
186
        <div class=\"namespace-list\">
187
            {% for ns in subnamespaces %}{{ namespace_link(ns) }}{% endfor %}
188
        </div>
189
    {% endif %}
190
191
    {% if classes %}
192
        <h2>Classes</h2>
193
        {{ render_classes(classes) }}
194
    {% endif %}
195
196
    {% if interfaces %}
197
        <h2>Interfaces</h2>
198
        {{ render_classes(interfaces) }}
199
    {% endif %}
200
201
    {% if exceptions %}
202
        <h2>Exceptions</h2>
203
        {{ render_classes(exceptions) }}
204
    {% endif %}
205
206
{% endblock %}
207
", "namespace.twig", "phar:///Users/bobby/Dropbox/Sites/OpenSource/Slackify/sami.phar/Sami/Resources/themes/default/namespace.twig");
208
    }
209
}
210