Completed
Push — master ( cb46a0...974133 )
by Marc
04:34
created

XmlRendererTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 1
c 4
b 0
f 2
lcom 0
cbo 1
dl 0
loc 47
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testIntegrity() 0 44 1
1
<?php
2
3
namespace Kaloa\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use Kaloa\Renderer\Config;
7
use Kaloa\Renderer\Factory;
8
9
class XmlRendererTest extends PHPUnit_Framework_TestCase
10
{
11
    public function testIntegrity()
12
    {
13
        // Environment
14
        $contentToRender = file_get_contents(__DIR__ . '/examples/xml/mvc.xml');
15
        $resourceBasePath = __DIR__ . '/examples/xml/mvc';
16
17
        #$contentToRender = file_get_contents('./examples/xml/kaloa_renderer.xml');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
        #$resourceBasePath = './examples/xml/kaloa_renderer';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
20
        $config = new Config($resourceBasePath);
21
22
        $renderer = Factory::createRenderer('xml', $config);
23
24
        /* Simulate run of preSave hook */
25
        $contentToRender = $renderer->firePreSaveEvent($contentToRender);
0 ignored issues
show
Bug introduced by
The method firePreSaveEvent does only exist in Kaloa\Renderer\XmlRenderer, but not in Kaloa\Renderer\CommonMar...derer\XmlLegacyRenderer.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
26
27
        $renderer->render($contentToRender);
28
29
        $ctr = '<k:toc/>
30
            <h2>Test</h2>
31
            <h3>Foo</h3>
32
            <img src="test.png" />
33
            <img src="http://test.png" />
34
            <a href="foo">link</a>
35
            <a href="https://example.org">link</a>
36
            <listing>1+1=2</listing>
37
            <h4>Bar</h4>
38
            <youtube id="dQw4w9WgXcQ" />
39
            <p>Test.<footnote>bla</footnote></p>
40
            <h2>Quz</h2>
41
            <p>Qux.<footnote><strong>Test</strong></footnote></p>
42
            <p>Qix.<footnote name="x">Qix</footnote></p>
43
            <p>Qaz.<footnote name="x">Qaz</footnote></p>
44
            <p>Quz.<footnote name="x">Quz</footnote></p>
45
            <p>Quz.<footnote name="fn:5">Quz</footnote></p>
46
            <p>Quz.<footnote name="fn:6">Quz</footnote></p>
47
            <p>Quz.<footnote name="fn:7">Quz</footnote></p>
48
            <h3>Foo</h3>
49
            <h4>Bar</h4>';
50
51
        $ctr = $renderer->firePreSaveEvent($ctr);
52
53
        $renderer->render($ctr);
54
    }
55
}
56