MetadataTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_loads_from_entity_descriptor() 0 6 1
A test_loads_from_entities_descriptor() 0 6 1
1
<?php
2
3
namespace LightSaml\Tests\Functional\Model\Metadata;
4
5
use LightSaml\Model\Metadata\EntitiesDescriptor;
6
use LightSaml\Model\Metadata\EntityDescriptor;
7
use LightSaml\Model\Metadata\Metadata;
8
use LightSaml\Tests\BaseTestCase;
9
10
class MetadataTest extends BaseTestCase
11
{
12
    public function test_loads_from_entity_descriptor()
13
    {
14
        $ed = Metadata::fromFile(__DIR__.'/../../../../../../resources/sample/EntityDescriptor/idp2-ed.xml');
15
        $this->assertInstanceOf(EntityDescriptor::class, $ed);
16
        $this->assertEquals('https://B1.bead.loc/adfs/services/trust', $ed->getEntityID());
0 ignored issues
show
Bug introduced by
The method getEntityID does only exist in LightSaml\Model\Metadata\EntityDescriptor, but not in LightSaml\Model\Metadata\EntitiesDescriptor.

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...
17
    }
18
19
    public function test_loads_from_entities_descriptor()
20
    {
21
        $eds = Metadata::fromFile(__DIR__.'/../../../../../../resources/sample/EntitiesDescriptor/testshib-providers.xml');
22
        $this->assertInstanceOf(EntitiesDescriptor::class, $eds);
23
        $this->assertCount(2, $eds->getAllEntityDescriptors());
0 ignored issues
show
Bug introduced by
The method getAllEntityDescriptors does only exist in LightSaml\Model\Metadata\EntitiesDescriptor, but not in LightSaml\Model\Metadata\EntityDescriptor.

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...
24
    }
25
}
26