Completed
Push — master ( 37b207...7906ee )
by Helmut
37:09
created

NameTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 34.52 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 29
loc 84
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_be_rendered() 7 7 1
A it_renders_default_values() 7 7 1
A it_renders_model_values() 0 8 1
A it_can_fill_model_values() 0 12 1
A it_escapes_values() 7 7 1
A it_provides_expected_values() 8 8 1
A it_provides_expected_default_values() 0 8 1
A it_validates_required() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
class NameTest extends FormTestCase {
6
7
	/** @test */
8 View Code Duplication
	public function it_can_be_rendered()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
	{
10
		$form = $this->form();
11
		$form->name('foo');
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
12
		$this->assertContains('<input name="foo_first" value=""', $form->render());
13
		$this->assertContains('<input name="foo_surname" value=""', $form->render());
14
	}
15
16
	/** @test */
17 View Code Duplication
	public function it_renders_default_values()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
	{
19
		$form = $this->form();
20
		$form->name('foo')->default(['first'=>'bar', 'surname'=>'baz']);
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
21
		$this->assertContains('<input name="foo_first" value="bar"', $form->render());
22
		$this->assertContains('<input name="foo_surname" value="baz"', $form->render());
23
	}
24
25
	/** @test */
26
	public function it_renders_model_values()
27
	{
28
		$form = $this->form();
29
		$form->defaults($this->model(['foo'=>'bar baz', 'foo_first'=>'bar', 'foo_surname'=>'baz']));
30
		$form->name('foo');
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
31
		$this->assertContains('<input name="foo_first" value="bar"', $form->render());
32
		$this->assertContains('<input name="foo_surname" value="baz"', $form->render());
33
	}
34
35
	/** @test */
36
	public function it_can_fill_model_values()
37
	{
38
		$model = $this->model(['foo'=>'', 'foo_first'=>'', 'foo_surname'=>'']);
39
40
		$form = $this->form();
41
		$form->name('foo')->default(['first'=>'bar', 'surname'=>'baz']);
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
		$form->fill($model);
43
44
		$form->assertEquals($model->foo, 'bar baz');
0 ignored issues
show
Documentation Bug introduced by
The method assertEquals does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
45
		$form->assertEquals($model->foo_first, 'bar');
0 ignored issues
show
Documentation Bug introduced by
The method assertEquals does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
46
		$form->assertEquals($model->foo_surname, 'baz');
0 ignored issues
show
Documentation Bug introduced by
The method assertEquals does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47
	}		
48
49
	/** @test */
50 View Code Duplication
	public function it_escapes_values()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		$form = $this->form();
53
		$form->name('foo')->default(['first'=>'bar&', 'surname'=>'baz&']);
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
		$this->assertContains('<input name="foo_first" value="bar&amp;"', $form->render());
55
		$this->assertContains('<input name="foo_surname" value="baz&amp;"', $form->render());
56
	}		
57
58
	/** @test */
59 View Code Duplication
	public function it_provides_expected_values()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
	{
61
		$form = $this->form();
62
		$form->name('foo');
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
63
64
		$expected = ['foo_first'=>'', 'foo_surname'=>'', 'foo'=>''];
65
		$this->assertSame($form->get('foo'), $expected);
66
	}
67
68
	/** @test */
69
	public function it_provides_expected_default_values()
70
	{
71
		$form = $this->form();
72
		$form->name('foo')->default(['first'=>'bar', 'surname'=>'baz']);
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
73
74
		$expected = ['foo_first'=>'bar', 'foo_surname'=>'baz', 'foo'=>'bar baz'];
75
		$this->assertSame($form->get('foo'), $expected);
76
	}	
77
78
	/** @test */
79
    public function it_validates_required()
80
    {
81
    	$this->assertValid(function($form) { $form->name('foo'); });
82
    	$this->assertValid(function($form) { $form->name('foo')->default(['first'=>'bar', 'surname'=>'baz'])->required(); });
83
84
    	$this->assertNotValid(function($form) { $form->name('foo')->required(); });
85
    	$this->assertNotValid(function($form) { $form->name('foo')->default(['first'=>'bar'])->required(); });
86
	}
87
88
}
89