Completed
Push — master ( 1a67d2...dfab50 )
by Neomerx
11:35 queued 22s
created

JsonApiBaseController::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 18
loc 18
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 14
nc 1
nop 3
crap 1
1
<?php namespace Limoncello\Flute\Http;
2
3
/**
4
 * Copyright 2015-2017 [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\Contracts\Settings\SettingsProviderInterface;
22
use Limoncello\Flute\Contracts\Encoder\EncoderInterface;
23
use Limoncello\Flute\Contracts\FactoryInterface;
24
use Limoncello\Flute\Contracts\Http\JsonApiControllerInterface;
25
use Limoncello\Flute\Contracts\Schema\JsonSchemasInterface;
26
use Limoncello\Flute\Http\Traits\DefaultControllerMethodsTrait;
27
use Psr\Container\ContainerExceptionInterface;
28
use Psr\Container\ContainerInterface;
29
use Psr\Container\NotFoundExceptionInterface;
30
use Psr\Http\Message\ResponseInterface;
31
use Psr\Http\Message\ServerRequestInterface;
32
33
/**
34
 * @package Limoncello\Flute
35
 */
36
abstract class JsonApiBaseController implements JsonApiControllerInterface
37
{
38
    use DefaultControllerMethodsTrait;
39
40
    /** API class name */
41
    const API_CLASS = null;
42
43
    /** JSON API Schema class name */
44
    const SCHEMA_CLASS = null;
45
46
    /** JSON API query validation rules class */
47
    const ON_INDEX_QUERY_VALIDATION_RULES_CLASS = null;
48
49
    /** JSON API query validation rules class */
50
    const ON_READ_QUERY_VALIDATION_RULES_CLASS = null;
51
52
    /** JSON API data validation rules class */
53
    const ON_CREATE_DATA_VALIDATION_RULES_CLASS = null;
54
55
    /** JSON API data validation rules class */
56
    const ON_UPDATE_DATA_VALIDATION_RULES_CLASS = null;
57
58
    /**
59
     * @inheritdoc
60
     */
61 12 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...
62
        array $routeParams,
63
        ContainerInterface $container,
64
        ServerRequestInterface $request
65
    ): ResponseInterface {
66 12
        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...
67 12
        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...
68 12
        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...
69
70 12
        return static::defaultIndexHandler(
71 12
            $request->getQueryParams(),
72 12
            $request->getUri(),
73 12
            static::defaultCreateQueryParser($container, static::ON_INDEX_QUERY_VALIDATION_RULES_CLASS),
74 12
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
75 12
            static::defaultCreateApi($container, static::API_CLASS),
76 12
            $container->get(SettingsProviderInterface::class),
77 12
            $container->get(JsonSchemasInterface::class),
78 12
            $container->get(EncoderInterface::class)
79
        );
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 1 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...
86
        array $routeParams,
87
        ContainerInterface $container,
88
        ServerRequestInterface $request
89
    ): ResponseInterface {
90 1
        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...
91 1
        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...
92 1
        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...
93
94 1
        $response = static::defaultCreateHandler(
95 1
            $request->getUri(),
96 1
            $request->getBody(),
97 1
            static::SCHEMA_CLASS,
98 1
            $container->get(ModelSchemaInfoInterface::class),
99 1
            static::defaultCreateDataParser($container, static::ON_CREATE_DATA_VALIDATION_RULES_CLASS),
100 1
            static::defaultCreateApi($container, static::API_CLASS),
101 1
            $container->get(SettingsProviderInterface::class),
102 1
            $container->get(JsonSchemasInterface::class),
103 1
            $container->get(EncoderInterface::class),
104 1
            $container->get(FactoryInterface::class),
105 1
            $container->get(FormatterFactoryInterface::class)
106
        );
107
108 1
        return $response;
109
    }
110
111
    /**
112
     * @inheritdoc
113
     */
114 1 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...
115
        array $routeParams,
116
        ContainerInterface $container,
117
        ServerRequestInterface $request
118
    ): ResponseInterface {
119 1
        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...
120 1
        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...
121 1
        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...
122
123 1
        return static::defaultReadHandler(
124 1
            $routeParams[static::ROUTE_KEY_INDEX],
125 1
            $request->getQueryParams(),
126 1
            $request->getUri(),
127 1
            static::defaultCreateQueryParser($container, static::ON_READ_QUERY_VALIDATION_RULES_CLASS),
128 1
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
129 1
            static::defaultCreateApi($container, static::API_CLASS),
130 1
            $container->get(SettingsProviderInterface::class),
131 1
            $container->get(JsonSchemasInterface::class),
132 1
            $container->get(EncoderInterface::class)
133
        );
134
    }
135
136
    /**
137
     * @inheritdoc
138
     */
139 5 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...
140
        array $routeParams,
141
        ContainerInterface $container,
142
        ServerRequestInterface $request
143
    ): ResponseInterface {
144 5
        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...
145 5
        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...
146 5
        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...
147
148 5
        $response = static::defaultUpdateHandler(
149 5
            $routeParams[static::ROUTE_KEY_INDEX],
150 5
            $request->getUri(),
151 5
            $request->getBody(),
152 5
            static::SCHEMA_CLASS,
153 5
            $container->get(ModelSchemaInfoInterface::class),
154 5
            static::defaultCreateDataParser($container, static::ON_UPDATE_DATA_VALIDATION_RULES_CLASS),
155 5
            static::defaultCreateApi($container, static::API_CLASS),
156 5
            $container->get(SettingsProviderInterface::class),
157 5
            $container->get(JsonSchemasInterface::class),
158 5
            $container->get(EncoderInterface::class),
159 5
            $container->get(FactoryInterface::class),
160 5
            $container->get(FormatterFactoryInterface::class)
161
        );
162
163 2
        return $response;
164
    }
165
166
    /**
167
     * @inheritdoc
168
     */
169 1 View Code Duplication
    public static function delete(
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...
170
        array $routeParams,
171
        ContainerInterface $container,
172
        ServerRequestInterface $request
173
    ): ResponseInterface {
174 1
        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...
175
176 1
        $response = static::defaultDeleteHandler(
177 1
            $routeParams[static::ROUTE_KEY_INDEX],
178 1
            $request->getUri(),
179 1
            static::defaultCreateApi($container, static::API_CLASS),
180 1
            $container->get(SettingsProviderInterface::class),
181 1
            $container->get(JsonSchemasInterface::class),
182 1
            $container->get(EncoderInterface::class)
183
        );
184
185 1
        return $response;
186
    }
187
188
    /**
189
     * @param string                 $index
190
     * @param string                 $modelRelName
191
     * @param string                 $queryValRulesClass
192
     * @param ContainerInterface     $container
193
     * @param ServerRequestInterface $request
194
     *
195
     * @return ResponseInterface
196
     *
197
     * @throws ContainerExceptionInterface
198
     * @throws NotFoundExceptionInterface
199
     */
200 2 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...
201
        string $index,
202
        string $modelRelName,
203
        string $queryValRulesClass,
204
        ContainerInterface $container,
205
        ServerRequestInterface $request
206
    ): ResponseInterface {
207 2
        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...
208 2
        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...
209
210 2
        $api     = static::defaultCreateApi($container, static::API_CLASS);
211 2
        $handler = function () use ($api, $index, $modelRelName) {
212 2
            return $api->readRelationship($index, $modelRelName);
213 2
        };
214
215 2
        return static::defaultReadRelationshipWithClosureHandler(
216 2
            $handler,
217 2
            $request->getQueryParams(),
218 2
            $request->getUri(),
219 2
            static::defaultCreateQueryParser($container, $queryValRulesClass),
220 2
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
221 2
            $api,
222 2
            $container->get(SettingsProviderInterface::class),
223 2
            $container->get(JsonSchemasInterface::class),
224 2
            $container->get(EncoderInterface::class)
225
        );
226
    }
227
228
    /**
229
     * @param string                 $index
230
     * @param string                 $modelRelName
231
     * @param string                 $queryValRulesClass
232
     * @param ContainerInterface     $container
233
     * @param ServerRequestInterface $request
234
     *
235
     * @return ResponseInterface
236
     *
237
     * @throws ContainerExceptionInterface
238
     * @throws NotFoundExceptionInterface
239
     */
240 1 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...
241
        string $index,
242
        string $modelRelName,
243
        string $queryValRulesClass,
244
        ContainerInterface $container,
245
        ServerRequestInterface $request
246
    ): ResponseInterface {
247 1
        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...
248 1
        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...
249
250 1
        $api     = static::defaultCreateApi($container, static::API_CLASS);
251 1
        $handler = function () use ($api, $index, $modelRelName) {
252 1
            return $api->readRelationship($index, $modelRelName);
253 1
        };
254
255 1
        return static::defaultReadRelationshipIdentifiersWithClosureHandler(
256 1
            $handler,
257 1
            $request->getQueryParams(),
258 1
            $request->getUri(),
259 1
            static::defaultCreateQueryParser($container, $queryValRulesClass),
260 1
            static::defaultCreateParameterMapper($container, static::SCHEMA_CLASS),
261 1
            $api,
262 1
            $container->get(SettingsProviderInterface::class),
263 1
            $container->get(JsonSchemasInterface::class),
264 1
            $container->get(EncoderInterface::class)
265
        );
266
    }
267
268
    /** @noinspection PhpTooManyParametersInspection
269
     * @param                        $parentIndex
270
     * @param string                 $modelRelName
271
     * @param                        $childIndex
272
     * @param string                 $childSchemaClass
273
     * @param string                 $childValidatorClass
274
     * @param string                 $childApiClass
275
     * @param ContainerInterface     $container
276
     * @param ServerRequestInterface $request
277
     *
278
     * @return ResponseInterface
279
     * @throws ContainerExceptionInterface
280
     * @throws NotFoundExceptionInterface
281
     */
282 2
    protected static function updateInRelationship(
283
        $parentIndex,
284
        string $modelRelName,
285
        string $childIndex,
286
        string $childSchemaClass,
287
        string $childValidatorClass,
288
        string $childApiClass,
289
        ContainerInterface $container,
290
        ServerRequestInterface $request
291
    ): ResponseInterface {
292 2
        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...
293
294 2
        $response = static::defaultUpdateInRelationshipHandler(
295 2
            $parentIndex,
296 2
            $modelRelName,
297 2
            $childIndex,
298 2
            $request->getUri(),
299 2
            $request->getBody(),
300 2
            $childSchemaClass,
301 2
            $container->get(ModelSchemaInfoInterface::class),
302 2
            static::defaultCreateDataParser($container, $childValidatorClass),
303 2
            static::defaultCreateApi($container, static::API_CLASS),
304 2
            static::defaultCreateApi($container, $childApiClass),
305 2
            $container->get(SettingsProviderInterface::class),
306 2
            $container->get(JsonSchemasInterface::class),
307 2
            $container->get(EncoderInterface::class),
308 2
            $container->get(FactoryInterface::class),
309 2
            $container->get(FormatterFactoryInterface::class)
310
        );
311
312 2
        return $response;
313
    }
314
315
    /**
316
     * @param string                 $parentIndex
317
     * @param string                 $modelRelName
318
     * @param string                 $childIndex
319
     * @param string                 $childApiClass
320
     * @param ContainerInterface     $container
321
     * @param ServerRequestInterface $request
322
     *
323
     * @return ResponseInterface
324
     * @throws ContainerExceptionInterface
325
     * @throws NotFoundExceptionInterface
326
     */
327 1 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...
328
        string $parentIndex,
329
        string $modelRelName,
330
        string $childIndex,
331
        string $childApiClass,
332
        ContainerInterface $container,
333
        ServerRequestInterface $request
334
    ): ResponseInterface {
335 1
        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...
336
337 1
        return static::defaultDeleteInRelationshipHandler(
338 1
            $parentIndex,
339 1
            $modelRelName,
340 1
            $childIndex,
341 1
            $request->getUri(),
342 1
            static::defaultCreateApi($container, static::API_CLASS),
343 1
            static::defaultCreateApi($container, $childApiClass),
344 1
            $container->get(SettingsProviderInterface::class),
345 1
            $container->get(JsonSchemasInterface::class),
346 1
            $container->get(EncoderInterface::class)
347
        );
348
    }
349
}
350