These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the API Platform project. |
||
5 | * |
||
6 | * (c) Kévin Dunglas <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace ApiPlatform\Core\Api; |
||
15 | |||
16 | /** |
||
17 | * Class OperationTypeDeprecationHelper |
||
18 | * Before API Platform 2.1, the operation type was one of: |
||
19 | * - "collection" (true) |
||
20 | * - "item" (false). |
||
21 | * |
||
22 | * Because we introduced a third type in API Platform 2.1, we're using a string with OperationType constants: |
||
23 | * - OperationType::ITEM |
||
24 | * - OperationType::COLLECTION |
||
25 | * - OperationType::SUBRESOURCE |
||
26 | * |
||
27 | * @internal |
||
28 | */ |
||
29 | final class OperationTypeDeprecationHelper |
||
30 | { |
||
31 | /** |
||
32 | * @param string|bool $operationType |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public static function getOperationType($operationType): string |
||
37 | { |
||
38 | if (is_bool($operationType)) { |
||
39 | @trigger_error('Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3', E_USER_DEPRECATED); |
||
1 ignored issue
–
show
|
|||
40 | |||
41 | $operationType = $operationType === true ? OperationType::COLLECTION : OperationType::ITEM; |
||
42 | } |
||
43 | |||
44 | return $operationType; |
||
45 | } |
||
46 | } |
||
47 |
If you suppress an error, we recommend checking for the error condition explicitly: