Completed
Push — master ( f73309...4d4b19 )
by Antoine
03:25
created

src/Api/OperationTypeDeprecationHelper.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * This file is part of the API Platform project.
6
 *
7
 * (c) Kévin Dunglas <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace ApiPlatform\Core\Api;
14
15
/**
16
 * Class OperationTypeDeprecationHelper
17
 * Before API Platform 2.1, the operation type was one of:
18
 * - "collection" (true)
19
 * - "item" (false).
20
 *
21
 * Because we introduced a third type in API Platform 2.1, we're using a string with OperationType constants:
22
 * - OperationType::ITEM
23
 * - OperationType::COLLECTION
24
 * - OperationType::SUBCOLLECTION
25
 *
26
 * @internal
27
 */
28
final class OperationTypeDeprecationHelper
29
{
30
    /**
31
     * @param string|bool $operationType
32
     *
33
     * @return string
34
     */
35
    public static function getOperationType($operationType): string
36
    {
37
        if (is_bool($operationType)) {
38
            @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
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
39
40
            $operationType = $operationType === true ? OperationType::COLLECTION : OperationType::ITEM;
41
        }
42
43
        return $operationType;
44
    }
45
}
46