Completed
Push — develop ( dcfc04...3d10a6 )
by Neomerx
04:33
created

JsonApiBaseController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 0
cts 11
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php namespace Limoncello\Flute\Http;
2
3
/**
4
 * Copyright 2015-2018 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Data\ModelSchemaInfoInterface;
20
use Limoncello\Contracts\L10n\FormatterFactoryInterface;
21
use Limoncello\Flute\Contracts\Encoder\EncoderInterface;
22
use Limoncello\Flute\Contracts\FactoryInterface;
23
use Limoncello\Flute\Contracts\Http\JsonApiControllerInterface;
24
use Limoncello\Flute\Contracts\Schema\JsonSchemasInterface;
25
use Limoncello\Flute\Http\Traits\DefaultControllerMethodsTrait;
26
use Psr\Container\ContainerExceptionInterface;
27
use Psr\Container\ContainerInterface;
28
use Psr\Container\NotFoundExceptionInterface;
29
use Psr\Http\Message\ResponseInterface;
30
use Psr\Http\Message\ServerRequestInterface;
31
32
/**
33
 * @package Limoncello\Flute
34
 */
35
abstract class JsonApiBaseController implements JsonApiControllerInterface
36
{
37
    use DefaultControllerMethodsTrait;
38
39
    /** API class name */
40
    const API_CLASS = null;
41
42
    /** JSON API Schema class name */
43
    const SCHEMA_CLASS = null;
44
45
    /** JSON API query validation rules class */
46
    const ON_INDEX_QUERY_VALIDATION_RULES_CLASS = null;
47
48
    /** JSON API query validation rules class */
49
    const ON_READ_QUERY_VALIDATION_RULES_CLASS = null;
50
51
    /** JSON API data validation rules class */
52
    const ON_CREATE_DATA_VALIDATION_RULES_CLASS = null;
53
54
    /** JSON API data validation rules class */
55
    const ON_UPDATE_DATA_VALIDATION_RULES_CLASS = null;
56
57
    /**
58
     * @inheritdoc
59
     */
60 View Code Duplication
    public static function index(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
        array $routeParams,
62
        ContainerInterface $container,
63
        ServerRequestInterface $request
64
    ): ResponseInterface {
65
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
66
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
67
        static::assertClassValueDefined(static::ON_INDEX_QUERY_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
68
69
        return static::defaultIndexHandler(
70
            $request->getQueryParams(),
71
            $request->getUri(),
72
            static::defaultCreateQueryParser($container, static::ON_INDEX_QUERY_VALIDATION_RULES_CLASS),
73
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
74
            static::defaultCreateApi($container, static::API_CLASS),
75
            $container->get(EncoderInterface::class)
76
        );
77
    }
78
79
    /**
80
     * @inheritdoc
81
     */
82 View Code Duplication
    public static function create(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
        array $routeParams,
84
        ContainerInterface $container,
85
        ServerRequestInterface $request
86
    ): ResponseInterface {
87
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
88
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
89
        static::assertClassValueDefined(static::ON_CREATE_DATA_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
90
91
        $response = static::defaultCreateHandler(
92
            $request->getUri(),
93
            $request->getBody(),
94
            static::SCHEMA_CLASS,
95
            $container->get(ModelSchemaInfoInterface::class),
96
            static::defaultCreateDataParser($container, static::ON_CREATE_DATA_VALIDATION_RULES_CLASS),
97
            static::defaultCreateApi($container, static::API_CLASS),
98
            $container->get(JsonSchemasInterface::class),
99
            $container->get(EncoderInterface::class),
100
            $container->get(FactoryInterface::class),
101
            $container->get(FormatterFactoryInterface::class)
102
        );
103
104
        return $response;
105
    }
106
107
    /**
108
     * @inheritdoc
109
     */
110 View Code Duplication
    public static function read(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
        array $routeParams,
112
        ContainerInterface $container,
113
        ServerRequestInterface $request
114
    ): ResponseInterface {
115
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
116
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
117
        static::assertClassValueDefined(static::ON_READ_QUERY_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
118
119
        return static::defaultReadHandler(
120
            $routeParams[static::ROUTE_KEY_INDEX],
121
            $request->getQueryParams(),
122
            $request->getUri(),
123
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
124
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
125
            static::defaultCreateApi($container, static::API_CLASS),
126
            $container->get(EncoderInterface::class)
127
        );
128
    }
129
130
    /**
131
     * @inheritdoc
132
     */
133 View Code Duplication
    public static function update(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
        array $routeParams,
135
        ContainerInterface $container,
136
        ServerRequestInterface $request
137
    ): ResponseInterface {
138
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
139
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
140
        static::assertClassValueDefined(static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
141
142
        $response = static::defaultUpdateHandler(
143
            $routeParams[static::ROUTE_KEY_INDEX],
144
            $request->getUri(),
145
            $request->getBody(),
146
            static::SCHEMA_CLASS,
147
            $container->get(ModelSchemaInfoInterface::class),
148
            static::defaultCreateDataParser($container, static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS),
149
            static::defaultCreateApi($container, static::API_CLASS),
150
            $container->get(EncoderInterface::class),
151
            $container->get(FactoryInterface::class),
152
            $container->get(FormatterFactoryInterface::class)
153
        );
154
155
        return $response;
156
    }
157
158
    /**
159
     * @inheritdoc
160
     */
161
    public static function delete(
162
        array $routeParams,
163
        ContainerInterface $container,
164
        ServerRequestInterface $request
165
    ): ResponseInterface {
166
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
167
168
        $response = static::defaultDeleteHandler(
169
            $routeParams[static::ROUTE_KEY_INDEX],
170
            $request->getUri(),
171
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
172
            static::defaultCreateApi($container, static::API_CLASS),
173
            $container->get(EncoderInterface::class)
174
        );
175
176
        return $response;
177
    }
178
179
    /**
180
     * @param string                 $index
181
     * @param string                 $modelRelName
182
     * @param string                 $queryValRulesClass
183
     * @param ContainerInterface     $container
184
     * @param ServerRequestInterface $request
185
     *
186
     * @return ResponseInterface
187
     *
188
     * @throws ContainerExceptionInterface
189
     * @throws NotFoundExceptionInterface
190
     */
191 View Code Duplication
    protected static function readRelationship(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
        string $index,
193
        string $modelRelName,
194
        string $queryValRulesClass,
195
        ContainerInterface $container,
196
        ServerRequestInterface $request
197
    ): ResponseInterface {
198
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
199
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
200
201
        $api     = static::defaultCreateApi($container, static::API_CLASS);
202
        $handler = function () use ($api, $index, $modelRelName) {
203
            return $api->readRelationship($index, $modelRelName);
204
        };
205
206
        return static::defaultReadRelationshipWithClosureHandler(
207
            $index,
208
            $handler,
209
            $request->getQueryParams(),
210
            $request->getUri(),
211
            static::defaultCreateQueryParser($container, $queryValRulesClass),
212
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
213
            $api,
214
            $container->get(EncoderInterface::class)
215
        );
216
    }
217
218
    /**
219
     * @param string                 $index
220
     * @param string                 $modelRelName
221
     * @param string                 $queryValRulesClass
222
     * @param ContainerInterface     $container
223
     * @param ServerRequestInterface $request
224
     *
225
     * @return ResponseInterface
226
     *
227
     * @throws ContainerExceptionInterface
228
     * @throws NotFoundExceptionInterface
229
     */
230 View Code Duplication
    protected static function readRelationshipIdentifiers(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
231
        string $index,
232
        string $modelRelName,
233
        string $queryValRulesClass,
234
        ContainerInterface $container,
235
        ServerRequestInterface $request
236
    ): ResponseInterface {
237
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
238
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
239
240
        $api     = static::defaultCreateApi($container, static::API_CLASS);
241
        $handler = function () use ($api, $index, $modelRelName) {
242
            return $api->readRelationship($index, $modelRelName);
243
        };
244
245
        return static::defaultReadRelationshipIdentifiersWithClosureHandler(
246
            $index,
247
            $handler,
248
            $request->getQueryParams(),
249
            $request->getUri(),
250
            static::defaultCreateQueryParser($container, $queryValRulesClass),
251
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
252
            $api,
253
            $container->get(EncoderInterface::class)
254
        );
255
    }
256
257
    /**
258
     * @param string                 $parentIndex
259
     * @param string                 $jsonRelName
260
     * @param string                 $modelRelName
261
     * @param ContainerInterface     $container
262
     * @param ServerRequestInterface $request
263
     *
264
     * @return ResponseInterface
265
     */
266 View Code Duplication
    protected static function addInRelationship(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
267
        string $parentIndex,
268
        string $jsonRelName,
269
        string $modelRelName,
270
        ContainerInterface $container,
271
        ServerRequestInterface $request
272
    ): ResponseInterface {
273
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
274
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
275
        static::assertClassValueDefined(static::ON_READ_QUERY_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
276
        static::assertClassValueDefined(static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
277
278
        return static::defaultAddInRelationshipHandler(
279
            $parentIndex,
280
            $jsonRelName,
281
            $modelRelName,
282
            $request->getUri(),
283
            $request->getBody(),
284
            static::SCHEMA_CLASS,
285
            $container->get(ModelSchemaInfoInterface::class),
286
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
287
            static::defaultCreateDataParser($container, static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS),
288
            static::defaultCreateApi($container, static::API_CLASS),
289
            $container->get(EncoderInterface::class),
290
            $container->get(FactoryInterface::class),
291
            $container->get(FormatterFactoryInterface::class)
292
        );
293
    }
294
295
    /**
296
     * @param string                 $parentIndex
297
     * @param string                 $jsonRelName
298
     * @param string                 $modelRelName
299
     * @param ContainerInterface     $container
300
     * @param ServerRequestInterface $request
301
     *
302
     * @return ResponseInterface
303
     */
304 View Code Duplication
    protected static function deleteInRelationship(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
        string $parentIndex,
306
        string $jsonRelName,
307
        string $modelRelName,
308
        ContainerInterface $container,
309
        ServerRequestInterface $request
310
    ): ResponseInterface {
311
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
312
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
313
        static::assertClassValueDefined(static::ON_READ_QUERY_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
314
        static::assertClassValueDefined(static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
315
316
        return static::defaultDeleteInRelationshipHandler(
317
            $parentIndex,
318
            $jsonRelName,
319
            $modelRelName,
320
            $request->getUri(),
321
            $request->getBody(),
322
            static::SCHEMA_CLASS,
323
            $container->get(ModelSchemaInfoInterface::class),
324
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
325
            static::defaultCreateDataParser($container, static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS),
326
            static::defaultCreateApi($container, static::API_CLASS),
327
            $container->get(EncoderInterface::class),
328
            $container->get(FactoryInterface::class),
329
            $container->get(FormatterFactoryInterface::class)
330
        );
331
    }
332
333
    /**
334
     * @param string                 $parentIndex
335
     * @param string                 $jsonRelName
336
     * @param string                 $modelRelName
337
     * @param ContainerInterface     $container
338
     * @param ServerRequestInterface $request
339
     *
340
     * @return ResponseInterface
341
     */
342 View Code Duplication
    protected static function replaceInRelationship(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
343
        string $parentIndex,
344
        string $jsonRelName,
345
        string $modelRelName,
346
        ContainerInterface $container,
347
        ServerRequestInterface $request
348
    ): ResponseInterface {
349
        static::assertClassValueDefined(static::API_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
350
        static::assertClassValueDefined(static::SCHEMA_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
351
        static::assertClassValueDefined(static::ON_READ_QUERY_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
352
        static::assertClassValueDefined(static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS);
0 ignored issues
show
Bug introduced by
Since assertClassValueDefined() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of assertClassValueDefined() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
353
354
        return static::defaultReplaceInRelationship(
355
            $parentIndex,
356
            $jsonRelName,
357
            $modelRelName,
358
            $request->getUri(),
359
            $request->getBody(),
360
            static::SCHEMA_CLASS,
361
            $container->get(ModelSchemaInfoInterface::class),
362
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
363
            static::defaultCreateDataParser($container, static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS),
364
            static::defaultCreateApi($container, static::API_CLASS),
365
            $container->get(EncoderInterface::class),
366
            $container->get(FactoryInterface::class),
367
            $container->get(FormatterFactoryInterface::class)
368
        );
369
    }
370
}
371