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.

CallbackTask   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureVariables() 0 11 1
B execute() 0 14 5
A preview() 0 13 4
1
<?php
2
/**
3
 * See class comment
4
 *
5
 * PHP Version 5
6
 *
7
 * @category   Netresearch
8
 * @package    Netresearch\Kite
9
 * @subpackage Task
10
 * @author     Christian Opitz <[email protected]>
11
 * @license    http://www.netresearch.de Netresearch Copyright
12
 * @link       http://www.netresearch.de
13
 */
14
15
namespace Netresearch\Kite\Task;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Execute a callback
20
 *
21
 * @category   Netresearch
22
 * @package    Netresearch\Kite
23
 * @subpackage Task
24
 * @author     Christian Opitz <[email protected]>
25
 * @license    http://www.netresearch.de Netresearch Copyright
26
 * @link       http://www.netresearch.de
27
 */
28
class CallbackTask extends \Netresearch\Kite\Task
29
{
30
    /**
31
     * Configures the options
32
     *
33
     * @return array
34
     */
35
    protected function configureVariables()
36
    {
37
        return array(
0 ignored issues
show
Best Practice introduced by
The expression return array('callback' ...::configureVariables(); seems to be an array, but some of its elements' types (string) are incompatible with the return type of the parent method Netresearch\Kite\Task::configureVariables of type array<string,array>.

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 new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return '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...
38
            'callback' => array(
39
                'type' => 'callable|string',
40
                'required' => true,
41
                'label' => 'The callback or user function to run (@see GeneralUtility::callUserFunction())'
42
            ),
43
            '--'
44
        ) + parent::configureVariables();
45
    }
46
47
    /**
48
     * Execute the task
49
     *
50
     * @return mixed
51
     */
52
    public function execute()
53
    {
54
        $callback = $this->get('callback');
55
        if (!is_array($callback) && !$callback instanceof \Closure) {
56
            if (strpos($callback, '::')) {
57
                $callback = explode('::', $callback);
58
            } elseif (strpos($callback, '->')) {
59
                $parts = explode('->', $callback);
60
                $instance = new $parts[0];
61
                $callback = array($instance, $parts[1]);
62
            }
63
        }
64
        return call_user_func($callback, $this->getParent());
65
    }
66
67
    /**
68
     * Show an information of what will happen
69
     *
70
     * @return void
71
     */
72
    public function preview()
73
    {
74
        parent::preview();
75
        $fn = $this->get('callback');
76
        if (is_string($fn)) {
77
            $name = $fn;
78
        } elseif (is_array($fn)) {
79
            $name = (is_object($fn[0]) ? get_class($fn[0]) . '->' : $fn[0] . '::') . $fn[1];
80
        } else {
81
            $name = 'anonymous function';
82
        }
83
        $this->console->output('Calling ' . $name, OutputInterface::VERBOSITY_DEBUG);
84
    }
85
}
86
?>
87