Passed
Push — main ( 72939e...42ec5e )
by Chris
20:41 queued 05:41
created

MediaConvert::getJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Meema\MediaConverter\Converters;
4
5
use Aws\Credentials\Credentials;
6
use Aws\MediaConvert\MediaConvertClient;
7
use Meema\MediaConverter\Contracts\Converter;
8
9
class MediaConvert implements Converter
10
{
11
    /**
12
     * Client instance of AWS MediaConvert.
13
     *
14
     * @var \Aws\MediaConvert\MediaConvertClient
15
     */
16
    protected MediaConvertClient $client;
17
18
    /**
19
     * Construct converter.
20
     *
21
     * @param \Aws\MediaConvert\MediaConvertClient $client
22
     */
23
    public function __construct(MediaConvertClient $client)
0 ignored issues
show
Unused Code introduced by
The parameter $client is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function __construct(/** @scrutinizer ignore-unused */ MediaConvertClient $client)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $config = config('media-converter');
26
27
        $this->client = new MediaConvertClient([
28
            'version' => $config['version'],
29
            'region' => $config['region'],
30
            'credentials' => new Credentials($config['credentials']['key'], $config['credentials']['secret']),
31
            'endpoint' => $config['url'],
32
        ]);
33
    }
34
35
    /**
36
     * Get the MediaConvert Client.
37
     *
38
     * @return \Aws\MediaConvert\MediaConvertClient
39
     */
40
    public function getClient(): MediaConvertClient
41
    {
42
        return $this->client;
43
    }
44
45
    /**
46
     * Cancels an active job.
47
     *
48
     * @param string $id
49
     * @return \Aws\Result
50
     */
51
    public function cancelJob(string $id)
52
    {
53
        return $this->client->cancelJob([
54
            'Id' => $id,
55
        ]);
56
    }
57
58
    /**
59
     * Creates a new job based on the settings passed.
60
     *
61
     * @param array $settings
62
     * @param array $metaData
63
     * @param int $priority
64
     * @return \Aws\Result
65
     */
66
    public function createJob(array $settings, $metaData = [], $priority = 0)
67
    {
68
        return $this->client->createJob([
69
            'Role' => config('media-converter.iam_arn'),
70
            'Settings' => $settings,
71
            'Queue' => config('media-converter.queue_arn'),
72
            'UserMetadata' => $metaData,
73
            'StatusUpdateInterval' => $this->getStatusUpdateInterval(),
74
            'Priority' => $priority,
75
        ]);
76
    }
77
78
    /**
79
     * Gets the job.
80
     *
81
     * @param string $id
82
     * @return \Aws\Result
83
     */
84
    public function getJob(string $id)
85
    {
86
        return $this->client->getJob([
87
            'Id' => $id,
88
        ]);
89
    }
90
91
    /**
92
     * Lists all of the jobs based on your options provided.
93
     *
94
     * @param array $options
95
     * @return \Aws\Result
96
     */
97
    public function listJobs(array $options)
98
    {
99
        return $this->client->listJobs($options);
100
    }
101
102
    protected function getStatusUpdateInterval(): string
103
    {
104
        $webhookInterval = config('media-converter.webhook_interval');
105
        $allowedValues = [10, 12, 15, 20, 30, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600];
106
107
        if (in_array($webhookInterval, [$allowedValues])) {
108
            return 'SECONDS_'.$webhookInterval;
109
        }
110
111
        return 'SECONDS_60'; // gracefully default to this value, in case the config value is missing or incorrect
112
    }
113
}
114