Passed
Push — trunk ( 77f064...22dab2 )
by Christian
15:37 queued 01:40
created

MetricController::needsApprovalRequest()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\Metrics\Api;
4
5
use Shopware\Core\Framework\Log\Package;
6
use Shopware\Core\System\Metrics\Approval\ApprovalDetector;
7
use Shopware\Core\System\SystemConfig\SystemConfigService;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Routing\Annotation\Route;
12
13
/**
14
 * @internal
15
 */
16
#[Package('merchant-services')]
17
#[Route(defaults: ['_routeScope' => ['api']])]
18
class MetricController extends AbstractController
19
{
20
    public const SYSTEM_CONFIG_KEY_SHARE_DATA = 'core.metrics.shareUsageData';
21
22
    public function __construct(
23
        private readonly ApprovalDetector $approvalDetector,
24
        private readonly SystemConfigService $configurationService,
25
    ) {
26
    }
27
28
    #[Route(path: '/api/metrics/needs-approval', name: 'api.metrics.request', methods: [Request::METHOD_GET])]
29
    public function needsApprovalRequest(): JsonResponse
30
    {
31
        return new JsonResponse($this->approvalDetector->needsApprovalRequest() && !$this->isApprovalAlreadyRequested());
32
    }
33
34
    private function isApprovalAlreadyRequested(): bool
35
    {
36
        return $this->configurationService->get(self::SYSTEM_CONFIG_KEY_SHARE_DATA) !== null;
37
    }
38
}
39