Completed
Push — master ( 1f1fbe...b94cbf )
by Sam
06:27
created

AbstractSyncCommand::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
namespace Digia\Lumen\ContentfulSync\Console\Commands;
4
5
use Contentful\Delivery\Client;
6
use Contentful\Delivery\Query;
7
use Digia\Lumen\ContentfulSync\Services\AbstractContentfulSyncService;
8
use Illuminate\Console\Command;
9
use Jalle19\Laravel\LostInterfaces\Console\Command as CommandInterface;
10
use Nord\Lumen\Contentful\ContentfulService;
11
12
/**
13
 * Class AbstractSyncCommand
14
 * @package Digia\Lumen\ContentfulSync\Console\Commands
15
 */
16
abstract class AbstractSyncCommand extends Command implements CommandInterface
17
{
18
19
    /**
20
     * @var boolean
21
     */
22
    protected $ignoreExisting;
23
24
    /**
25
     * @var ContentfulService
26
     */
27
    protected $contentfulService;
28
29
    /**
30
     * @var AbstractContentfulSyncService
31
     */
32
    protected $contentfulSyncService;
33
34
    /**
35
     * @var array
36
     */
37
    protected $contentTypes;
38
39
    /**
40
     * @var int
41
     */
42
    protected $numSynchronized;
43
44
    /**
45
     * @var int
46
     */
47
    protected $skip;
48
49
    /**
50
     * @param null|string $contentType the content type, or null if not applicable
51
     *
52
     * @return Query the query used to fetch all entries/assets
53
     */
54
    abstract protected function getQuery(?string $contentType = null): Query;
55
56
    /**
57
     * @param null|string $contentType the content type, or null if not applicable
58
     *
59
     * @return Query the query used to get the total number of items
60
     */
61
    abstract protected function getTotalQuery(?string $contentType = null): Query;
62
63
    /**
64
     * AbstractSyncCommand constructor.
65
     *
66
     * @param array                         $contentTypes
67
     * @param ContentfulService             $contentfulService
68
     * @param AbstractContentfulSyncService $contentfulSyncService
69
     */
70
    public function __construct(
71
        array $contentTypes,
72
        ContentfulService $contentfulService,
73
        AbstractContentfulSyncService $contentfulSyncService
74
    ) {
75
        parent::__construct();
76
77
        $this->contentTypes          = $contentTypes;
78
        $this->contentfulService     = $contentfulService;
79
        $this->contentfulSyncService = $contentfulSyncService;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     *
85
     * @throws \Throwable
86
     */
87
    public function handle()
88
    {
89
        // Parse options and set defaults
90
        $this->ignoreExisting  = (bool)$this->option('ignoreExisting');
91
        $this->numSynchronized = 0;
92
        $this->skip            = 0;
93
    }
94
95
    /**
96
     * @return Client
97
     */
98
    protected function getClient(): Client
99
    {
100
        return $this->contentfulService->getClient();
101
    }
102
}
103