Completed
Pull Request — master (#14)
by Tomáš
03:35
created

ProxySourceTaxonomyIndexGenerator::generate()   C

Complexity

Conditions 11
Paths 97

Size

Total Lines 59
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 0
cts 43
cp 0
rs 6.3545
c 0
b 0
f 0
cc 11
eloc 33
nc 97
nop 1
crap 132

How to fix   Long Method    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
3
$permalink = $source->data()->get('permalink') ?: $source->relativePathname();
4
$basename = basename($permalink);
5
6
$permalink = dirname($permalink);
7
8
$indexType = null;
9
10
if (preg_match('/^(.+?)\.(.+)$/', $basename, $matches)) {
11
    $urlTaxon = $this->permalinkStrategyCollection->process($taxon);
12
    $indexType = $matches[2];
13
    $suffix = in_array($indexType, ['xml', 'rss', 'json']) ? '.'.$indexType : '/';
14
    $permalink = $permalink.'/'.$urlTaxon.$suffix;
15
} else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
16
    // not sure what case this is?
17
}
18
19
if (0 === strpos($permalink, './')) {
20
    $permalink = substr($permalink, 2);
21
}
22
23
if (0 !== strpos($permalink, '/')) {
24
    $permalink = '/'.$permalink;
25
}
26
27
if ($permalink) {
28
    // not sure if this is ever going to happen?
29
    $generatedSource->data()->set('permalink', $permalink);
30
}
31
32
33