Service   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 72
ccs 31
cts 31
cp 1
rs 10
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethods() 0 3 1
A getContextualPart() 0 3 1
A __construct() 0 4 1
A addMethod() 0 6 1
A getReservedMethodsInstance() 0 3 1
A setMethods() 0 5 1
A getMethod() 0 3 1
A getExtends() 0 5 2
A setMethodsFromSerializedJson() 0 4 2
A getDocSubPackages() 0 4 1
A toJsonSerialize() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\Model;
6
7
use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod;
8
use WsdlToPhp\PackageGenerator\Container\Model\Method as MethodContainer;
9
use WsdlToPhp\PackageGenerator\Generator\Generator;
10
use WsdlToPhp\PackageGenerator\Generator\Utils;
11
12
/**
13
 * Class Service stands for an available service containing the methods/operations described in the WSDL.
14
 */
15
class Service extends AbstractModel
16
{
17
    public const DEFAULT_SERVICE_CLASS_NAME = 'Service';
18
19
    protected MethodContainer $methods;
20
21 372
    public function __construct(Generator $generator, string $name)
22
    {
23 372
        parent::__construct($generator, $name);
24 372
        $this->setMethods(new MethodContainer($generator));
25
    }
26
27 368
    public function getContextualPart(): string
28
    {
29 368
        return $this->getGenerator()->getOptionServicesFolder();
30
    }
31
32 46
    public function getDocSubPackages(): array
33
    {
34 46
        return [
35 46
            'Services',
36 46
        ];
37
    }
38
39 78
    public function getMethods(): MethodContainer
40
    {
41 78
        return $this->methods;
42
    }
43
44 148
    public function addMethod(string $methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true): Method
45
    {
46 148
        $method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique);
47 148
        $this->methods->add($method);
48
49 148
        return $method;
50
    }
51
52 180
    public function getMethod(string $methodName): ?Method
53
    {
54 180
        return $this->methods->getMethodByName($methodName);
55
    }
56
57 46
    public function getExtends(bool $short = false): string
58
    {
59 46
        $extends = $this->getGenerator()->getOptionSoapClientClass();
60
61 46
        return $short ? Utils::removeNamespace($extends) : $extends;
62
    }
63
64 2
    public function getReservedMethodsInstance(?string $filename = null): ServiceReservedMethod
65
    {
66 2
        return ServiceReservedMethod::instance($filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return WsdlToPhp\Package...od::instance($filename) returns the type WsdlToPhp\PackageGenerat...ader\AbstractYamlReader which includes types incompatible with the type-hinted return WsdlToPhp\PackageGenerat...r\ServiceReservedMethod.
Loading history...
67
    }
68
69 214
    public function setMethodsFromSerializedJson(array $methods): void
70
    {
71 214
        foreach ($methods as $method) {
72 214
            $this->methods->add(self::instanceFromSerializedJson($this->generator, $method)->setOwner($this));
73
        }
74
    }
75
76 372
    protected function setMethods(MethodContainer $methodContainer): self
77
    {
78 372
        $this->methods = $methodContainer;
79
80 372
        return $this;
81
    }
82
83 2
    protected function toJsonSerialize(): array
84
    {
85 2
        return [
86 2
            'methods' => $this->methods,
87 2
        ];
88
    }
89
}
90