UpdateSchemaLockCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getQueryPath() 0 3 1
A handle() 0 5 1
A __construct() 0 5 1
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Commands;
4
5
use Digia\Lumen\GraphQL\Helpers\JsonEncoder;
6
use Digia\Lumen\GraphQL\GraphQLService;
7
use Digia\Lumen\GraphQL\LockFile;
8
use Illuminate\Console\Command;
9
use Jalle19\Laravel\LostInterfaces\Console\Command as CommandInterface;
10
11
/**
12
 * Class UpdateSchemaLockCommand
13
 * @package Digia\Lumen\GraphQL\Commands
14
 */
15
class UpdateSchemaLockCommand extends Command implements CommandInterface
16
{
17
18
    /**
19
     * Path to default Introspection query
20
     *
21
     * @var string
22
     */
23
    public const INTROSPECTION_GRAPHQL =  __DIR__ . '/../../resources/graphql/Introspection.graphql';
24
25
    /**
26
     * @var string
27
     */
28
    protected $signature = 'graphql:schema:lock:update';
29
30
    /**
31
     * @var string
32
     */
33
    protected $description = 'Updates the schema.lock file';
34
35
    /**
36
     * @var GraphQLService
37
     */
38
    private $graphQlService;
39
40
    /**
41
     * UpdateSchemaLockCommand constructor.
42
     *
43
     * @param GraphQLService $graphQlService
44
     */
45
    public function __construct(GraphQLService $graphQlService)
46
    {
47
        parent::__construct();
48
49
        $this->graphQlService = $graphQlService;
50
    }
51
52
    /**
53
     * Returns path to graphql query
54
     *
55
     * @return string
56
     */
57
    protected function getQueryPath()
58
    {
59
        return self::INTROSPECTION_GRAPHQL;
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65
    public function handle()
66
    {
67
        $response = $this->graphQlService->getQueryResponse(file_get_contents($this->getQueryPath()));
68
69
        file_put_contents(LockFile::getAbsolutePath(), JsonEncoder::encode($response));
70
    }
71
}
72