PretendLinkChecker::checkLink()   B
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 18
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 16
c 1
b 0
f 0
nc 10
nop 1
dl 0
loc 18
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace SilverStripe\ExternalLinks\Tests\Stubs;
3
4
use SilverStripe\Dev\TestOnly;
5
use SilverStripe\ExternalLinks\Tasks\LinkChecker;
6
7
class PretendLinkChecker implements LinkChecker, TestOnly
8
{
9
    public function checkLink($href)
10
    {
11
        switch ($href) {
12
            case 'http://www.working.com':
13
                return 200;
14
            case 'http://www.broken.com':
15
                return 403;
16
            case 'http://www.nodomain.com':
17
                return 0;
18
            case '/internal/link':
19
            case '[sitetree_link,id=9999]':
20
            case 'home':
21
            case 'broken-internal':
22
            case '[sitetree_link,id=1]':
23
                return null;
24
            case 'http://www.broken.com/url/thing':
25
            default:
26
                return 404;
27
        }
28
    }
29
}
30