Completed
Push — master ( 468379...ad9d92 )
by Petr
23:49 queued 21:04
created

Component   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 80
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getGrid() 0 4 1
A getLabel() 0 4 1
A getType() 0 4 1
A translate() 0 4 1
A getForm() 0 8 2
A addComponentToGrid() 0 13 2
1
<?php
2
3
/**
4
 * This file is part of the Grido (http://grido.bugyik.cz)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido\Components;
13
14
/**
15
 * Base of grid components.
16
 *
17
 * @package     Grido
18
 * @subpackage  Components
19
 * @author      Petr Bugyík
20
 *
21
 * @property-read string $label
22
 * @property-read string $type
23
 * @property-read \Grido\Grid $grid
24
 * @property-read \Nette\Application\UI\Form $form
25
 */
26
abstract class Component extends \Nette\Application\UI\PresenterComponent
27 1
{
28
    /** @var string */
29
    protected $label;
30
31
    /** @var string */
32
    protected $type;
33
34
    /** @var \Grido\Grid */
35
    protected $grid;
36
37
    /** @var \Nette\Application\UI\Form */
38
    protected $form;
39
40
    /**
41
     * @return \Grido\Grid
42
     */
43
    public function getGrid()
44
    {
45 1
        return $this->grid;
46
    }
47
48
    /**
49
     * @return \Nette\Application\UI\Form
50
     */
51
    public function getForm()
52
    {
53 1
        if ($this->form === NULL) {
54 1
            $this->form = $this->grid->getComponent('form');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->grid->getComponent('form') can also be of type object<Nette\ComponentModel\IComponent>. However, the property $form is declared as type object<Nette\Application\UI\Form>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
55 1
        }
56
57 1
        return $this->form;
58
    }
59
60
    /**
61
     * @return string
62
     * @internal
63
     */
64
    public function getLabel()
65
    {
66 1
        return $this->label;
67
    }
68
69
    /**
70
     * @return string
71
     * @internal
72
     */
73
    public function getType()
74
    {
75 1
        return $this->type;
76
    }
77
78
    /**
79
     * @param \Grido\Grid $grid
80
     * @param string $name
81
     * @return \Nette\ComponentModel\Container
82
     */
83
    protected function addComponentToGrid($grid, $name)
84
    {
85 1
        $this->grid = $grid;
86
87
        //check container exist
88 1
        $container = $this->grid->getComponent($this::ID, FALSE);
89 1
        if (!$container) {
90 1
            $this->grid->addComponent(new \Nette\ComponentModel\Container, $this::ID);
91 1
            $container = $this->grid->getComponent($this::ID);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $container is correct as $this->grid->getComponent($this::ID) (which targets Nette\ComponentModel\Container::getComponent()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
92 1
        }
93
94 1
        return $container->addComponent($this, $name);
95
    }
96
97
    /**
98
     * @param  string $message
99
     * @return string
100
     */
101
    protected function translate($message)
102
    {
103 1
        return call_user_func_array([$this->grid->getTranslator(), "translate"], func_get_args());
104
    }
105
}
106