Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Service
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
9
100.00% covered (success)
100.00%
1 / 1
 addService
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 getServiceByName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMethods
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 objectClass
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\Container\Model;
6
7use WsdlToPhp\PackageGenerator\Model\Method as MethodModel;
8use WsdlToPhp\PackageGenerator\Model\Service as Model;
9
10final class Service extends AbstractModel
11{
12    public function addService(string $serviceName, string $methodName, $methodParameter, $methodReturn): Service
13    {
14        if (!$this->get($serviceName) instanceof Model) {
15            $this->add(new Model($this->generator, $serviceName));
16        }
17        $serviceMethod = $this->get($serviceName)->getMethod($methodName);
18
19        // Service method does not already exist, register it
20        if (!$serviceMethod instanceof MethodModel) {
21            $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn);
22        }
23        // Service method exists with a different signature, register it too by identifying the service functions as non unique functions
24        elseif ($methodParameter !== $serviceMethod->getParameterType()) {
25            $serviceMethod->setUnique(false);
26            $this->get($serviceName)->addMethod($methodName, $methodParameter, $methodReturn, false);
27        }
28
29        return $this;
30    }
31
32    public function getServiceByName(string $name): ?Model
33    {
34        return $this->get($name);
35    }
36
37    public function getMethods(): Method
38    {
39        $methods = new Method($this->generator);
40
41        /** @var Model $service */
42        foreach ($this->objects as $service) {
43            foreach ($service->getMethods() as $method) {
44                $methods->add($method);
45            }
46        }
47
48        return $methods;
49    }
50
51    protected function objectClass(): string
52    {
53        return Model::class;
54    }
55}