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_20bba254f5e2d1957ac85951a7e76ac1976eea949cce130b8fcfd9472c36fcd5   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 248
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 3
dl 0
loc 248
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A doGetParent() 0 4 1
A doDisplay() 0 7 1
A block_title() 0 5 1
A block_body_class() 0 4 1
B block_page_content() 0 37 1
A block_js_search() 0 57 1
A getTemplateName() 0 4 1
A isTraitable() 0 4 1
A getDebugInfo() 0 4 1
B getSourceContext() 0 92 1
1
<?php
2
3
/* search.twig */
4
class __TwigTemplate_20bba254f5e2d1957ac85951a7e76ac1976eea949cce130b8fcfd9472c36fcd5 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", "search.twig", 1);
12
        $this->blocks = array(
13
            'title' => array($this, 'block_title'),
14
            'body_class' => array($this, 'block_body_class'),
15
            'page_content' => array($this, 'block_page_content'),
16
            'js_search' => array($this, 'block_js_search'),
17
        );
18
    }
19
20
    protected function doGetParent(array $context)
21
    {
22
        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...
23
    }
24
25
    protected function doDisplay(array $context, array $blocks = array())
26
    {
27
        // line 2
28
        $context["__internal_247206b2fb6c306c9cc662623e904e86fc4aa269da835e7e4875c7b0babdbb68"] = $this->loadTemplate("macros.twig", "search.twig", 2);
29
        // line 1
30
        $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...
31
    }
32
33
    // line 3
34
    public function block_title($context, array $blocks = array())
35
    {
36
        echo "Search | ";
37
        $this->displayParentBlock("title", $context, $blocks);
38
    }
39
40
    // line 4
41
    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...
42
    {
43
        echo "search-page";
44
    }
45
46
    // line 6
47
    public function block_page_content($context, array $blocks = array())
48
    {
49
        // line 7
50
        echo "
51
    <div class=\"page-header\">
52
        <h1>Search</h1>
53
    </div>
54
55
    <p>This page allows you to search through the API documentation for
56
    specific terms. Enter your search words into the box below and click
57
    \"submit\". The search will be performed on namespaces, classes, interfaces,
58
    traits, functions, and methods.</p>
59
60
    <form class=\"form-inline\" role=\"form\" action=\"";
61
        // line 17
62
        echo twig_escape_filter($this->env, $this->env->getExtension('Sami\Renderer\TwigExtension')->pathForStaticFile($context, "search.html"), "html", null, true);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Twig_ExtensionInterface as the method pathForStaticFile() does only exist in the following implementations of said interface: Sami\Renderer\TwigExtension.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
63
        echo "\" method=\"GET\">
64
        <div class=\"form-group\">
65
            <label class=\"sr-only\" for=\"search\">Search</label>
66
            <input type=\"search\" class=\"form-control\" name=\"search\" id=\"search\" placeholder=\"Search\">
67
        </div>
68
        <button type=\"submit\" class=\"btn btn-default\">submit</button>
69
    </form>
70
71
    <h2>Search Results</h2>
72
73
    <div class=\"container-fluid\">
74
        <ul class=\"search-results\"></ul>
75
    </div>
76
77
    ";
78
        // line 31
79
        $this->displayBlock("js_search", $context, $blocks);
80
        echo "
81
82
";
83
    }
84
85
    // line 35
86
    public function block_js_search($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...
87
    {
88
        // line 36
89
        echo "    <script type=\"text/javascript\">
90
91
        (function() {
92
            var term = Sami.cleanSearchTerm();
93
94
            if (!term) {
95
                \$('h2').hide();
96
                return;
97
            }
98
99
            \$('#search').val(term);
100
            var container = \$('.search-results');
101
            var results = Sami.search(term);
102
            var len = results.length;
103
104
            if (len == 0) {
105
                container.html('No results were found');
106
                return;
107
            }
108
109
            for (var i = 0, text_content = ''; i < len; i++) {
110
111
                var ele = results[i];
112
                var contents = '<li><h2 class=\"clearfix\">';
113
                var class_name = Sami.getSearchClass(ele.type);
114
                contents += '<a href=\"' + ele.link + '\">' + ele.name + '</a>';
115
                contents += '<div class=\"search-type type-' + ele.type + '\"><span class=\"pull-right label ' + class_name + '\">' + ele.type + '</span></div>';
116
                contents += '</h2>';
117
118
                if (ele.fromName && ele.fromLink) {
119
                    contents += '<div class=\"search-from\">from <a href=\"' + ele.fromLink + '\">' + ele.fromName + '</a></div>';
120
                }
121
122
                contents += '<div class=\"search-description\">';
123
124
                // Add description, decode entities, and strip wrapping quotes
125
                if (ele.doc) {
126
                    text_content = \$('<p>' + ele.doc + '</p>').text();
127
                    if (text_content[0] == '\"') {
128
                        text_content = text_content.substring(1);
129
                    }
130
                    if (text_content[text_content.length - 1] == '\"') {
131
                        text_content = text_content.substring(0, text_content.length - 1);
132
                    }
133
                    contents += text_content;
134
                }
135
136
                contents += '</div></li>';
137
                container.append(\$(contents));
138
            }
139
        })();
140
    </script>
141
";
142
    }
143
144
    public function getTemplateName()
145
    {
146
        return "search.twig";
147
    }
148
149
    public function isTraitable()
150
    {
151
        return false;
152
    }
153
154
    public function getDebugInfo()
155
    {
156
        return array (  89 => 36,  86 => 35,  79 => 31,  62 => 17,  50 => 7,  47 => 6,  41 => 4,  34 => 3,  30 => 1,  28 => 2,  11 => 1,);
157
    }
158
159
    public function getSourceContext()
160
    {
161
        return new Twig_Source("{% extends \"layout/layout.twig\" %}
162
{% from \"macros.twig\" import class_link, namespace_link, method_link, property_link %}
163
{% block title %}Search | {{ parent() }}{% endblock %}
164
{% block body_class 'search-page' %}
165
166
{% block page_content %}
167
168
    <div class=\"page-header\">
169
        <h1>Search</h1>
170
    </div>
171
172
    <p>This page allows you to search through the API documentation for
173
    specific terms. Enter your search words into the box below and click
174
    \"submit\". The search will be performed on namespaces, classes, interfaces,
175
    traits, functions, and methods.</p>
176
177
    <form class=\"form-inline\" role=\"form\" action=\"{{ path('search.html') }}\" method=\"GET\">
178
        <div class=\"form-group\">
179
            <label class=\"sr-only\" for=\"search\">Search</label>
180
            <input type=\"search\" class=\"form-control\" name=\"search\" id=\"search\" placeholder=\"Search\">
181
        </div>
182
        <button type=\"submit\" class=\"btn btn-default\">submit</button>
183
    </form>
184
185
    <h2>Search Results</h2>
186
187
    <div class=\"container-fluid\">
188
        <ul class=\"search-results\"></ul>
189
    </div>
190
191
    {{ block('js_search') }}
192
193
{% endblock %}
194
195
{% block js_search %}
196
    <script type=\"text/javascript\">
197
198
        (function() {
199
            var term = Sami.cleanSearchTerm();
200
201
            if (!term) {
202
                \$('h2').hide();
203
                return;
204
            }
205
206
            \$('#search').val(term);
207
            var container = \$('.search-results');
208
            var results = Sami.search(term);
209
            var len = results.length;
210
211
            if (len == 0) {
212
                container.html('No results were found');
213
                return;
214
            }
215
216
            for (var i = 0, text_content = ''; i < len; i++) {
217
218
                var ele = results[i];
219
                var contents = '<li><h2 class=\"clearfix\">';
220
                var class_name = Sami.getSearchClass(ele.type);
221
                contents += '<a href=\"' + ele.link + '\">' + ele.name + '</a>';
222
                contents += '<div class=\"search-type type-' + ele.type + '\"><span class=\"pull-right label ' + class_name + '\">' + ele.type + '</span></div>';
223
                contents += '</h2>';
224
225
                if (ele.fromName && ele.fromLink) {
226
                    contents += '<div class=\"search-from\">from <a href=\"' + ele.fromLink + '\">' + ele.fromName + '</a></div>';
227
                }
228
229
                contents += '<div class=\"search-description\">';
230
231
                // Add description, decode entities, and strip wrapping quotes
232
                if (ele.doc) {
233
                    text_content = \$('<p>' + ele.doc + '</p>').text();
234
                    if (text_content[0] == '\"') {
235
                        text_content = text_content.substring(1);
236
                    }
237
                    if (text_content[text_content.length - 1] == '\"') {
238
                        text_content = text_content.substring(0, text_content.length - 1);
239
                    }
240
                    contents += text_content;
241
                }
242
243
                contents += '</div></li>';
244
                container.append(\$(contents));
245
            }
246
        })();
247
    </script>
248
{% endblock %}
249
", "search.twig", "phar:///Users/bobby/Dropbox/Sites/OpenSource/Slackify/sami.phar/Sami/Resources/themes/default/search.twig");
250
    }
251
}
252