JFormRuleOptionsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 46.77 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 3 1
A testOptions() 29 29 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
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
4
 * @license    GNU General Public License version 2 or later; see LICENSE
5
 */
6
7
namespace Joomla\Form\Tests;
8
9
use Joomla\Test\TestHelper;
10
use Joomla\Form\Rule\Options as RuleOptions;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17
class JFormRuleOptionsTest extends \PHPUnit_Framework_TestCase
18
{
19
	/**
20
	 * Set up for testing
21
	 *
22
	 * @return  void
23
	 *
24
	 * @since   1.0
25
	 */
26
	public function setUp()
27
	{
28
		parent::setUp();
29
	}
30
31
	/**
32
	 * Tear down test
33
	 *
34
	 * @return void
35
	 *
36
	 * @since   1.0
37
	 */
38
	protected function tearDown()
39
	{
40
	}
41
42
	/**
43
	 * Test the Joomla\Form\Rule\Options::test method.
44
	 *
45
	 * @return  void
46
	 *
47
	 * @since   1.0
48
	 */
49 View Code Duplication
	public function testOptions()
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...
50
	{
51
		$rule = new RuleOptions;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Options has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
52
		$xml = simplexml_load_string(
53
			'<form><field name="field1"><option value="value1">Value1</option><option value="value2">Value2</option></field></form>'
54
		);
55
56
		// Test fail conditions.
57
58
		$this->assertThat(
59
			$rule->test($xml->field[0], 'bogus'),
60
			$this->isFalse(),
61
			'Line:' . __LINE__ . ' The rule should fail and return false.'
62
		);
63
64
		// Test pass conditions.
65
66
		$this->assertThat(
67
			$rule->test($xml->field[0], 'value1'),
68
			$this->isTrue(),
69
			'Line:' . __LINE__ . ' value1 should pass and return true.'
70
		);
71
72
		$this->assertThat(
73
			$rule->test($xml->field[0], 'value2'),
74
			$this->isTrue(),
75
			'Line:' . __LINE__ . ' value2 should pass and return true.'
76
		);
77
	}
78
}
79