Issues (9)

src/Utility/ApiClientTrait.php (1 issue)

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * BEdita, API-first content management framework
6
 * Copyright 2023 Atlas Srl, Chialab Srl
7
 *
8
 * This file is part of BEdita: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published
10
 * by the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
14
 */
15
namespace App\Utility;
16
17
use BEdita\SDK\BEditaClient;
18
use BEdita\WebTools\ApiClientProvider;
19
20
/**
21
 * Read and write configuration via API
22
 */
23
trait ApiClientTrait
24
{
25
    /**
26
     * BEdita Api client
27
     *
28
     * @var \BEdita\SDK\BEditaClient|null
29
     */
30
    protected ?BEditaClient $apiClient = null;
31
32
    /**
33
     * Get API client.
34
     *
35
     * @return \BEdita\SDK\BEditaClient
36
     */
37
    public function getClient(): BEditaClient
38
    {
39
        if ($this->apiClient === null) {
40
            $this->apiClient = ApiClientProvider::getApiClient();
41
        }
42
43
        return $this->apiClient;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->apiClient could return the type null which is incompatible with the type-hinted return BEdita\SDK\BEditaClient. Consider adding an additional type-check to rule them out.
Loading history...
44
    }
45
}
46