Test Failed
Pull Request — master (#124)
by Christopher
05:14
created

addNavigationPropertyToEntityType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 74
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 74
rs 9.0335
cc 2
eloc 62
nc 2
nop 16

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace AlgoWeb\ODataMetadata;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType\EndAnonymousType;
7
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType;
8
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType;
9
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationEndType;
10
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationType;
11
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypePropertyType;
12
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType;
13
use AlgoWeb\ODataMetadata\MetadataV3\edm\TConstraintType;
14
use AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType;
15
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType;
16
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType;
17
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionImportReturnTypeType;
18
use AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType;
19
use AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType;
20
use AlgoWeb\ODataMetadata\MetadataV3\edm\TReferentialConstraintRoleElementType;
21
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTextType;
22
use AlgoWeb\ODataMetadata\MetadataV3\edmx\Edmx;
23
use Illuminate\Support\Str;
24
use JMS\Serializer\SerializerBuilder;
25
26
class MetadataManager
27
{
28
    private $V3Edmx = null;
0 ignored issues
show
Coding Style introduced by
$V3Edmx does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
29
    private $lastError = null;
30
    private $serializer = null;
31
32
    public function __construct($namespaceName = 'Data', $containerName = 'DefaultContainer', Edmx $edmx = null)
33
    {
34
        $msg = null;
35
        $this->V3Edmx = (null == $edmx) ? new Edmx($namespaceName, $containerName) : $edmx;
36
        assert($this->V3Edmx->isOK($msg), $msg);
37
        $this->initSerialiser();
38
        assert(null != $this->serializer, 'Serializer must not be null at end of constructor');
39
    }
40
41
    public function getEdmx()
42
    {
43
        $msg = null;
44
        assert($this->V3Edmx->isOK($msg), $msg);
45
        return $this->V3Edmx;
46
    }
47
48
    public function getEdmxXML()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        $cereal = $this->getSerialiser();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $cereal is correct as $this->getSerialiser() (which targets AlgoWeb\ODataMetadata\Me...anager::getSerialiser()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
        assert(null != $cereal, 'Serializer must not be null when trying to get edmx xml');
52
        return $cereal->serialize($this->getEdmx(), 'xml');
0 ignored issues
show
Bug introduced by
The method serialize cannot be called on $cereal (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
53
    }
54
55
    public function addEntityType($name,
56
                                  TEntityTypeType $baseType = null,
57
                                  $isAbstract = false,
58
                                  $accessType = 'Public',
59
                                  $summary = null,
60
                                  $longDescription = null)
61
    {
62
        $NewEntity = new TEntityTypeType();
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
63
        $NewEntity->setName($name);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
64
        $this->addDocumentation($summary, $longDescription, $NewEntity);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
65
        $NewEntity->setAbstract($isAbstract);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
66
        $NewEntity->setBaseType(null === $baseType ? $baseType->getName():null);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method getName cannot be called on $baseType (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
67
        if ($isAbstract) {
68
            return [$NewEntity, null];
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
69
        }
70
        $entitySet = new EntitySetAnonymousType();
71
        $entitySet->setName(Str::plural($NewEntity->getName()));
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
72
        $namespace = $this->getNamespace();
73
        $entityTypeName = $namespace . $NewEntity->getName();
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
74
        $entitySet->setEntityType($entityTypeName);
75
        $entitySet->setGetterAccess($accessType);
76
77
        $this->V3Edmx->getDataServiceType()->getSchema()[0]->addToEntityType($NewEntity);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Compatibility introduced by
$NewEntity of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...V3\edm\TEntityTypeType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
78
        $this->V3Edmx->getDataServiceType()->getSchema()[0]->getEntityContainer()[0]->addToEntitySet($entitySet);
79
        assert($this->V3Edmx->isOK($this->lastError), $this->lastError);
80
        return [$NewEntity, $entitySet];
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
81
    }
82
83
    public function addComplexType($name, $accessType = 'Public', $summary = null, $longDescription = null)
84
    {
85
        $NewEntity = new TComplexTypeType();
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
86
        $NewEntity->setName($name);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
87
        $NewEntity->setTypeAccess($accessType);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
88
        $this->addDocumentation($summary, $longDescription, $NewEntity);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
89
        assert($NewEntity->isOK($this->lastError), $this->lastError);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
90
        $this->V3Edmx->getDataServiceType()->getSchema()[0]->addToComplexType($NewEntity);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Compatibility introduced by
$NewEntity of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...3\edm\TComplexTypeType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
91
92
        return $NewEntity;
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
93
    }
94
95
    public function getSerialiser()
96
    {
97
        return $this->serializer;
98
    }
99
100
    public function addPropertyToComplexType(
101
        \AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType $complexType,
102
        $name,
103
        $type,
104
        $defaultValue = null,
105
        $nullable = false,
106
        $summary = null,
107
        $longDescription = null
108
    ) {
109
        if (is_array($defaultValue) || is_object($defaultValue)) {
110
            throw new \InvalidArgumentException('Default value cannot be object or array');
111
        }
112
        if (null != $defaultValue) {
113
            $defaultValue = var_export($defaultValue, true);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $defaultValue. This often makes code more readable.
Loading history...
114
        }
115
        $NewProperty = new TComplexTypePropertyType();
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
116
        $NewProperty->setName($name);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
117
        $NewProperty->setType($type);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
118
        $NewProperty->setNullable($nullable);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
119
        $this->addDocumentation($summary, $longDescription, $NewProperty);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
120
        if (null != $defaultValue) {
121
            $NewProperty->setDefaultValue($defaultValue);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
122
        }
123
        assert($NewProperty->isOK($this->lastError), $this->lastError);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
124
        $complexType->addToProperty($NewProperty);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Compatibility introduced by
$NewProperty of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...omplexTypePropertyType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
125
        return $NewProperty;
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
126
    }
127
128
    public function addPropertyToEntityType(
129
        TEntityTypeType $entityType,
130
        $name,
131
        $type,
132
        $defaultValue = null,
133
        $nullable = false,
134
        $isKey = false,
135
        $storeGeneratedPattern = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $storeGeneratedPattern exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
136
        $summary = null,
137
        $longDescription = null
138
    ) {
139
        $NewProperty = new TEntityPropertyType();
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
140
        $NewProperty->setName($name);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
141
        $NewProperty->setType($type);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
142
        $NewProperty->setStoreGeneratedPattern($storeGeneratedPattern);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
143
        $NewProperty->setNullable($nullable);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
144
        $this->addDocumentation($summary, $longDescription, $NewProperty);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
145
        if (null != $defaultValue) {
146
            $NewProperty->setDefaultValue($defaultValue);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
147
        }
148
        $entityType->addToProperty($NewProperty);
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Compatibility introduced by
$NewProperty of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...dm\TEntityPropertyType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
149
        if ($isKey) {
150
            $Key = new TPropertyRefType();
0 ignored issues
show
Coding Style introduced by
$Key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
151
            $Key->setName($name);
0 ignored issues
show
Coding Style introduced by
$Key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
152
            $entityType->addToKey($Key);
0 ignored issues
show
Coding Style introduced by
$Key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
153
        }
154
        return $NewProperty;
0 ignored issues
show
Coding Style introduced by
$NewProperty does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
155
    }
156
157
    public function addNavigationPropertyToEntityType(
158
        TEntityTypeType $principalType,
159
        $principalMultiplicity,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalMultiplicity exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
160
        $principalProperty,
161
        TEntityTypeType $dependentType,
162
        $dependentMultiplicity,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentMultiplicity exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
163
        $dependentProperty = '',
164
        array $principalConstraintProperty = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalConstraintProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
165
        array $dependentConstraintProperty = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentConstraintProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
166
        $principalGetterAccess = 'Public',
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalGetterAccess exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
167
        $principalSetterAccess = 'Public',
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalSetterAccess exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
168
        $dependentGetterAccess = 'Public',
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentGetterAccess exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
169
        $dependentSetterAccess = 'Public',
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentSetterAccess exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
170
        $principalSummery = null,
171
        $principalLongDescription = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalLongDescription exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
172
        $dependentSummery = null,
173
        $dependentLongDescription = null
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentLongDescription exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
174
    ) {
175
        $principalEntitySetName = Str::plural($principalType->getName());
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalEntitySetName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
176
        $dependentEntitySetName = Str::plural($dependentType->getName());
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentEntitySetName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
177
        $relationName = $principalType->getName() . '_' . $principalProperty . '_'
178
                        . $dependentType->getName() . '_' . $dependentProperty;
179
        $relationName = trim($relationName, '_');
180
181
        $namespace = $this->getNamespace();
182
        $relationFQName = $namespace . $relationName;
183
184
        $principalNavigationProperty = new TNavigationPropertyType();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalNavigationProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
185
        $principalNavigationProperty->setName($principalProperty);
186
        $principalNavigationProperty->setToRole(trim($dependentEntitySetName . '_' . $dependentProperty, '_'));
187
        $principalNavigationProperty->setFromRole($principalEntitySetName . '_' . $principalProperty);
188
        $principalNavigationProperty->setRelationship($relationFQName);
189
        $principalNavigationProperty->setGetterAccess($principalGetterAccess);
190
        $principalNavigationProperty->setSetterAccess($principalSetterAccess);
191
        $this->addDocumentation($principalSummery, $principalLongDescription, $principalNavigationProperty);
192
        $principalType->addToNavigationProperty($principalNavigationProperty);
0 ignored issues
show
Compatibility introduced by
$principalNavigationProperty of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...NavigationPropertyType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
193
        $dependentNavigationProperty = null;
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentNavigationProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
194
        if (!empty($dependentProperty)) {
195
            $dependentNavigationProperty = new TNavigationPropertyType();
196
            $dependentNavigationProperty->setName($dependentProperty);
197
            $dependentNavigationProperty->setToRole($principalEntitySetName . '_' . $principalProperty);
198
            $dependentNavigationProperty->setFromRole($dependentEntitySetName . '_' . $dependentProperty);
199
            $dependentNavigationProperty->setRelationship($relationFQName);
200
            $dependentNavigationProperty->setGetterAccess($dependentGetterAccess);
201
            $dependentNavigationProperty->setSetterAccess($dependentSetterAccess);
202
            $this->addDocumentation($dependentSummery, $dependentLongDescription, $dependentNavigationProperty);
203
            $dependentType->addToNavigationProperty($dependentNavigationProperty);
0 ignored issues
show
Compatibility introduced by
$dependentNavigationProperty of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...NavigationPropertyType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
204
        }
205
206
        $assocation = $this->createAssocationFromNavigationProperty(
207
            $principalType,
208
            $dependentType,
209
            $principalNavigationProperty,
0 ignored issues
show
Compatibility introduced by
$principalNavigationProperty of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...NavigationPropertyType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
210
            $dependentNavigationProperty,
0 ignored issues
show
Bug introduced by
It seems like $dependentNavigationProperty can also be of type object<AlgoWeb\ODataMetadata\IsOK>; however, AlgoWeb\ODataMetadata\Me...romNavigationProperty() does only seem to accept null|object<AlgoWeb\ODat...NavigationPropertyType>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
211
            $principalMultiplicity,
212
            $dependentMultiplicity,
213
            $principalConstraintProperty,
214
            $dependentConstraintProperty
215
        );
216
217
        $this->V3Edmx->getDataServiceType()->getSchema()[0]->addToAssociation($assocation);
218
219
        $associationSet = $this->createAssocationSetForAssocation(
220
            $assocation,
221
            $principalEntitySetName,
222
            $dependentEntitySetName
223
        );
224
225
        $this->V3Edmx->getDataServiceType()->getSchema()[0]
226
            ->getEntityContainer()[0]->addToAssociationSet($associationSet);
227
228
        assert($this->V3Edmx->isOK($this->lastError), $this->lastError);
229
        return [$principalNavigationProperty, $dependentNavigationProperty];
230
    }
231
232
    protected function createAssocationFromNavigationProperty(
233
        TEntityTypeType $principalType,
234
        TEntityTypeType $dependentType,
235
        TNavigationPropertyType $principalNavigationProperty,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalNavigationProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
236
        TNavigationPropertyType $dependentNavigationProperty = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentNavigationProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
237
        $principalMultiplicity,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalMultiplicity exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
238
        $dependentMultiplicity,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentMultiplicity exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
239
        array $principalConstraintProperty = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalConstraintProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
240
        array $dependentConstraintProperty = null
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentConstraintProperty exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
241
    ) {
242
        $multCombo = ['*' => ['*', '1'], '0..1' => ['1'], '1' => ['*', '0..1']];
243
        $multKeys = array_keys($multCombo);
244
        if (null != $dependentNavigationProperty) {
245
            if ($dependentNavigationProperty->getRelationship() != $principalNavigationProperty->getRelationship()) {
246
                $msg = 'If you have both a dependent property and a principal property,'
247
                        .' relationship should match';
248
                throw new \InvalidArgumentException($msg);
249
            }
250
            if ($dependentNavigationProperty->getFromRole() != $principalNavigationProperty->getToRole()
251
                || $dependentNavigationProperty->getToRole() != $principalNavigationProperty->getFromRole()
252
            ) {
253
                throw new \InvalidArgumentException(
254
                    'Principal to role should match dependent from role, and vice versa'
255
                );
256
            }
257
        }
258
        if (!in_array($principalMultiplicity, $multKeys) || !in_array($dependentMultiplicity, $multKeys)) {
259
            throw new \InvalidArgumentException('Malformed multiplicity - valid values are *, 0..1 and 1');
260
        }
261
        if (!in_array($dependentMultiplicity, $multCombo[$principalMultiplicity])) {
262
            throw new \InvalidArgumentException(
263
                'Invalid multiplicity combination - ' . $principalMultiplicity . ' ' . $dependentMultiplicity
264
            );
265
        }
266
267
        $namespace = $this->getNamespace();
268
        $principalTypeFQName = $namespace . $principalType->getName();
269
        $dependentTypeFQName = $namespace . $dependentType->getName();
270
        $association = new TAssociationType();
271
        $relationship = $principalNavigationProperty->getRelationship();
272
        if (false !== strpos($relationship, '.')) {
273
            $relationship = substr($relationship, strpos($relationship, '.') + 1);
274
        }
275
276
        $principalTargRole = $principalNavigationProperty->getFromRole();
277
        $principalSrcRole = $principalNavigationProperty->getToRole();
278
        $dependentTargRole = null != $dependentNavigationProperty ? $dependentNavigationProperty->getFromRole() : null;
279
280
        $association->setName($relationship);
281
        $principalEnd = new TAssociationEndType();
282
        $principalEnd->setType($principalTypeFQName);
283
        $principalEnd->setRole($principalTargRole);
284
        $principalEnd->setMultiplicity($principalMultiplicity);
285
        $association->addToEnd($principalEnd);
286
        $dependentEnd = new TAssociationEndType();
287
        $dependentEnd->setType($dependentTypeFQName);
288
        $dependentEnd->setMultiplicity($dependentMultiplicity);
289
        $association->addToEnd($dependentEnd);
290
291
        $dependentEnd->setRole(null != $dependentNavigationProperty ? $dependentTargRole : $principalSrcRole);
292
293
        $hasPrincipalReferral = null != $principalConstraintProperty && 0 < count($principalConstraintProperty);
294
        $hasDependentReferral = null != $dependentConstraintProperty && 0 < count($dependentConstraintProperty);
295
296
        if ($hasPrincipalReferral && $hasDependentReferral) {
297
            $principalReferralConstraint = $this->makeReferentialConstraint(
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalReferralConstraint exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
298
                $principalConstraintProperty, $principalTargRole
299
            );
300
            $dependentReferralConstraint = $this->makeReferentialConstraint(
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentReferralConstraint exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
301
                $dependentConstraintProperty, $dependentTargRole
302
            );
303
            $constraint = new TConstraintType();
304
            $constraint->setPrincipal($principalReferralConstraint);
305
            $constraint->setDependent($dependentReferralConstraint);
306
            $association->setReferentialConstraint($constraint);
307
        }
308
        return $association;
309
    }
310
311
    /**
312
     * @param string $principalEntitySetName
313
     * @param string $dependentEntitySetName
314
     */
315
    protected function createAssocationSetForAssocation(
316
        TAssociationType $association,
317
        $principalEntitySetName,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $principalEntitySetName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
318
        $dependentEntitySetName
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $dependentEntitySetName exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
319
    ) {
320
        $as = new AssociationSetAnonymousType();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $as. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
321
        $name = $association->getName();
322
        $as->setName($name);
323
        $namespace = $this->getNamespace();
324
        $associationSetName = $namespace . $association->getName();
325
        $as->setAssociation($associationSetName);
326
        $end1 = new EndAnonymousType();
327
        $end1->setRole($association->getEnd()[0]->getRole());
328
        $end1->setEntitySet($principalEntitySetName);
329
        $end2 = new EndAnonymousType();
330
        $end2->setRole($association->getEnd()[1]->getRole());
331
        $end2->setEntitySet($dependentEntitySetName);
332
        assert($end1->getRole() != $end2->getRole());
333
        $as->addToEnd($end1);
334
        $as->addToEnd($end2);
335
        return $as;
336
    }
337
338
    public function getLastError()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
339
    {
340
        return $this->lastError;
341
    }
342
343
    /**
344
     * @param  string                      $name
345
     * @param  IsOK                        $expectedReturnType
346
     * @param  TTextType                   $shortDesc
0 ignored issues
show
Documentation introduced by
Should the type for parameter $shortDesc not be null|TTextType?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
347
     * @param  TTextType                   $longDesc
0 ignored issues
show
Documentation introduced by
Should the type for parameter $longDesc not be null|TTextType?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
348
     * @return FunctionImportAnonymousType
349
     */
350
    public function createSingleton(
351
        $name,
352
        IsOK $expectedReturnType,
353
        TTextType $shortDesc = null,
354
        TTextType $longDesc = null
355
    ) {
356
        if (!($expectedReturnType instanceof TEntityTypeType) && !($expectedReturnType instanceof TComplexTypeType)) {
357
            $msg = 'Expected return type must be either TEntityType or TComplexType';
358
            throw new \InvalidArgumentException($msg);
359
        }
360
361
        if (!is_string($name) || empty($name)) {
362
            $msg = 'Name must be a non-empty string';
363
            throw new \InvalidArgumentException($msg);
364
        }
365
366
        $funcType = new FunctionImportAnonymousType();
367
        $funcType->setName($name);
368
369
        $typeName = $expectedReturnType->getName();
370
        $returnType = new TFunctionImportReturnTypeType();
371
        $returnType->setType($typeName);
372
        $returnType->setEntitySetAttribute($typeName);
373
        assert($returnType->isOK($msg), $msg);
374
        $funcType->addToReturnType($returnType);
375
        $this->addDocumentation($shortDesc, $longDesc, $funcType);
376
377
        $this->getEdmx()->getDataServiceType()->getSchema()[0]->getEntityContainer()[0]->addToFunctionImport($funcType);
0 ignored issues
show
Compatibility introduced by
$funcType of type object<AlgoWeb\ODataMetadata\IsOK> is not a sub-type of object<AlgoWeb\ODataMeta...ionImportAnonymousType>. It seems like you assume a child class of the class AlgoWeb\ODataMetadata\IsOK to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
378
379
        return $funcType;
380
    }
381
382
    private function initSerialiser()
383
    {
384
        $ymlDir = __DIR__ . DIRECTORY_SEPARATOR . 'MetadataV3' . DIRECTORY_SEPARATOR . 'JMSmetadata';
385
        $this->serializer =
386
            SerializerBuilder::create()
387
            ->addMetadataDir($ymlDir)
388
            ->build();
389
    }
390
391
    public function __sleep()
392
    {
393
        $this->serializer = null;
394
        $result = array_keys(get_object_vars($this));
395
        return $result;
396
    }
397
398
    public function __wakeup()
399
    {
400
        $this->initSerialiser();
401
    }
402
403
    /**
404
     * @param $summary
405
     * @param $longDescription
406
     * @return TDocumentationType
407
     */
408
    private function generateDocumentation(TTextType $summary, TTextType $longDescription)
409
    {
410
        $documentation = new TDocumentationType();
411
        $documentation->setSummary($summary);
412
        $documentation->setLongDescription($longDescription);
413
        return $documentation;
414
    }
415
416
    /**
417
     * @return string
418
     */
419
    private function getNamespace()
420
    {
421
        $namespace = $this->V3Edmx->getDataServiceType()->getSchema()[0]->getNamespace();
422
        if (0 == strlen(trim($namespace))) {
423
            $namespace = '';
424
        } else {
425
            $namespace .= '.';
426
        }
427
        return $namespace;
428
    }
429
430
    /**
431
     * @param  array                                 $constraintProperty
432
     * @param  string                                $targRole
433
     * @return TReferentialConstraintRoleElementType
434
     */
435
    protected function makeReferentialConstraint(array $constraintProperty, $targRole)
436
    {
437
        assert(!empty($constraintProperty));
438
        assert(is_string($targRole));
439
        $referralConstraint = new TReferentialConstraintRoleElementType();
440
        $referralConstraint->setRole($targRole);
441
        foreach ($constraintProperty as $propertyRef) {
442
            $TpropertyRef = new TPropertyRefType();
0 ignored issues
show
Coding Style introduced by
$TpropertyRef does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
443
            $TpropertyRef->setName($propertyRef);
0 ignored issues
show
Coding Style introduced by
$TpropertyRef does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
444
            $referralConstraint->addToPropertyRef($TpropertyRef);
0 ignored issues
show
Coding Style introduced by
$TpropertyRef does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
445
        }
446
        return $referralConstraint;
447
    }
448
449
    /**
450
     * @param $summary
451
     * @param $longDescription
452
     * @param $NewEntity
453
     */
454
    private function addDocumentation($summary, $longDescription, IsOK & $NewEntity)
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style Naming introduced by
The parameter $NewEntity is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
455
    {
456
        if (null != $summary && null != $longDescription) {
457
            $documentation = $this->generateDocumentation($summary, $longDescription);
458
            if (method_exists($NewEntity, 'addToDocumentation')) {
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
459
                $NewEntity->addToDocumentation($documentation);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class AlgoWeb\ODataMetadata\IsOK as the method addToDocumentation() does only exist in the following sub-classes of AlgoWeb\ODataMetadata\IsOK: AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...ComplexTypePropertyType, AlgoWeb\ODataMetadata\Me...edm\TEntityPropertyType. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
460
            } else {
461
                $NewEntity->setDocumentation($documentation);
0 ignored issues
show
Coding Style introduced by
$NewEntity does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
It seems like you code against a specific sub-type and not the parent class AlgoWeb\ODataMetadata\IsOK as the method setDocumentation() does only exist in the following sub-classes of AlgoWeb\ODataMetadata\IsOK: AlgoWeb\ODataMetadata\Me...aV1\edm\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...tionImportAnonymousType, AlgoWeb\ODataMetadata\Me...edm\TAssociationEndType, AlgoWeb\ODataMetadata\Me...V1\edm\TAssociationType, AlgoWeb\ODataMetadata\Me...ComplexTypePropertyType, AlgoWeb\ODataMetadata\Me...V1\edm\TComplexTypeType, AlgoWeb\ODataMetadata\Me...aV1\edm\TConstraintType, AlgoWeb\ODataMetadata\Me...edm\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...aV1\edm\TEntityTypeType, AlgoWeb\ODataMetadata\Me...tionImportParameterType, AlgoWeb\ODataMetadata\Me...TNavigationPropertyType, AlgoWeb\ODataMetadata\MetadataV1\edm\TOnActionType, AlgoWeb\ODataMetadata\MetadataV1\edm\TUsingType, AlgoWeb\ODataMetadata\Me...dm\ssdl\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...sdl\TAssociationEndType, AlgoWeb\ODataMetadata\Me...m\ssdl\TAssociationType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TConstraintType, AlgoWeb\ODataMetadata\Me...sdl\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TEntityTypeType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TFunctionType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TOnActionType, AlgoWeb\ODataMetadata\Me...edm\ssdl\TParameterType, AlgoWeb\ODataMetadata\Me...m\ssdl\TPropertyRefType, AlgoWeb\ODataMetadata\Me...nstraintRoleElementType, AlgoWeb\ODataMetadata\Me...aV2\edm\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...tionImportAnonymousType, AlgoWeb\ODataMetadata\Me...edm\TAssociationEndType, AlgoWeb\ODataMetadata\Me...V2\edm\TAssociationType, AlgoWeb\ODataMetadata\Me...ComplexTypePropertyType, AlgoWeb\ODataMetadata\Me...V2\edm\TComplexTypeType, AlgoWeb\ODataMetadata\Me...aV2\edm\TConstraintType, AlgoWeb\ODataMetadata\Me...edm\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...aV2\edm\TEntityTypeType, AlgoWeb\ODataMetadata\Me...tionImportParameterType, AlgoWeb\ODataMetadata\MetadataV2\edm\TFunctionType, AlgoWeb\ODataMetadata\Me...TNavigationPropertyType, AlgoWeb\ODataMetadata\MetadataV2\edm\TOnActionType, AlgoWeb\ODataMetadata\Me...\edm\TReferenceTypeType, AlgoWeb\ODataMetadata\MetadataV2\edm\TTypeRefType, AlgoWeb\ODataMetadata\MetadataV2\edm\TUsingType, AlgoWeb\ODataMetadata\Me...dm\ssdl\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...sdl\TAssociationEndType, AlgoWeb\ODataMetadata\Me...m\ssdl\TAssociationType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TConstraintType, AlgoWeb\ODataMetadata\Me...sdl\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TEntityTypeType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TFunctionType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TOnActionType, AlgoWeb\ODataMetadata\Me...edm\ssdl\TParameterType, AlgoWeb\ODataMetadata\Me...m\ssdl\TPropertyRefType, AlgoWeb\ODataMetadata\Me...nstraintRoleElementType, AlgoWeb\ODataMetadata\Me...aV3\edm\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...tionImportAnonymousType, AlgoWeb\ODataMetadata\Me...edm\TAssociationEndType, AlgoWeb\ODataMetadata\Me...V3\edm\TAssociationType, AlgoWeb\ODataMetadata\Me...ComplexTypePropertyType, AlgoWeb\ODataMetadata\Me...V3\edm\TComplexTypeType, AlgoWeb\ODataMetadata\Me...aV3\edm\TConstraintType, AlgoWeb\ODataMetadata\Me...edm\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...aV3\edm\TEntityTypeType, AlgoWeb\ODataMetadata\Me...edm\TEnumTypeMemberType, AlgoWeb\ODataMetadata\MetadataV3\edm\TEnumTypeType, AlgoWeb\ODataMetadata\Me...tionImportParameterType, AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionType, AlgoWeb\ODataMetadata\Me...TNavigationPropertyType, AlgoWeb\ODataMetadata\MetadataV3\edm\TOnActionType, AlgoWeb\ODataMetadata\Me...\edm\TReferenceTypeType, AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeRefType, AlgoWeb\ODataMetadata\MetadataV3\edm\TUsingType, AlgoWeb\ODataMetadata\Me...taV3\edm\TValueTermType, AlgoWeb\ODataMetadata\Me...dm\ssdl\EntityContainer, AlgoWeb\ODataMetadata\Me...ciationSetAnonymousType, AlgoWeb\ODataMetadata\Me...usType\EndAnonymousType, AlgoWeb\ODataMetadata\Me...\EntitySetAnonymousType, AlgoWeb\ODataMetadata\Me...sdl\TAssociationEndType, AlgoWeb\ODataMetadata\Me...m\ssdl\TAssociationType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TConstraintType, AlgoWeb\ODataMetadata\Me...sdl\TEntityPropertyType, AlgoWeb\ODataMetadata\Me...dm\ssdl\TEntityTypeType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TFunctionType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TOnActionType, AlgoWeb\ODataMetadata\Me...edm\ssdl\TParameterType, AlgoWeb\ODataMetadata\Me...m\ssdl\TPropertyRefType, AlgoWeb\ODataMetadata\Me...\edm\ssdl\TPropertyType, AlgoWeb\ODataMetadata\Me...nstraintRoleElementType. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
462
            }
463
        }
464
    }
465
}
466