Completed
Push — 2.2 ( 8a877d )
by Damian
09:45 queued 06:58
created

BlogTagTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 121
Duplicated Lines 57.02 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 8
lcom 1
cbo 5
dl 69
loc 121
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 5 1
A testBlogPosts() 16 16 2
A testCanView() 0 16 1
A testCanEdit() 21 21 1
A testCanCreate() 11 11 1
A testCanDelete() 21 21 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
/**
4
 * @mixin PHPUnit_Framework_TestCase
5
 */
6
class BlogTagTest extends FunctionalTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
	/**
8
	 * @var string
9
	 */
10
	static $fixture_file = 'blog.yml';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fixture_file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	/**
13
	 * {@inheritdoc}
14
	 */
15
	public function setUp() {
16
		parent::setUp();
17
18
		SS_Datetime::set_mock_now('2013-10-10 20:00:00');
19
	}
20
21
	/**
22
	 * {@inheritdoc}
23
	 */
24
	public function tearDown() {
25
		SS_Datetime::clear_mock_now();
26
27
		parent::tearDown();
28
	}
29
30
	/**
31
	 * Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
32
	 * normal 'save & publish' functionality and by publish date.
33
	 */
34 View Code Duplication
	public function testBlogPosts() {
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...
35
		$member = Member::currentUser();
36
37
		if($member) {
38
			$member->logout();
39
		}
40
41
		$this->objFromFixture('BlogPost', 'FirstBlogPost');
42
43
		/**
44
		 * @var BlogTag $tag
45
		 */
46
		$tag = $this->objFromFixture('BlogTag', 'FirstTag');
47
48
		$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
	}
50
51
	/**
52
	 * The first blog can be viewed by anybody.
53
	 */
54
	public function testCanView() {
55
		$this->useDraftSite();
56
57
		$admin = $this->objFromFixture('Member', 'Admin');
58
		$editor = $this->objFromFixture('Member', 'Editor');
59
60
		$tag = $this->objFromFixture('BlogTag', 'FirstTag');
61
62
		$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 57 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
		$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 58 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
65
		$tag = $this->objFromFixture('BlogTag', 'SecondTag');
66
67
		$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 57 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
		$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 58 can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
	}
70
71 View Code Duplication
	public function testCanEdit() {
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...
72
		$this->useDraftSite();
73
74
		$admin = $this->objFromFixture('Member', 'Admin');
75
		$editor = $this->objFromFixture('Member', 'Editor');
76
77
		$tag = $this->objFromFixture('BlogTag', 'FirstTag');
78
79
		$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 74 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
		$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 75 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
82
		$tag = $this->objFromFixture('BlogTag', 'SecondTag');
83
84
		$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 74 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
		$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 75 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
87
		$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
88
89
		$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 74 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
		$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 75 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
	}
92
93 View Code Duplication
	public function testCanCreate() {
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...
94
		$this->useDraftSite();
95
96
		$admin = $this->objFromFixture('Member', 'Admin');
97
		$editor = $this->objFromFixture('Member', 'Editor');
98
99
		$tag = singleton('BlogTag');
100
101
		$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
		$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
	}
104
105 View Code Duplication
	public function testCanDelete() {
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...
106
		$this->useDraftSite();
107
108
		$admin = $this->objFromFixture('Member', 'Admin');
109
		$editor = $this->objFromFixture('Member', 'Editor');
110
111
		$tag = $this->objFromFixture('BlogTag', 'FirstTag');
112
113
		$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
		$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
115
116
		$tag = $this->objFromFixture('BlogTag', 'SecondTag');
117
118
		$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
		$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertFalse() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
120
121
		$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
122
123
		$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
		$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
The method assertTrue() does not seem to exist on object<BlogTagTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
	}
126
}
127