SitemapDefintionTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 30.91 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 17
loc 55
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testItIsInstantiable() 0 9 1
A testSetting() 0 9 1
A testSettingWithDefault() 0 6 1
A testTtl() 9 9 1
A testTtlWithoutCache() 8 8 1
A testTtlDefault() 0 6 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
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\SitemapBundle\Tests\Definition;
11
12
use Core23\SitemapBundle\Definition\SitemapDefinition;
13
use PHPUnit\Framework\TestCase;
14
15
final class SitemapDefintionTest extends TestCase
16
{
17
    public function testItIsInstantiable(): void
18
    {
19
        $definition = new SitemapDefinition('acme.sitemap');
20
21
        static::assertSame('acme.sitemap', $definition->getType());
22
        static::assertSame('acme.sitemap', $definition->toString());
23
        static::assertSame('acme.sitemap', $definition->__toString());
24
        static::assertSame([], $definition->getSettings());
25
    }
26
27
    public function testSetting(): void
28
    {
29
        $definition = new SitemapDefinition('acme.sitemap');
30
        $definition->setSettings([
31
            'foo'=> 'bar',
32
        ]);
33
34
        static::assertSame('bar', $definition->getSetting('foo'));
35
    }
36
37
    public function testSettingWithDefault(): void
38
    {
39
        $definition = new SitemapDefinition('acme.sitemap');
40
41
        static::assertSame('baz', $definition->getSetting('foo', 'baz'));
42
    }
43
44 View Code Duplication
    public function testTtl(): void
0 ignored issues
show
Duplication introduced by core23
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...
45
    {
46
        $definition = new SitemapDefinition('acme.sitemap', [
47
            'use_cache' => true,
48
            'ttl'       => 90,
49
        ]);
50
51
        static::assertSame(90, $definition->getTtl());
52
    }
53
54 View Code Duplication
    public function testTtlWithoutCache(): void
0 ignored issues
show
Duplication introduced by core23
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...
55
    {
56
        $definition = new SitemapDefinition('acme.sitemap', [
57
            'use_cache' => false,
58
        ]);
59
60
        static::assertSame(0, $definition->getTtl());
61
    }
62
63
    public function testTtlDefault(): void
64
    {
65
        $definition = new SitemapDefinition('acme.sitemap');
66
67
        static::assertSame(0, $definition->getTtl());
68
    }
69
}
70