Passed
Push — ref ( 45b89b )
by Asmir
02:50
created

MetadataUtils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPort() 0 8 4
A getService() 0 8 4
1
<?php
2
3
namespace GoetasWebservices\SoapServices\Metadata;
4
5
use GoetasWebservices\XML\WSDLReader\Exception\PortNotFoundException;
6
use GoetasWebservices\XML\WSDLReader\Exception\ServiceNotFoundException;
7
8
class MetadataUtils {
9
10
    /**
11
     * @param $serviceName
12
     * @param array $services
13
     * @return array
14
     * @throws ServiceNotFoundException
15
     */
16
    public static function getService($serviceName, array $services)
17
    {
18
        if ($serviceName && isset($services[$serviceName])) {
19
            return $services[$serviceName];
20
        } elseif ($serviceName) {
21
            throw new ServiceNotFoundException("The service named $serviceName can not be found");
22
        } else {
23
            return reset($services);
24
        }
25
    }
26
27
    /**
28
     * @param string $portName
29
     * @param array $service
30
     * @return array
31
     * @throws PortNotFoundException
32
     */
33
    public static  function getPort($portName, array $service)
34
    {
35
        if ($portName && isset($service[$portName])) {
36
            return $service[$portName];
37
        } elseif ($portName) {
38
            throw new PortNotFoundException("The port named $portName can not be found");
39
        } else {
40
            return reset($service);
41
        }
42
    }
43
}
44
45