Test Failed
Pull Request — master (#125)
by Litera
08:49
created

BaseForm   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
D setupRendering() 0 36 10
1
<?php
2
3
namespace App\Components\Forms;
4
5
use App\Components\BaseControl;
6
use Nette\Application\UI\Form;
7
use Nette\Forms\Controls;
8
9
abstract class BaseForm extends BaseControl
10
{
11
12
	const TEMPLATE_DIR = __DIR__ . '/../../templates/components/Forms';
13
14
	/**
15
	 * @param  Form   $form
16
	 * @return Form
17
	 */
18
	protected function setupRendering(Form $form): Form
19
	{
20
		// setup form rendering
21
		$renderer = $form->getRenderer();
22
		$renderer->wrappers['controls']['container'] = NULL;
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
23
		$renderer->wrappers['pair']['.error'] = 'has-error';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
24
		$renderer->wrappers['control']['description'] = 'span class=help-block';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
25
		$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
26
27
		// make form and controls compatible with Twitter Bootstrap
28
		$form->getElementPrototype()->class('form-horizontal');
29
		foreach ($form->getControls() as $control) {
30
			if ($control instanceof Controls\Button) {
31
				$control->getControlPrototype()
32
					->addClass(empty($usedPrimary) ? 'btn btn-default' : '');
33
				$usedPrimary = TRUE;
34
			} elseif (
35
				$control instanceof Controls\TextBase ||
36
				$control instanceof Controls\SelectBox ||
37
				$control instanceof Controls\MultiSelectBox
38
			) {
39
				$control->getControlPrototype()
40
					->addClass('form-control');
41
			} elseif (
42
				$control instanceof Controls\Checkbox ||
43
				$control instanceof Controls\CheckboxList ||
44
				$control instanceof Controls\RadioList
45
			) {
46
				$control->getSeparatorPrototype()
47
					->setName('div')
48
					->addClass($control->getControlPrototype()->type);
49
			}
50
		}
51
52
		return $form;
53
	}
54
55
}
56