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

getDebugInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/* traits.twig */
4
class __TwigTemplate_e8a02c0b0baa956c7d09d29124a61836be4c1b3079b87ce3cc43d0bdfa61672c 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", "traits.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
        );
17
    }
18
19
    protected function doGetParent(array $context)
20
    {
21
        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...
22
    }
23
24
    protected function doDisplay(array $context, array $blocks = array())
25
    {
26
        // line 2
27
        $context["__internal_85e957d16c16d43a099da5e05533379c49bc8b43f44343be05967d21f1cacea5"] = $this->loadTemplate("macros.twig", "traits.twig", 2);
28
        // line 1
29
        $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...
30
    }
31
32
    // line 3
33
    public function block_title($context, array $blocks = array())
34
    {
35
        echo "Traits | ";
36
        $this->displayParentBlock("title", $context, $blocks);
37
    }
38
39
    // line 4
40
    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...
41
    {
42
        echo "traits";
43
    }
44
45
    // line 6
46
    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...
47
    {
48
        // line 7
49
        echo "    <div class=\"page-header\">
50
        <h1>Traits</h1>
51
    </div>
52
53
    <div class=\"container-fluid underlined\">
54
        ";
55
        // line 12
56
        $context['_parent'] = $context;
57
        $context['_seq'] = twig_ensure_traversable((isset($context["classes"]) || array_key_exists("classes", $context) ? $context["classes"] : (function () { throw new Twig_Error_Runtime('Variable "classes" does not exist.', 12, $this->getSourceContext()); })()));
58
        foreach ($context['_seq'] as $context["_key"] => $context["class"]) {
59
            // line 13
60
            echo "            ";
61
            if (twig_get_attribute($this->env, $this->getSourceContext(), $context["class"], "trait", array())) {
62
                // line 14
63
                echo "                <div class=\"row\">
64
                    <div class=\"col-md-6\">
65
                        ";
66
                // line 16
67
                echo $context["__internal_85e957d16c16d43a099da5e05533379c49bc8b43f44343be05967d21f1cacea5"]->macro_class_link($context["class"], true);
68
                echo "
69
                    </div>
70
                    <div class=\"col-md-6\">
71
                        ";
72
                // line 19
73
                echo $this->env->getExtension('Sami\Renderer\TwigExtension')->parseDesc($context, twig_get_attribute($this->env, $this->getSourceContext(), $context["class"], "shortdesc", array()), $context["class"]);
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 parseDesc() 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...
74
                echo "
75
                    </div>
76
                </div>
77
            ";
78
            }
79
            // line 23
80
            echo "        ";
81
        }
82
        $_parent = $context['_parent'];
83
        unset($context['_seq'], $context['_iterated'], $context['_key'], $context['class'], $context['_parent'], $context['loop']);
84
        $context = array_intersect_key($context, $_parent) + $_parent;
0 ignored issues
show
Unused Code introduced by
$context is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
85
        // line 24
86
        echo "    </div>
87
";
88
    }
89
90
    public function getTemplateName()
91
    {
92
        return "traits.twig";
93
    }
94
95
    public function isTraitable()
96
    {
97
        return false;
98
    }
99
100
    public function getDebugInfo()
101
    {
102
        return array (  86 => 24,  80 => 23,  73 => 19,  67 => 16,  63 => 14,  60 => 13,  56 => 12,  49 => 7,  46 => 6,  40 => 4,  33 => 3,  29 => 1,  27 => 2,  11 => 1,);
103
    }
104
105
    public function getSourceContext()
106
    {
107
        return new Twig_Source("{% extends \"layout/layout.twig\" %}
108
{% from \"macros.twig\" import class_link %}
109
{% block title %}Traits | {{ parent() }}{% endblock %}
110
{% block body_class 'traits' %}
111
112
{% block page_content %}
113
    <div class=\"page-header\">
114
        <h1>Traits</h1>
115
    </div>
116
117
    <div class=\"container-fluid underlined\">
118
        {% for class in classes %}
119
            {% if class.trait %}
120
                <div class=\"row\">
121
                    <div class=\"col-md-6\">
122
                        {{ class_link(class, true) }}
123
                    </div>
124
                    <div class=\"col-md-6\">
125
                        {{ class.shortdesc|desc(class) }}
126
                    </div>
127
                </div>
128
            {% endif %}
129
        {% endfor %}
130
    </div>
131
{% endblock %}
132
", "traits.twig", "phar:///Users/bobby/Dropbox/Sites/OpenSource/Slackify/sami.phar/Sami/Resources/themes/default/traits.twig");
133
    }
134
}
135