• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 9838795518

08 Jul 2024 11:33AM UTC coverage: 64.239% (+0.07%) from 64.173%
9838795518

push

github

web-flow
Merge pull request #6459 from soyuka/main

Merge 3.4

154 of 179 new or added lines in 24 files covered. (86.03%)

36 existing lines in 12 files now uncovered.

11326 of 17631 relevant lines covered (64.24%)

68.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.71
/src/Metadata/Resource/Factory/DeprecationResourceMetadataCollectionFactory.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\Metadata\Resource\Factory;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\Metadata\Operations;
18
use ApiPlatform\Metadata\Put;
19
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
20

21
/**
22
 * Triggers resource deprecations.
23
 *
24
 * @final
25
 *
26
 * @internal
27
 */
28
class DeprecationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
29
{
30
    // Hashmap to avoid triggering too many deprecations
31
    private array $deprecated;
32

33
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $decorated)
34
    {
35
    }
563✔
36

37
    public function create(string $resourceClass): ResourceMetadataCollection
38
    {
39
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
12✔
40

41
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
12✔
42
            $newOperations = [];
12✔
43
            foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
12✔
44
                $extraProperties = $operation->getExtraProperties();
12✔
45
                if ($operation instanceof Put && null === ($extraProperties['standard_put'] ?? null)) {
12✔
46
                    $this->triggerDeprecationOnce($operation, 'extraProperties["standard_put"]', 'In API Platform 4 PUT will always replace the data, use extraProperties["standard_put"] to "true" on every operation to avoid breaking PUT\'s behavior. Use PATCH to use the old behavior.');
×
47
                }
48

49
                if (true === ($extraProperties['use_legacy_parameter_validator'] ?? null)) {
12✔
NEW
50
                    $this->triggerDeprecationOnce($operation, 'extraProperties["use_legacy_parameter_validator"]', 'In API Platform 4 the query_parameter_validator will be removed in favor of Parameter constraints, set "use_legacy_parameter_validator" to false.');
×
51
                }
52

53
                $newOperations[$operationName] = $operation;
12✔
54
            }
55

56
            $resourceMetadataCollection[$i] = $resourceMetadata->withOperations(new Operations($newOperations));
12✔
57
        }
58

59
        return $resourceMetadataCollection;
12✔
60
    }
61

62
    private function triggerDeprecationOnce(Operation $operation, string $deprecationName, string $deprecationReason): void
63
    {
64
        if (isset($this->deprecated[$operation->getClass().$deprecationName])) {
×
65
            return;
×
66
        }
67

68
        $this->deprecated[$operation->getClass().$deprecationName] = true;
×
69

70
        trigger_deprecation('api-platform/core', '3.1', $deprecationReason);
×
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc