CommandPresenter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
dl 0
loc 34
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderDefault() 0 9 2
A createComponentForm() 0 12 1
A formSuccess() 0 4 1
1
<?php
2
3
namespace UniMan\Presenters;
4
5
use Nette\Application\ForbiddenRequestException;
6
use Nette\Application\UI\Form;
7
use Nette\Utils\ArrayHash;
8
use Tomaj\Form\Renderer\BootstrapVerticalRenderer;
9
10
class CommandPresenter extends BasePresenter
11
{
12
    private $commands;
13
14
    private $results = [];
15
16
    public function renderDefault($driver, $database = null, $commands = null)
0 ignored issues
show
Unused Code introduced by
The parameter $driver 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...
17
    {
18
        if (!$this->driver->permissions()->canExecuteCommands()) {
19
            throw new ForbiddenRequestException('Executing commands is not available');
20
        }
21
        $this->database = $database;
22
        $this->commands = $commands;
23
        $this->template->results = $this->results;
24
    }
25
26
    protected function createComponentForm()
27
    {
28
        $form = new Form();
29
        $form->setMethod('get');
30
        $form->setRenderer(new BootstrapVerticalRenderer());
31
        $form->addTextArea('commands', 'Commands', null, 10)
32
            ->setDefaultValue($this->commands)
33
            ->setRequired('%label is required');
0 ignored issues
show
Documentation introduced by
'%label is required' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
        $form->addSubmit('submit', 'Execute');
35
        $form->onSuccess[] = [$this, 'formSuccess'];
36
        return $form;
37
    }
38
39
    public function formSuccess(Form $form, ArrayHash $values)
40
    {
41
        $this->results = $this->driver->dataManager()->execute($values['commands']);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->driver->dataManag...te($values['commands']) can be null. However, the property $results is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
42
    }
43
}
44