Completed
Push — develop ( 0869de...14a867 )
by Mikaël
31:40
created

Service::getReservedMethodsInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Model;
4
5
use WsdlToPhp\PackageGenerator\Generator\Utils;
6
use WsdlToPhp\PackageGenerator\Container\Model\Method as MethodContainer;
7
use WsdlToPhp\PackageGenerator\Generator\Generator;
8
use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod;
9
10
/**
11
 * Class Service stands for an available service containing the methods/operations described in the WSDL
12
 */
13
class Service extends AbstractModel
14
{
15
    /**
16
     * @var string
17
     */
18
    const DEFAULT_SERVICE_CLASS_NAME = 'Service';
19
    /**
20
     * Store the methods of the service
21
     * @var MethodContainer
22
     */
23
    private $methods;
24
    /**
25
     * Main constructor
26
     * @see AbstractModel::__construct()
27
     * @uses Service::setMethods()
28
     * @param Generator $generator
29
     * @param string $name the service name
30
     */
31 508
    public function __construct(Generator $generator, $name)
32
    {
33 508
        parent::__construct($generator, $name);
34 508
        $this->setMethods(new MethodContainer($generator));
35 508
    }
36
    /**
37
     * Returns the contextual part of the class name for the package
38
     * @see AbstractModel::getContextualPart()
39
     * @return string
40
     */
41 500
    public function getContextualPart()
42
    {
43 500
        return $this->getGenerator()->getOptionServicesFolder();
44
    }
45
    /**
46
     * Returns the sub package name which the model belongs to
47
     * Must be overridden by sub classes
48
     * @see AbstractModel::getDocSubPackages()
49
     * @return array
50
     */
51 84
    public function getDocSubPackages()
52
    {
53
        return array(
54 84
            'Services',
55 63
        );
56
    }
57
    /**
58
     * Returns the methods of the service
59
     * @return MethodContainer
60
     */
61 132
    public function getMethods()
62
    {
63 132
        return $this->methods;
64
    }
65
    /**
66
     * Sets the methods container
67
     * @param MethodContainer $methodContainer
68
     * @return Service
69
     */
70 508
    private function setMethods(MethodContainer $methodContainer)
71
    {
72 508
        $this->methods = $methodContainer;
73 508
        return $this;
74
    }
75
    /**
76
     * Adds a method to the service
77
     * @uses Method::setIsUnique()
78
     * @param string $methodName original method name
79
     * @param string|array $methodParameterType original parameter type/name
80
     * @param string|array $methodReturnType original return type/name
81
     * @param bool $methodIsUnique original isUnique value
82
     * @return Method
83
     */
84 496
    public function addMethod($methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true)
85
    {
86 496
        $method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique);
87 496
        $this->methods->add($method);
88 496
        return $method;
89
    }
90
    /**
91
     * Returns the method by its original name
92
     * @uses Service::getMethods()
93
     * @uses AbstractModel::getName()
94
     * @param string $methodName the original method name
95
     * @return Method|null
96
     */
97 500
    public function getMethod($methodName)
98
    {
99 500
        return $this->methods->getMethodByName($methodName);
100
    }
101
    /**
102
     * Allows to define from which class the curent model extends
103
     * @param bool $short
104
     * @return string
105
     */
106 84
    public function getExtends($short = false)
107
    {
108 84
        $extends = $this->getGenerator()->getOptionSoapClientClass();
109 84
        return $short ? Utils::removeNamespace($extends) : $extends;
110
    }
111
    /**
112
     * @param $filename
113
     * @return ServiceReservedMethod
114
     */
115 4
    public function getReservedMethodsInstance($filename = null)
116
    {
117 4
        return ServiceReservedMethod::instance($filename);
118
    }
119
}
120